Skip to end of metadata
Go to start of metadata

Component list


  1. Raspberry Pi
  2. DHT11/22 or AM2302 temperature and humidity sensor
  3. 4.7K or 10K resister
  4. Breadboard
  5. Jumper wires

1. RPI and sensor Hardware preparation


First of all follow the tutorial on this url to prepare the RPI and sensor hardware.Temperature monitoring with Raspberry Pi and DHT11/22 temperature and humidity sensor

You only need to follow the steps from 1 to 4. Assuming that now we have the working scripts read_temperature.sh and read_humidity.sh you can follow the instructions given below.

2. GadgetKeeper configuration


Follow the Instructions in this url and implement the remote property. Implement Remote Property

Use 10000 like bigger value instead of 1000 as the timeout value in the step 2.

3. MQTT client preparation


  1. create a directory MQTT

  2. Download the mosquitto from this site or simply use the following command. http://mosquitto.org/download/

  3. I used this mosquitto-1.0.2.tar.gz version for this tutorial
  4. Follow these commands to install mosquitto

  5. If it fails the compile process try the following supportive commands on the terminal to install the dependency libraries. Then compile again

  6. Next step is to prepare the MQTT client script to communicate with gadgetkeeper MQTT server. Following Python script can be used to do it. First go to the gadgetkeeper directory we created on the Temperature monitoring with Raspberry Pi and DHT11/22 temperature and humidity sensor tutorial. Then create a file as follows

    Then paste the following Python code on it.

  7. Now simply run this script as follows

                                                                                                                                                                                           

  8. Make sure that port 1883 is not blocked by the firewall.

4. Test the communication


Now you can use the "Get property value" step on the Implement Remote Property .Simply click on "Get" button and it should fetch the new value (Temperature or Humidity) from the RPI via the MQTT protocol.

Sensor read error will be shown as below (If the sensor is not available or fetching the temperature or humidity value from the sensor is failed, then the following response will be received from the MQTT client. You can assign any value for this as the error code on the python script. I have used -1000 to indicate error readings)

This window shows the communication between the client and server.

Following window shows a successful sensor reading upload to the server. Here the sensor value is 62.33

This window shows the communication between the client and server.

  • No labels