#include "B4RDefines.h"
namespace B4R {
B4RString* B4RESP8266OTA::StringToB4R(String* o) {
PrintToMemory pm;
B4RString* s = B4RString:
rintableToString(NULL);
pm.print(*o);
StackMemory::buffer[StackMemory::cp++] = 0;
return s;
}
B4RString* B4RESP8266OTA::HTTPUpdate(B4RString* server, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError()) + " " + ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
// Return "ERROR" in case no switch case matched
s = "ERROR";
return StringToB4R(&s);
}
B4RString* B4RESP8266OTA::HTTPUpdate2(B4RString* server, int port, B4RString* filename, bool reboot) {
WiFiClient client;
String s;
ESPhttpUpdate.rebootOnUpdate(reboot);
t_httpUpdate_return ret = ESPhttpUpdate.update(client, server->data, port, filename->data);
switch(ret) {
case HTTP_UPDATE_FAILED:
s = String(ESPhttpUpdate.getLastError()) + " " + ESPhttpUpdate.getLastErrorString().c_str();
return StringToB4R(&s);
break;
case HTTP_UPDATE_OK:
s = "success";
return StringToB4R(&s);
break;
}
// Return "ERROR" in case no switch case matched
s = "ERROR";
return StringToB4R(&s);
}
void B4RESP8266OTA::ESPRestart(void) {
ESP.restart();
}
}