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:

  1. the logic is preatty complex and cannot be loaded into the small memory of the ATmega32u4;
  2. 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.
Also if we develop the main logic on the Linux side we can easily take advantage of the OS itself: rotate the log files, schedule activities with crontab and so on.

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.

No comments:

Post a Comment