Exemplo n.º 1
0
void bringUpMqtt()
{
    unsigned brokerConnectionTryLimit = 10;
    unsigned count = 0;
    // if we lost wifiConnectivity, we need to break out and
    // go back to bringing up wifi
    debugSerial.println("ARDUINO: Inside bringUpMqtt()");


    if( !mqttClient.init() )
    {
        debugSerial.println("ARDUINO: Bad news, mqtt client failed to initialize correctly");
        return;
    }

    while(!MqttClient::connected && (count < brokerConnectionTryLimit) )
    {
        debugSerial.println("ARDUINO: Connecting mqttClient");
        mqttClient.connect(SERVER_NAME, SERVER_PORT, false);
        // process 10 times
        espMultipleProcess(10);
        delay(100);
        espMultipleProcess(10);

        ++count;
    }
    debugSerial.println("ARDUINO: Leaving bringUpMqtt()");

    return;
}
Exemplo n.º 2
0
// Run MQTT client
void startMqttClient()
{
	if(!mqtt.setWill("last/will","The connection from this device is lost:(", 1, true)) {
		debugf("Unable to set the last will and testament. Most probably there is not enough memory on the device.");
	}
	mqtt.connect("esp8266");
	mqtt.subscribe("main/status/#");
}
// Run MQTT client
void startMqttClient()
{
	if(!mqtt.setWill("last/will","The connection from this device is lost:(", 1, true)) {
		debugf("Unable to set the last will and testament. Most probably there is not enough memory on the device.");
	}
	mqtt.connect("ESP8266");
	mqtt.subscribe("messagebox");
	displayText("Start MQTT client...");
}
Exemplo n.º 4
0
// Will be called when WiFi station was connected to AP
void connectOk()
{
	Serial.println("I'm CONNECTED");

	// Run MQTT client
	mqtt.connect("esp8266");
	mqtt.subscribe("main/status/#");

	// Start publishing loop
	procTimer.initializeMs(20 * 1000, publishMessage).start(); // every 20 seconds
}