16#ifdef USE_REST_MESSAGING
17#include <WiFiClientSecure.h>
45String
_binName =
"/OTA/TEST/M5AtomS3/ESP_IOT.ino.m5stick_c_plus.bin";
46#elif defined(ESP_M5_ATOM_LITE)
47String
_binName =
"/OTA/TEST/M5Atom/ESP_IOT.ino.m5stick_c_plus.bin";
50String
_binName =
"/OTA/ESP_IOT.ino.m5stick_c_plus.bin";
56String
_binName =
"/OTA/OTA_Board/ESP_IOT.ino.esp32.bin";
59String
_binName =
"/OTA/ESP_IOT.ino.esp32.bin";
67String
_binName =
"/OTA/TEST/M5AtomS3/ESP_IOT.ino.m5stick_c_plus.bin";
68#elif defined(ESP_M5_ATOM_LITE)
69String
_binName =
"/OTA/TEST/M5Atom/ESP_IOT.ino.m5stick_c_plus.bin";
71String
_binName =
"/OTA/ESP_IOT.ino.m5stick_c_plus.bin";
72#elif defined(ESP_32) && defined(BOARD)
73String
_binName =
"/OTA/OTA_Board/ESP_IOT.ino.esp32.bin";
75String
_binName =
"/OTA/ESP_IOT.ino.esp32.bin";
81 return header.substring(strlen(headerName.c_str()));
89 SerialDebug.println(
"Connecting to: " + String(
_hostIP) +
", bin = " + String(
_binName));
90#ifdef TRY_WITHOUT_THIS_MAYBE_OTHER_THREAD_GOOFS
98#ifdef USE_DISPLAY_MODULE
114 SerialDebug.println(
"Fetching Bin: " + String(
_binName));
119 "Cache-Control: no-cache\r\n" +
120 "Connection: close\r\n\r\n");
128 unsigned long timeout =
millis();
129 while (
_client.available() == 0) {
131 if (
millis() - timeout > 5000) {
132 SerialDebug.println(
"Client Timeout !");
158 String line =
_client.readStringUntil(
'\n');
167 if (!line.length()) {
174 if (line.startsWith(
"HTTP/1.1")) {
175 if (line.indexOf(
"200") < 0) {
176 SerialDebug.println(
"Got a non 200 status code from server. Exiting OTA Update.");
183 if (line.startsWith(
"Content-Length: ")) {
185 SerialDebug.println(
"Content-Length: " + String(
_contentLength) +
" bytes from server");
189 if (line.startsWith(
"Content-Type: ")) {
191 SerialDebug.println(
"Got " + contentType +
" payload.");
192 if (contentType ==
"application/octet-stream") {
201 SerialDebug.println(
"Connection to " + String(
_hostIP) +
" failed. Please check your setup");
216 SerialDebug.println(
"Begin OTA streaming those bytes from the server..");
217 SerialDebug.println(
"This may take 2 - 5 mins to complete. Things might be quiet for a while.. Patience!");
220 size_t written = Update.writeStream(
_client);
223 SerialDebug.println(
"Written : " + String(written) +
" successfully *****");
225 SerialDebug.println(
"******* ERROR: Written only : " + String(written) +
"/" + String(
_contentLength));
231 SerialInfo.println(
"OTA done!");
232 if (Update.isFinished()) {
233 SerialDebug.println(
"Update successfully completed. Rebooting.");
238 SerialDebug.println(
"Update not finished? Something went wrong!");
239 for (
int i=0;i<3;i++)
245 SerialDebug.println(
"Error Occurred. Error #: " + String(Update.getError()));
246 for (
int i=0;i<3;i++)
255 SerialError.println(
"**** Not enough space to begin OTA ** REPORT THIS TO DEVELOPERS");
259 SerialError.println(
"There was no content in the response");
275 char *after = rindex(hostname,
'/');
291 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