marvinroger / async-mqtt-client

📶 An Arduino for ESP8266 asynchronous MQTT client implementation
MIT License
834 stars 266 forks source link

OTA over MQTT #34

Closed ionciubotaru closed 7 years ago

ionciubotaru commented 7 years ago

Please consider adding OTA over MQTT - it is very useful when you have a large number of ESP modules
I found un example here https://github.com/Imroy/pubsubclient/blob/master/examples/ESP8266-OTA/ESP8266-OTA.ino it works fine. Your library is better and I prefer to use it.

jamesmyatt commented 7 years ago

Is this what you're after https://github.com/marvinroger/homie-esp8266?

ionciubotaru commented 7 years ago

Homie is a great library, very advanced for a newbie. A small standalone example will be good for everybody.

marvinroger commented 7 years ago

Advances for newbie, really?

marvinroger commented 7 years ago

As the previously closed issue, this library is meant for the raw MQTT client. If you want some higher features like OTA over MQTT, see Homie for ESP8266 and its source code.

dvv commented 6 years ago

@ionciubotaru A workaround could be:

static void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {

  // update requested?
  if (strcmp(topic, MQTT_CLIENT "/update") == 0) {
    int _lastError = 0;
    // start update
    if (index == 0) {
      Update.runAsync(true);
      if (!Update.begin(total, U_FLASH)) {
        _lastError = Update.getError();
        Update.printError(Serial);
        // ignore the rest
        topic[0] = 0;
      }
    }
    // do update in chunks
    if (!_lastError) {
      if (Update.write((uint8_t *)payload, len) != len) {
        _lastError = Update.getError();
        Update.printError(Serial);
        // ignore the rest
        topic[0] = 0;
      }
    }
    // finish update
    if (!_lastError) {
      if (index + len == total) {
        if (!Update.end()) {
          _lastError = Update.getError();
          Update.printError(Serial);
        } else {
          // restart?
          ESP.restart();
        }
      }
    }
  }

  // ...
}
ionciubotaru commented 6 years ago

Only @arendst can decide to include this new feature in Tasmota's code. From my point of view using OTA over MQTT allow user to disable web server and web client and decrease the size of the final bin file. More, user need only one server (mqtt) not two (mqtt + http)