I want to update software OTA on multiple of my nodemcu devices that are currently sending data to my firebase database. I found this tutorial (https://medium.com/firebase-developers/over-the-air-arduino-firmware-updates-using-firebase-part-1-3e874ad9f93e) for ESP32 and tried adapting it to work with one of my nodemcu however it writes no binary and "gives up". I am not sure why/how to modify the code further. I am currently running core 2.7.4 as upgrading does not allow me to upload code to my nodemcu.
I have attached part of my code below and output I get in serial monitor. I am able to connect to wifi, change my "updatebit", and send data to firebase so there is no issue there.
#include <Firebase.h>
#include <FirebaseArduino.h>
#include <FirebaseCloudMessaging.h>
#include <FirebaseError.h>
#include <FirebaseHttpClient.h>
#include <FirebaseObject.h>
//#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>
#include "Updater.h"
#include "ESP8266WiFi.h"
#include "ESP8266HTTPClient.h"
#define FIREBASE_HOST "..."
#define FIREBASE_AUTH "..."
#define FIRMWARE_URL \
"http://..."
HTTPClient http;
void setup() {
....
}
void loop() {
if(updatebit==1){
updateFirmware();
} else {
}
}
void updateFirmware() {
// Start pulling down the firmware binary.
http.begin(FIRMWARE_URL);
int httpCode = http.GET();
if (httpCode <= 0) {
Serial.printf("HTTP failed, error: %s\n",
http.errorToString(httpCode).c_str());
return;
}
// Check that we have enough space for the new binary.
int contentLen = http.getSize();
Serial.printf("Content-Length: %d\n", contentLen);
bool canBegin = Update.begin(contentLen);
if (!canBegin) {
Serial.println("Not enough space to begin OTA");
return;
}
// Write the HTTP stream to the Update library.
WiFiClient* client = http.getStreamPtr();
size_t written = Update.writeStream(*client);
Serial.printf("OTA: %d/%d bytes written.\n", written, contentLen);
if (written != contentLen) {
Serial.println("Wrote partial binary. Giving up."); //content length printed in serial
monitor is 42 but 0/42 bytes are written and it says "Wrote partial binary. Giving up."
return;
}
if (!Update.end()) {
Serial.println("Error from Update.end(): " +
String(Update.getError()));
return;
}
if (Update.isFinished()) {
Firebase.setInt("updatebit",0);
Serial.println("Update successfully completed. Rebooting.");
// This line is specific to the ESP32 platform:
ESP.restart();
} else {
Serial.println("Error from Update.isFinished(): " +
String(Update.getError()));
return;
}
}
If I add the "s" in http changing from
#define FIRMWARE_URL \
"http://..."
to
#define FIRMWARE_URL \
"https://..."
I get "HTTP failed, error: connection failed" in serial monitor
if (httpCode <= 0) {