The main logic of the engine has already been implemented and tested. What is now missing is the management of a soil moisture sensor and the management of the weather forecast.
Implementing the first feature is not so hard, once we have the value of the humidity of the soil we just need to add an IF statement to enable/disable the irrigation valves.
Implementing the second feature (weather forecast) is a bit more tricky: we need to collect the values of pressure and humidity and use them to understand if it's going to rain.
The code is ready to manage both the features in a specific function named 'evaluateTurningOnOutput' that now always returns TRUE. So when we will develop those functionalities, we will not change the engine code a part from this function.
Now let's start with the code explanation of wnw_engine.py that is a bit more complex than the sketch, so we will not follow the script line by line.
Showing posts with label engine. Show all posts
Showing posts with label engine. Show all posts
Monday, July 14, 2014
The engine: an overview of the architecture
We have seen how the sketch works: it is just a layer to interact with the input/output element of the project, retrieving sensors values and activating/deactivating outputs. The logic of the project is demanded to a python script running on the Linux side of the Arudino Yun due to two main reasons:
- the logic is preatty complex and cannot be loaded into the small memory of the ATmega32u4;
- we need to interact with a logging system and a database, and it's much more easy to do that using already developed python libraries than reinventing the wheel in C.
The engine is based on three .PY files: the main file defining the logic and two simple library defining the bridge and the database objects.
- wnw_engine.py => the python script running the logic of the engine;
- wnw_bridge.py => the python class (WnWBridge) used to access the mailbox and share data and request with the lower layer (the sketch running on the ATmega 32u4 side);
- wnw_database.py => the python class (WnWDatabaseConnection) managing the connection to the database and wrapping the communication with it.
I created a shell script to automatically run the engine as soon as the system (Linux) completes the startup procedure. In order to be sure that the engine is always up and running, I added a line to the crontab calling the same script every minute. The script check if the engine is working and re-start it only in case it's not running.
Subscribe to:
Posts (Atom)