mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-28 21:56:35 +00:00
Add webupdate
This commit is contained in:
parent
f1a3e782da
commit
7cb167a632
@ -8,10 +8,27 @@
|
|||||||
#include "hasp_ota.h"
|
#include "hasp_ota.h"
|
||||||
|
|
||||||
#include "hasp_conf.h"
|
#include "hasp_conf.h"
|
||||||
|
|
||||||
#if HASP_USE_MQTT
|
#if HASP_USE_MQTT
|
||||||
#include "hasp_mqtt.h"
|
#include "hasp_mqtt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HASP_USE_MDNS
|
||||||
|
#include "hasp_mdns.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
#include <ESP8266HTTPClient.h>
|
||||||
|
#include <ESP8266httpUpdate.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#else
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
#include <HTTPUpdate.h>
|
||||||
|
#include <WiFi.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
WiFiClient wifiClient;
|
||||||
|
|
||||||
#define F_OTA_URL F("otaurl")
|
#define F_OTA_URL F("otaurl")
|
||||||
|
|
||||||
std::string otaUrl = "http://10.1.0.3";
|
std::string otaUrl = "http://10.1.0.3";
|
||||||
@ -108,4 +125,59 @@ void otaLoop()
|
|||||||
void otaEverySecond()
|
void otaEverySecond()
|
||||||
{
|
{
|
||||||
if(otaPrecentageComplete >= 0) otaProgress();
|
if(otaPrecentageComplete >= 0) otaProgress();
|
||||||
|
}
|
||||||
|
|
||||||
|
void otaHttpUpdate(const char * espOtaUrl)
|
||||||
|
{ // Update ESP firmware from HTTP
|
||||||
|
// nextionSendCmd("page 0");
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP update\\rstarting...\"");
|
||||||
|
mdnsStop(); // Keep mDNS responder from breaking things
|
||||||
|
|
||||||
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
|
t_httpUpdate_return returnCode = ESPhttpUpdate.update(wifiClient, espOtaUrl);
|
||||||
|
|
||||||
|
switch(returnCode) {
|
||||||
|
case HTTP_UPDATE_FAILED:
|
||||||
|
Log.error("FWUP: HTTP_UPDATE_FAILED error %d %s", ESPhttpUpdate.getLastError(),
|
||||||
|
ESPhttpUpdate.getLastErrorString().c_str());
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\"");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
|
Log.notice(F("FWUP: HTTP_UPDATE_NO_UPDATES"));
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\"");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_OK:
|
||||||
|
Log.notice(F("FWUP: HTTP_UPDATE_OK"));
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\"");
|
||||||
|
dispatchReboot(true);
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
t_httpUpdate_return returnCode = httpUpdate.update(wifiClient, espOtaUrl);
|
||||||
|
|
||||||
|
switch(returnCode) {
|
||||||
|
case HTTP_UPDATE_FAILED:
|
||||||
|
Log.error("FWUP: HTTP_UPDATE_FAILED error %i %s", httpUpdate.getLastError(),
|
||||||
|
httpUpdate.getLastErrorString().c_str());
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rFAILED\"");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_NO_UPDATES:
|
||||||
|
Log.notice(F("FWUP: HTTP_UPDATE_NO_UPDATES"));
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rNo update\"");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case HTTP_UPDATE_OK:
|
||||||
|
Log.notice(F("FWUP: HTTP_UPDATE_OK"));
|
||||||
|
// nextionSetAttr("p[0].b[1].txt", "\"HTTP Update\\rcomplete!\\r\\rRestarting.\"");
|
||||||
|
dispatchReboot(true);
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
mdnsStart();
|
||||||
|
// nextionSendCmd("page " + String(nextionActivePage));
|
||||||
}
|
}
|
@ -6,5 +6,6 @@
|
|||||||
void otaSetup(JsonObject settings);
|
void otaSetup(JsonObject settings);
|
||||||
void otaLoop(void);
|
void otaLoop(void);
|
||||||
void otaEverySecond(void);
|
void otaEverySecond(void);
|
||||||
|
void otaHttpUpdate(const char * espOtaUrl);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user