Last active
August 29, 2015 14:04
-
-
Save dulichan/05f62f2db585b5e962b3 to your computer and use it in GitHub Desktop.
Reading a DHT11 sensor and publishing a MQTT message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void run() { | |
dhtSensor.read(); | |
float temperature = dhtSensor.getTemperature(false); | |
int humidity = dhtSensor.getHumidity(); | |
try { | |
String message = "Temperature:" + Float.toString(temperature); | |
String humidityMsg = "Humidity:" + Integer.toString(humidity); | |
mqttClient.publish(1,message.getBytes()); | |
} catch (MqttException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment