Hi all,
Maybe you could help me explain why this happen. I use VSCode + PlatformIO + ThingerIO. I am using Wemos ESP8266 D1 Mini board.
Vanilla example ESP8266OTA from ThingerIO was working. I added simple led blink to that example also was working – I could update the blink interval using OTA update.
Next, I put EspMQTTClient arduino/platformio library from Patrick Lapointe in the sketch. Once the firmware is running … I can no longer do OTA update. The serial debug showed “Cannot Read Socket” and in VSCode there was a notification of “timeout 60000ms”.
I use my own MQTT server in my local network, and I want to see if OTA from ThingerIO can be used for this project.
Below is the code which is no longer able to handle OTA after I added MqttClient.loop()
in the loop(){}
.
I hope someone can help me explain what happened, and how should I do it to make it work.
By the way, it is working fine with ESP32 (NodeMCU-32s).
Cheers,
Fahmy
/* ThingerIO */
#define THINGER_SERIAL_DEBUG
#include <ThingerESP8266.h>
#include <ThingerESP8266OTA.h>
#include "arduino_secrets.h"
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
/***
* Initialize ESP8266 OTA
* use Thinger.io VSCode Studio extension + Platformio to upgrade the device remotelly
*/
ThingerESP8266OTA ota(thing);
/* MQTT */
#include <EspMQTTClient.h>
/* Init MQTT Client */
EspMQTTClient MqttClient(
MQTT_ADDRESS, // MQTT Broker server ip
MQTT_PORT, // The MQTT port, default to 1883. this line can be omitted
MQTT_USER, // mqtt user, Can be omitted if not needed
MQTT_PW, // mqtt password, Can be omitted if not needed
MODULE_NAME // Client name that uniquely identify your device
);
void onConnectionEstablished();
void setup()
{
// open serial for monitoring
Serial.begin(115200);
// set builtin led as output
pinMode(LED_BUILTIN, OUTPUT);
// add WiFi credentials
thing.add_wifi(SSID, SSID_PASSWORD);
// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)
thing["led"] << digitalPin(LED_BUILTIN);
// resource output example (i.e. reading a sensor value)
thing["millis"] >> outputValue(millis());
// more details at http://docs.thinger.io/arduino/
/* Optional functionalities of EspMQTTClient */
// MqttClient.enableDebuggingMessages();
MqttClient.enableLastWillMessage(TOPIC(_PREFIX, _LastWill), LastWillMsg, true); // You can activate the retain flag by setting the third parameter to true
}
void loop()
{
static unsigned long led_millis = millis();
thing.handle();
MqttClient.loop();
if (millis() - led_millis > 1000)
{
led_millis = millis();
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
MqttClient.publish(TOPIC(_PREFIX, _MOD_HEARTBEAT), String(led_millis), true);
}
}
void onConnectionEstablished()
{
MqttClient.publish(TOPIC(_PREFIX, _MOD_STATUS), "Online", true);
}