Controller – Main Loop

The main controller program is main_sched.py. It consists of:

  • a continuous loop which performs periodic routine activities e.g. reading sensors
  • a thread that controls time-sensitive functions e.g. updating timers
  • a thread that does high-priority work e.g. responding to user instruction
  • logging initialisation

This program needs to run when the pi is started, so it is placed in the rc.local script:

sudo nano /etc/rc.local

Add the following between the section that prints the IP Address, and the exit statement:

# Run the Hub Program in a seperate process (&)
cd /usr/local/bin/code/controller
sudo python main_sched.py --log=INFO --slave=false >> hub.log &

Save the file.

The parameters set the logging level and the slave status. This will be our master node, so slave is false.

To assist with the staged implementation of the controller code, as per the project plan, I have commented out a number of lines in the main scheduler with the double hash # #. This enables the controller to run, and future modules to be added later, with their required dependencies.

The following command will fetch the files for this first stage…

wget -nH -x --cut-dirs=3 -P /usr/local/bin/code/controller/ -i /usr/local/bin/code/controller/manifest1.txt http://www.warrensoft.co.uk/home-hub/manifests/controller/manifest1.txt

 

The next post will cover reading values from sensors.