// 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);
}
Example #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
}
Example #3
0
bool sendCmd(Cmd cmd)
{
    static const char* itemCurtains = "curtains";
    static const char* itemLights = "overHeadLights";
    static const char* itemPixels = "pixelWall";
    static const char* itemFan = "fan";

    // figure out which itemName we are talking to
    const char* itemName = 0;
    switch(cmd)
    {
    case e_cmdButton1:
        itemName = itemCurtains;
        break;
    case e_cmdButton2:
        itemName = itemLights;
        break;
    case e_cmdButton3:
        itemName = itemPixels;
        break;
    case e_cmdButton4:
        itemName = itemFan;
        break;
    default:
        debugSerial.println("ARDUINO: Bad cmd passed to sendCmd()\n");
        itemName = "";
        return false;
    }
    char topic[32] = {0};
    sprintf(topic, "/%s/%s", "bedroom1", itemName);

    char mesg[64] = {0};
    sprintf(mesg, "{\"command\":\"toggle\"}");
    debugSerial.println("");
    debugSerial.println(topic);
    debugSerial.println(mesg);

    // Send out command over mqtt protocol
    mqttClient.publish(topic, mesg);

    return true;
}
Example #4
0
// Publish our message
void publishMessage()
{
	Serial.println("Let's publish message now!");
	mqtt.publish("main/frameworks/sming", "Hello friends, from Internet of things :)"); // or publishWithQoS
}