iGPIO

中文

The General Purpose Input Output over Internet.*


Home | iGPIO | Resource

 
 

An example to build a remote temperature monitor using iGPIO

At the end of this example, you will be able to monitor the temperature using the iGPIO website interface.

Parts needed in the example:

  • Raspberry Pi Model B (with Internet access, either wired or wireless)
  • MCP9808 Temperature Sensor
  • Jumper Wire, Breadboard

Also needed is a PC or smartphone to access iGPIO website.

Follow these steps to setup the temperature monitor:

(1) Register for a free account at iGPIO

Click here to visit the iGPIO registration page

You will need to have an email address and to select a password to register for an account. After registration, you will have an account with user ID, i.e., your email address, and password.

(2) Setup device general parameters on iGPIO

After registration at the iGPIO website, click this link. This will bring you to the sign in page; sign in using your account email and password, then click on the Device Manager button. Set the following parameters:

  • Name: Temp Monitor
  • Update Interval: no change (default value is 300 seconds between two updates from a device, e.g., Raspberry Pi)
  • Mail Interval: no change (default value is 3600 seconds (one hour) between two system email notifications)
  • D Mail Interval: no change (default value is 3600 seconds between two device email notifications)
  • Alert Delay: 600 (wait this time in seconds before the iGPIO system sends an email warning to user if device has not updated the temperature at the expected Update Interval setting)

Check Enable box and click on 'Update' button.

(3) Setup device detail parameters on iGPIO

After completing the device general parameters setup, click on 'Open #1' link to bring up the detail parameters page for device #1. In this example, we use CH 2. Set parameters as follows:

  • Label: Rm(C) (Room temperature in degrees C)
  • Value: no change (which will be updated by the device)
  • Value2: 19 (Set lower limit to 19 degrees C)
  • Value3: 22 (Set higher limit to 22 degrees C)
  • Flag: 0 (Allow a device to update the value)

Check Enable box (a channel must be enable before use) and then click on the 'Update' button to complete the setting. This setting will allow the device to update the value, i.e., Room temperature in degrees C. If the temperature is out of the specified range (19 to 22), the system will notify the user that the temperature is out of the preset range.

(4) Build the temperature monitor

This link will tell you all steps to build the temperature monitor:

https://learn.adafruit.com/mcp9808-temperature-sensor-python-library?view=all

To test if the setup on the Raspberry Pi correct, put the following python code in a file, e.g., /home/pi/read_temp.py

import time
import Adafruit_MCP9808.MCP9808 as MCP9808
sensor = MCP9808.MCP9808()
sensor.begin()
temp = sensor.readTempC()
print 'Temp: ' + str(temp) + ' C'

Then run the command:

sudo python read_temp.py

If everything is working correctly, the temperature will be displayed on the screen and you can continue to the following steps.

(5) Run a sample python code on Raspberry Pi

Connect Raspberry Pi to the Internet either wired (using an ethernet cable to a router) or wireless (using a USB WiFi adapter to a router, http://www.raspberrypi.org/documentation/configuration/wireless/). Download the sample code from this link. Edit the top 2 lines, viz., use your account name (email address) and password, and save it to /home/pi. For more information, please read Specification of device user interface. Use this command to run the sample python program:

sudo python temp_mon.py

Please note, since the update interval is 300 (s), after running the code once, you will need to wait 300 s before running it again. Therefore, it is recommended to run the code in crontab (an operating system scheduler). To do this, use the command

crontab -e

and add a line at the end of crontab:

*/5 * * * * sudo /usr/bin/python /home/pi/temp_mon.py

Save and exit crontab. With this setting, the device will update the room temperature every 5 minutes (300s), and it can be monitored from anywhere in the world with a PC, tablet or smartphone that has a browser and Internet access. When the monitored temperature goes out of the preset range, a message will be sent to notify the user. Also if the device is not updating the temperature as configured by the user, the iGPIO server will notify the user by sending an email. If the inactive device comes back to work after some time, the iGPIO server will notify the user by sending an email.

Please Note: If you are using the Crontab scheduler to run your program, please add a line in your application program (add the line before the request to the iGPIO website) to sleep for some "randomly chosen" number of seconds (in Python the command is time.sleep(#.#) to sleep for #.# seconds; you would have to also include the line "import time" at the beginning of the program). The reason we suggest you do this is that the Crontab scheduling is based on absolute minutes, so if 1000 users were to schedule using Crontab their applications to run every five minutes, then all 1000 users' programs would be accessing iGPIO all at the same time, e.g., 2:00 PM, 2:05 PM, 2:10 PM, etc. However, if all users take their own arbitrarily chosen number of seconds to delay their iGPIO accesses, this problem will be avoided. Note that the sleep command will not affect the time interval; for example a 4 second delay will mean that the initial access of the iGPIO web site is delayed by 4 seconds; however the interval between accesses will still be, e.g., 5 minutes, if that is the setting on Crontab.

 

*US Patent No. 9,727,046, ©2018 iGPIO® All Rights Reserved | Terms of Service and Privacy Policy | Contact Us