Component list
- BeagleBone Black
- DHT11/22 or AM2302 temperature and humidity sensor
- 4.7K or 10K resistor
- Breadboard
- Jumper wires
1. BBB and sensor Hardware preparation
To prepare BBB hardware and software for sendor use tutorial under link Temperature monitoring with BeagleBoneBlack and DHT11/22 and AM2302 temperature and humidity sensor .
You only need to follow the steps from 1 to 5. Assuming that now we have the working scripts read_temperature.py
and read_humidity.py
you can follow the instructions given below.
2. GadgetKeeper configuration
Follow the Instructions in Implement Remote Property to implement the remote property.
On step 2. "Create MQTT connection to device", set "Response, ms" to 60000 ms
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 BeagleBoneBlack and DHT11/22 and AM2302 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 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 BBB 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)
Successful communication between user and server you can see below.