Taking readings from the sensors

Now that our app is set up, we need to configure the Pi to regularly take readings from the sensors and update the database with the latest weather conditions. To do this, we will use a Python script that will communicate with the DHT11/22 and BMP180 sensors using their Adafruit libraries and the Maplin sensors using the pySerial library and perform the following steps:

  1. We must first install the pySerial library to be used by the script. All the other libraries used are either installed by default or were installed when we had set up the DHT11/22 and BMP130 sensors:
    sudo pip install pyserial
    
  2. Next, we will modify the rc.local file to perform the script run when the Pi boots:
    sudo nano /etc/rc.local
    
  3. Here, add the following line to the file:
    python /home/pi/sensor_manager.py --database /home/pi/weather_station_webapp/weather.db --poll-interval 10 --submit-interval 600 &

    The output should look as shown in the following screenshot:

    Taking readings from the sensors

    Note

    The interval at which the script takes readings from the sensors and stores them in the database can be configured by changing the --poll-interval and --submit-interval arguments. Note that if the --submit-interval setting is set any lower than 300 seconds (5 minutes), then this can make the history view in the web application slow to load.

  4. Finally, reboot the Pi and try to access the web interface to check whether the data update after the submit interval has elapsed.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.109.8