Skip to content

Instantly share code, notes, and snippets.

@dulichan
Last active August 29, 2015 14:04
Show Gist options
  • Save dulichan/05f62f2db585b5e962b3 to your computer and use it in GitHub Desktop.
Save dulichan/05f62f2db585b5e962b3 to your computer and use it in GitHub Desktop.
Reading a DHT11 sensor and publishing a MQTT message
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