// MQTT : Publish our message
void publishMessage()
{
	if (mqtt.getConnectionState() != eTCS_Connected) {
		startMqttClient(); // Auto reconnect
		return;
	}

	// Read DHT22
	TempAndHumidity th;
	if(!dht.readTempAndHumidity(th)) {
		return;
	}
	// Make JSON data
	String message = "{\"temp\":";
	message += th.temp;
	message += ", \"humi\":";
	message += th.humid;
	message += "}";

	// publish message
	Serial.println("Let's publish message now!");
	mqtt.publish("home/thirdroom/temp_humi", message, true); // retained message

	displayTemp(message);
}
示例#2
0
// Publish our message
void publishMessage()
{
	if (mqtt.getConnectionState() != eTCS_Connected)
		startMqttClient(); // Auto reconnect

	Serial.println("Let's publish message now!");
	mqtt.publish("main/frameworks/sming", "Hello friends, from Internet of things :)"); // or publishWithQoS
}