16#ifdef USE_REST_MESSAGING
17#include <WiFiClientSecure.h>
43String
_binName =
"/OTA/ESP_IOT.ino.m5stick_c_plus.bin";
48String
_binName =
"/OTA/OTA_Board/ESP_IOT.ino.esp32.bin";
51String
_binName =
"/OTA/ESP_IOT.ino.esp32.bin";
58 return header.substring(strlen(headerName.c_str()));
66 SerialDebug.println(
"Connecting to: " + String(
_hostIP) +
", bin = " + String(
_binName));
67#ifdef TRY_WITHOUT_THIS_MAYBE_OTHER_THREAD_GOOFS
75#ifdef USE_DISPLAY_MODULE
91 SerialDebug.println(
"Fetching Bin: " + String(
_binName));
96 "Cache-Control: no-cache\r\n" +
97 "Connection: close\r\n\r\n");
105 unsigned long timeout =
millis();
106 while (
_client.available() == 0) {
108 if (
millis() - timeout > 5000) {
109 SerialDebug.println(
"Client Timeout !");
135 String line =
_client.readStringUntil(
'\n');
144 if (!line.length()) {
151 if (line.startsWith(
"HTTP/1.1")) {
152 if (line.indexOf(
"200") < 0) {
153 SerialDebug.println(
"Got a non 200 status code from server. Exiting OTA Update.");
160 if (line.startsWith(
"Content-Length: ")) {
162 SerialDebug.println(
"Content-Length: " + String(
_contentLength) +
" bytes from server");
166 if (line.startsWith(
"Content-Type: ")) {
168 SerialDebug.println(
"Got " + contentType +
" payload.");
169 if (contentType ==
"application/octet-stream") {
178 SerialDebug.println(
"Connection to " + String(
_hostIP) +
" failed. Please check your setup");
193 SerialDebug.println(
"Begin OTA streaming those bytes from the server..");
194 SerialDebug.println(
"This may take 2 - 5 mins to complete. Things might be quiet for a while.. Patience!");
197 size_t written = Update.writeStream(
_client);
200 SerialDebug.println(
"Written : " + String(written) +
" successfully *****");
202 SerialDebug.println(
"******* ERROR: Written only : " + String(written) +
"/" + String(
_contentLength));
208 SerialInfo.println(
"OTA done!");
209 if (Update.isFinished()) {
210 SerialDebug.println(
"Update successfully completed. Rebooting.");
215 SerialDebug.println(
"Update not finished? Something went wrong!");
216 for (
int i=0;i<3;i++)
222 SerialDebug.println(
"Error Occurred. Error #: " + String(Update.getError()));
223 for (
int i=0;i<3;i++)
232 SerialError.println(
"**** Not enough space to begin OTA ** REPORT THIS TO DEVELOPERS");
236 SerialError.println(
"There was no content in the response");
252 char *after = rindex(hostname,
'/');
268 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
WiFiClient _client
8.16.25 MQTT
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)
8.16.25 MQTT
String _binName
location of bin file