mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 13:16:45 +00:00
Add otaUpdateCheck
This commit is contained in:
parent
61d1746c26
commit
9afcac61de
@ -28,6 +28,48 @@ std::string otaUrl = "http://ota.netwize.be";
|
||||
int16_t otaPort = HASP_OTA_PORT;
|
||||
int8_t otaPrecentageComplete = -1;
|
||||
|
||||
bool otaUpdateCheck()
|
||||
{ // firmware update check
|
||||
WiFiClientSecure wifiUpdateClientSecure;
|
||||
HTTPClient updateClient;
|
||||
Log.notice(TAG_OTA, F("UPDATE: Checking update URL: %s"), otaUrl.c_str());
|
||||
|
||||
// wifiUpdateClientSecure.setInsecure();
|
||||
// wifiUpdateClientSecure.setBufferSizes(512, 512);
|
||||
updateClient.begin(wifiUpdateClientSecure, otaUrl.c_str());
|
||||
|
||||
int httpCode = updateClient.GET(); // start connection and send HTTP header
|
||||
if(httpCode != HTTP_CODE_OK) {
|
||||
Log.error(TAG_OTA, F("Update check failed: %s"), updateClient.errorToString(httpCode).c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
DynamicJsonDocument updateJson(1024);
|
||||
DeserializationError jsonError = deserializeJson(updateJson, updateClient.getString());
|
||||
updateClient.end();
|
||||
|
||||
if(jsonError) { // Couldn't parse the returned JSON, so bail
|
||||
Log.error(TAG_OTA, F("JSON parsing failed: %s"), jsonError.c_str());
|
||||
// mqttClient.publish(mqttStateJSONTopic,
|
||||
// String(F("{\"event\":\"jsonError\",\"event_source\":\"updateCheck()\",\"event_description\":"
|
||||
// "\"Failed to parse incoming JSON command with error\"")) +
|
||||
// String(jsonError.c_str()));
|
||||
return false;
|
||||
} else {
|
||||
if(!updateJson["d1_mini"]["version"].isNull()) {
|
||||
// updateEspAvailableVersion = updateJson["d1_mini"]["version"].as<float>();
|
||||
// debugPrintln(String(F("UPDATE: updateEspAvailableVersion: ")) + String(updateEspAvailableVersion));
|
||||
// espFirmwareUrl = updateJson["d1_mini"]["firmware"].as<String>();
|
||||
// if(updateEspAvailableVersion > haspVersion) {
|
||||
// updateEspAvailable = true;
|
||||
// debugPrintln(String(F("UPDATE: New ESP version available: ")) + String(updateEspAvailableVersion));
|
||||
// }
|
||||
}
|
||||
Log.verbose(TAG_OTA, F("UPDATE: Update check completed"));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline void otaProgress(void)
|
||||
{
|
||||
Log.verbose(TAG_OTA, F("%s update in progress... %3u%"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user