Component list
- Raspberry Pi
- DHT11/22 or AM2302 temperature and humidity sensor
- 4.7K or 10K resister
- Breadboard
- 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
-
create a directory MQTT
-
Download the mosquitto from this site or simply use the following command. http://mosquitto.org/download/
- I used this mosquitto-1.0.2.tar.gz version for this tutorial
-
Follow these commands to install mosquitto
-
If it fails the compile process try the following supportive commands on the terminal to install the dependency libraries. Then compile again
-
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.
-
Now simply run this script as follows
- 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.