Making the python script run at boot
Now to convert the pi as a stand alone embedded system i.e it will do the desired task if powered on.
This is achieved using the crontab function of the linux kernel and a shell script.
-
now go to the directory which contains the target files.
$cd /ubidots -
Create a pyhton script called
new.pywith the contents asimport time time.sleep(10)To induce a 10 sec delay of runnnig the ubi-test.py at boot up so all the required protocols and drivers will be up and running before the code is executed.
-
Create a new file called
launcher.sh. And input the following data$cd / $cd /home/pi/ubidots $sudo python new.py $sudo python ubi-test.py & $cd / -
Now make the
launcher.shas an executable file by$sudo chmod 755 launcher.sh -
Now try running the
launcher .sh$sudo sh launcher.shwhich will result in the script in running after a time interwal of 10 secs.
-
Now edit the
crontabusing $sudo crontab -e and add these lines at the bottom@reboot sh /home/pi/ubidots/launcher.sh > /home/pi/ubidots/logs/cronlog 2>&1It will look as follows

-
now save this and reboot the system using the command
$sudo reboot -
Now the raspberry will reboot and the code will run as a background service.This need to be verified in two ways.
-
Firstly use the following command to check wether the program is running or not.
$ps aux | grep /home/pi/ubidots/ubi-test.py -
Secondly verify wether the value has beeen uploaded to the online cloud.
-