14#ifdef USE_MQTT_NETWORKING
37String
_binName =
"/OTA/ESP_IOT.ino.m5stick_c_plus.bin";
42String
_binName =
"/OTA/OTA_Board/ESP_IOT.ino.esp32.bin";
45String
_binName =
"/OTA/ESP_IOT.ino.esp32.bin";
52 return header.substring(strlen(headerName.c_str()));
60 SerialDebug.println(
"Connecting to: " + String(
_hostIP) +
", bin = " + String(
_binName));
61#ifdef TRY_WITHOUT_THIS_MAYBE_OTHER_THREAD_GOOFS
62#ifdef USE_MQTT_NETWORKING
70#ifdef USE_DISPLAY_MODULE
86 SerialDebug.println(
"Fetching Bin: " + String(
_binName));
91 "Cache-Control: no-cache\r\n" +
92 "Connection: close\r\n\r\n");
100 unsigned long timeout = millis();
101 while (
_client.available() == 0) {
103 if (millis() - timeout > 5000) {
104 SerialDebug.println(
"Client Timeout !");
130 String line =
_client.readStringUntil(
'\n');
139 if (!line.length()) {
146 if (line.startsWith(
"HTTP/1.1")) {
147 if (line.indexOf(
"200") < 0) {
148 SerialDebug.println(
"Got a non 200 status code from server. Exiting OTA Update.");
155 if (line.startsWith(
"Content-Length: ")) {
157 SerialDebug.println(
"Content-Length: " + String(
_contentLength) +
" bytes from server");
161 if (line.startsWith(
"Content-Type: ")) {
163 SerialDebug.println(
"Got " + contentType +
" payload.");
164 if (contentType ==
"application/octet-stream") {
173 SerialDebug.println(
"Connection to " + String(
_hostIP) +
" failed. Please check your setup");
188 SerialDebug.println(
"Begin OTA streaming those bytes from the server..");
189 SerialDebug.println(
"This may take 2 - 5 mins to complete. Things might be quiet for a while.. Patience!");
192 size_t written = Update.writeStream(
_client);
195 SerialDebug.println(
"Written : " + String(written) +
" successfully *****");
197 SerialDebug.println(
"******* ERROR: Written only : " + String(written) +
"/" + String(
_contentLength));
203 SerialInfo.println(
"OTA done!");
204 if (Update.isFinished()) {
205 SerialDebug.println(
"Update successfully completed. Rebooting.");
210 SerialDebug.println(
"Update not finished? Something went wrong!");
211 for (
int i=0;i<3;i++)
217 SerialDebug.println(
"Error Occurred. Error #: " + String(Update.getError()));
218 for (
int i=0;i<3;i++)
227 SerialError.println(
"**** Not enough space to begin OTA ** REPORT THIS TO DEVELOPERS");
231 SerialError.println(
"There was no content in the response");
247 char *after = rindex(hostname,
'/');
263 SerialDebug.println(
"OTAImageUpdate.performOTAUpdateSimple");
void showOTAUpdatingMessage()
show an OTA message..
void sendMessageMQTT(char *message)
void stopProcessesForOTAUpdate_mainModule()
stop all loops... while OTA working..
void blinkMessageCallback(char *message)
callback for blinking led
void restartProcessesForOTAUpdate_mainModule()
restart all loops... while OTA working..
void performOTAUpdateSimple()
retrieves from constant location
int _port
Non https. For HTTPS 443. As of today, HTTPS doesn't work.
String getHeaderValue(String header, String headerName)
Utility to extract header value from headers.
char _binAddress[100]
address of bin string
void performOTAUpdate(char *hostname, char *httpAddress)
connects to host and grabs the http file and tries to update the binary (OTA)
String _binName
location of bin file