Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTA firmware update #27

Open
roarfred opened this issue Mar 5, 2018 · 2 comments
Open

OTA firmware update #27

roarfred opened this issue Mar 5, 2018 · 2 comments
Labels

Comments

@roarfred
Copy link
Owner

roarfred commented Mar 5, 2018

Listen for specific MQTT message, with url for binary to update from

@roarfred roarfred changed the title OTA updates OTA firmware update Mar 5, 2018
@xibriz
Copy link
Contributor

xibriz commented Apr 9, 2018

Something like this:

#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>

const int FW_VERSION = 1011;
const char* mqtt_topic_fw_info = "esp/test/info";

void checkForUpdates(String fwImageURL) {
  HTTPClient httpClient;
  
  String newFWVersion = httpClient.getString();
  
  mqtt.publish(mqtt_topic_fw_info, ((String)"Current firmware version").c_str());
  mqtt.publish(mqtt_topic_fw_info, ((String)FW_VERSION).c_str());
  
  mqtt.publish(mqtt_topic_fw_info, ((String)"Preparing to update").c_str());
  
  mqtt.publish(mqtt_topic_fw_info, ((String)"Downloading new firmware.").c_str());
  mqtt.publish(mqtt_topic_fw_info, fwImageURL.c_str());
      
  t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL );
  
  switch(ret) {
     case HTTP_UPDATE_FAILED:
       mqtt.publish(mqtt_topic_fw_info, ((String)HTTP_UPDATE_FAILED).c_str());
       mqtt.publish(mqtt_topic_fw_info, ((String)ESPhttpUpdate.getLastError()).c_str());
       mqtt.publish(mqtt_topic_fw_info, ESPhttpUpdate.getLastErrorString().c_str());
       break;
    case HTTP_UPDATE_NO_UPDATES:
       mqtt.publish(mqtt_topic_fw_info, ((String)HTTP_UPDATE_NO_UPDATES).c_str());
       break;
  }
    
  httpClient.end();
}

@roarfred
Copy link
Owner Author

We should also include a initial MQTT message, once connected to the MQTT, and include the FW_VERSION. This will prove the update succeeded. It is important to know the ESPhttpUpdate.update call will immediately cause a reset once completed (on success), so there is no option to report this status inside the update code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants