How to Flash a Blank ESP32 module

Discussion and support for the Nmea4Wifi multiplexer - a 4-input Nmea 0183 wifi multiplexer.
Post Reply
Luis Sa
Site Admin
Posts: 140
Joined: Thu May 04, 2017 4:12 am

How to Flash a Blank ESP32 module

Post by Luis Sa » Fri Mar 15, 2019 12:14 am

Hello,

If it happens that I release a new firmware with correction of bugs or improvements you can update your multiplexer either using a web browser as explained here:

https://www.vela-navega.com/nmea4wifi/d ... pdate.html

or using the Nmea4Wifi Windows tool as explained here:

https://www.vela-navega.com/nmea4wifi/d ... pdate.html

This is possible because the ESP32 module that comes with your multiplexer is prepared for update Over The Air (OTA). However if you get an ESP32 module from elsewhere (I am calling it a Blank ESP32 module) you can flash that module if you know how to use the Arduino IDE. Here is a simple sketch that prepares an ESP32 module to be able to receive a multiplexer BIN file by OTA update.

Code: Select all

/*    
   This small programme prepares an ESP32 module to be flashed Over The Air with
   an NMEA4WIFIVXX.BIN file. If your ESP32 module was supplied by vela-navega it is
   already prepared to be flashed with the BIN file. However if you want have an
   ESP32 module obtained elsewhere you need to run this small programme. It was 
   tested with Arduino IDE 1.8.7 using the ESP32 1.0.0 core.
   
   In the Tools menu make sure that you have the following settings:

   Board: "ESP32 Dev Module"
   Upload Speed: "921600"
   Flash Frequency: "80MHz"
   Flash Mode: "QIO"
   Flash Size: "4MB (32Mb)"
   Partition Scheme: "Minimal SPIFFS (Large Apps with OTA)"
   Core Debug Level: "None"
   PS RAM: "Disabled"
   Port: "COMX"  (please enter your COM port number instead of X)

   Once you upload this firmware to the ESP32 module, it will be prepaired to
   receive the NMEA4WIFIVXX.BIN file. You will notice that an Access Point
   with ssid NMEA4WIFI is created. You need to connect to this network using the
   password 12345678. Then in a browser you type 192.168.4.1:82 and you follow 
   similar steps found here:

   https://www.vela-navega.com/nmea4wifi/docs/nmea4wifi_files/FirmwareUpdate.html

   to upload the desidered NMEA4WIFIVXX.BIN file.
*/

#include <WiFi.h>
#include <WebServer.h>
#include <Update.h>

const char* ssidAP = "NMEA4WIFI";
const char* passAP = "12345678";

WebServer server(82);

void setup() {
  WiFi.softAP(ssidAP, passAP);
  delay(100);
  OtaSetting();
  delay(100);
}

void loop() {
  server.handleClient();
}

const char* str1 = "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><br><br><input type='submit' value='Update'></form>";

void OtaSetting() {
  server.on("/", HTTP_GET, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", str1);
    //    server.sendContent(str1);
  });
  /*handling uploading firmware file */
  server.on("/update", HTTP_POST, []() {
    server.sendHeader("Connection", "close");
    server.send(200, "text/html", (Update.hasError()) ? "<center>FAIL</center>" : "<center>SUCCESS</center>");
    ESP.restart();
  }, []() {
    HTTPUpload& upload = server.upload();
    if (upload.status == UPLOAD_FILE_START) {
      Serial.printf("Update: %s\n", upload.filename.c_str());
      if (!Update.begin(UPDATE_SIZE_UNKNOWN)) { //start with max available size
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_WRITE) {
      /* flashing firmware to ESP*/
      if (Update.write(upload.buf, upload.currentSize) != upload.currentSize) {
        Update.printError(Serial);
      }
    } else if (upload.status == UPLOAD_FILE_END) {
      if (Update.end(true)) { //true to set the size to the current progress
        Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
      } else {
        Update.printError(Serial);
      }
    }
  });
  server.begin();
}
Regards, Luis

Post Reply