A Raspberry Pi IoT to collect and post field data

This is the third blog post in a series that uses the Raspberry Pi as an Internet of Things device to collect environmental data (with a DHT22 weather sensor) and post the data in real-time to an ArcGIS Online feature service.  The post below is a highly synopsized version of a chapter in the forthcoming third edition of the book, Tech-enabled Field Studies.

Begin by setting up a Raspberry Pi with the DHT22 sensor..  See The Pi Becomes a Data Collector

Use the Pi’s command prompt to make the following installations and configurations:

  1. pip3 install virtualenv
  2. virtualenv datalogger
  3. cd datalogger
  4. source bin/activate datalogger
  5. pip3 install Adafruit_DHT
  6. pip3 install pandas
  7. pip3 install arcgis – -no-deps

Note: Step 6 above (Pandas) may take several minutes. The above steps create a virtual environment in Python called datalogger and install three libraries into that environment including a streamlined ArcGIS API for Python.  When you call the weather script below, you will need to reference it from this environment, described below.

Continue the set-up by:

  • Configuring the ArcGIS Online service as described in the previous blog post, A Time-aware Geo Data Bucket.
  • Download the sample Python file that reads data from the DHT22 and posts to ArcGIS Online. The Python file is here or download/clone the entire project here.  be sure to update the python file with your information, as described in the file.
  • Put the Python file in your datalogger directory to help you remember that it must be run from that environment.  Once you have added your data to the python script and have the ArcGIS Online service running, you can run the script by using the command:
    • /home/pi/datalogger/bin/python3 addwx.py

The service does have a date/time attribute and the service can become time-aware.  Once the service is added to a map, you may also choose a symbology that you prefer.

Finally, on the Pi, you may choose to set-up a Cron job to schedule the script execution on a reoccurring basis.  Do a quick Google search to find tutorials on how best to do this.  Enjoy!