How to Flash a Blank ESP32 module

Discussion and support for the Nmea4Wifi multiplexer - a 4-input Nmea 0183 wifi multiplexer.
Luis Sa
Site Admin
Posts: 845
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,

(in May 2021 I added another post about this subject that does not requires arduino)

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

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.10 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

Norbert
Posts: 3
Joined: Sun Jun 16, 2019 4:10 pm

Re: How to Flash a Blank ESP32 module

Post by Norbert » Mon Jun 17, 2019 4:44 pm

Hello Luis,

did not work with flash the Firmware.
I have now continous reboot from the Module.

18:42:27.537 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
18:42:27.537 -> configsip: 0, SPIWP:0xee
18:42:27.537 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
18:42:27.537 -> mode:DIO, clock div:1
18:42:27.537 -> load:0x3fff0018,len:4
18:42:27.537 -> load:0x3fff001c,len:1100
18:42:27.537 -> load:0x40078000,len:9232
18:42:27.537 -> load:0x40080400,len:6400
18:42:27.537 -> entry 0x400806a8
18:42:27.818 ->
18:42:36.352 -> rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
18:42:36.352 -> configsip: 0, SPIWP:0xee
18:42:36.352 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
18:42:36.352 -> mode:DIO, clock div:1
18:42:36.352 -> load:0x3fff0018,len:4
18:42:36.352 -> load:0x3fff001c,len:1100
18:42:36.398 -> load:0x40078000,len:9232
18:42:36.398 -> load:0x40080400,len:6400
18:42:36.398 -> entry 0x400806a8
18:42:36.726 ->

Can you me help , please

Regards Norbert

Luis Sa
Site Admin
Posts: 845
Joined: Thu May 04, 2017 4:12 am

Re: How to Flash a Blank ESP32 module

Post by Luis Sa » Mon Jun 17, 2019 6:16 pm

Hello,

Are you trying to flash a module that you got elsewhere or the module included in the multiplexer?

Please explain.

Regards Luis

Norbert
Posts: 3
Joined: Sun Jun 16, 2019 4:10 pm

Re: How to Flash a Blank ESP32 module

Post by Norbert » Tue Jun 18, 2019 5:59 pm

Hello,

i have tried to flash a new wemos module .
I demolished the USB port from the original modul.:-(

Regards Norbert

Luis Sa
Site Admin
Posts: 845
Joined: Thu May 04, 2017 4:12 am

Re: How to Flash a Blank ESP32 module

Post by Luis Sa » Tue Jun 18, 2019 7:11 pm

Hello,

OK! If the module is the same as the one in the multiplexer you can use the small sketch in this topic. I used it with Arduino Ide version 1.8.7 without problems. Please read and follow the options that are commented in the sketch.

Regards Luis

Norbert
Posts: 3
Joined: Sun Jun 16, 2019 4:10 pm

Re: How to Flash a Blank ESP32 module

Post by Norbert » Tue Jun 18, 2019 8:22 pm

Hello,
it's my fault, i have wrong "ESP32 1.0.2 core" taken, with 1.0.0 works.
Thanks for the answer.
Regards Norbert

dagnall
Posts: 459
Joined: Wed Mar 04, 2020 6:36 pm

Re: How to Flash a Blank ESP32 module

Post by dagnall » Fri Aug 28, 2020 5:28 pm

Luis.
I have just had a frustrating day. I was trying to test a lot of my Apps to see which can read the Seatalk DBT message, but somehow during this the NMEA4WIFI stopped. --I will put the results I did get in the other "depth" thread.

My problem came when the WIFI signal disappeared.: The red light top left was regularly flashing, (And the tiny red light was "On" on the regulator board) but none of the green leds on the IO ports were flashing and I could no longer see the WIFI signal for NMEA4WIFI. I was surprised nothing was flashing, as the instruments were working and should be sending data...
I have the Module now at home and checked the Arduino reflash procedure on a spare esp32 before trying the "suspect" one from the boat. I write this to help others having the same problems..
  • I found that Arduino 1.8.10, with esp32 boards version 1.0.4 will upload to my known good board.
  • The module's wifi is then visible
  • After connecting to the wifi "NMEA4WIFI" , the NEMA4WIFI.exe will "connect"
    • (BUT note that you cannot read "settings" (presumably they are not stored yet?)
  • I CAN "Update Firmware"
  • So now I have a test module, and I know the re-flash process works. :)
:!: Please note that the new Arduino has another parameter "CPU frequency". I used 240MHz (Wifi/BT) and it worked. i am not sure if this makes any difference, and have not tried the other frequency options.

Unfortunately, with my "proper" WEMOS from the boat, and following the same process, I get this error message from Arduino, :cry:

Code: Select all

esptool.py v2.6
Serial port COM4
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: a4:cf:12:4c:4d:34
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Warning: Could not auto-detect Flash size (FlashID=0xffffff, SizeID=0xff), defaulting to 4MB
Compressed 8192 bytes to 47...

A fatal error occurred: Timed out waiting for packet content
:oops: So I presume my "proper" module somehow died - It looks like the flash is corrupted?
:?: :?: Luis.. Do you agree this module is now dead- or have you any suggestions to bring it back to life?
Is there any way to use the ESP "flashdownload tools V3.6.8" ? They seem very comprehensive?

I have managed to order a replacement "x-esp32" module the same as the NMEA4WIFI on ebay, But they are very rare!!

:?: Why did you choose that particular ESP32 Module?- It is difficult to find replacements.
:!: Just an idea!, but if you do ever do another re-design of the PCB, could you consider using a more easily available ESP32 module?
The "WEMOS LOLIN32 ESP32 Lite V1.0". is nice and programs easily..(no "BOOT" button issues! and is cheap and easily available.) Its what I used to check the programming sequence- so now I have a module at home pretending to be a NMEA4WIFI!.- useful for testing in simulation mode.. ;)
cheers Dagnall

Luis Sa
Site Admin
Posts: 845
Joined: Thu May 04, 2017 4:12 am

Re: How to Flash a Blank ESP32 module

Post by Luis Sa » Fri Aug 28, 2020 6:15 pm

Hello,


Thank you for your post. I could not follow your sequence of experiments. Is the ESP32 module that came with the multiplexer dead? Can you flash the blink sketch?

If you got a replacement you should flash the small "OTA preparation sketch" and then use OTA to update whatever firmware you need.

The reason I chose this particular module is the size. I thought once to change to this one

https://www.ebay.co.uk/itm/MINI-Wemos-D ... SwZEtdrwft

In September, 15 I return to Portugal and will look to this problem in more detail.
Best Regards, Luis (in Koufos, Greece)

dagnall
Posts: 459
Joined: Wed Mar 04, 2020 6:36 pm

Re: How to Flash a Blank ESP32 module

Post by dagnall » Fri Aug 28, 2020 9:36 pm

Luis.
Thanks or fast reply- And sorry I sent two long forum post so quickly..
I will call the board from the NMEA4WIFI that you supplied (board 1), and my "spare" lolin32 board (board 2).

Sequence of events / experiments in the previous two posts was:
  • On boat, checking what apps respond to the Seatalk depth
  • Did a lot of tests with the apps noted in post, then started exploring with Weather4d, which has a NMEA viewer and lots of NMEA option.
  • I was trying to find what it was accepting, and was switching between TCP and UDP - also I was turning on and off settings on 192.168.4.1 using the HTTP server in NMEA4WIFI. I had an Ipad changing the settings, and was using an Iphone with Weather4d.
  • At some point the ESP32 (board 1) stopped working.
  • I came home and tried to reflash the original ESP32 (Board 1). (I may have tried to use the ESP tool to directly flash the binary first- which was probably a mistake)
  • To check out the "official" reflash process I used the Arduino sketch you supplied in Arduino.
  • Because I saw that another user had issues with ESP32 board version 1.0.2, I tested with 1.0.4 (latest) and also 1.0.0
  • My blank ESP32 board (Board 2) accepted the OTA preparation sketch and I connected to it as AP, and also updated the binary. I did this several times using either the .exe or the 192.168.4.1:82 method.
  • All seemed clear, (I had broken Board 1 but Board 2 was working), So I wrote the first post to help anyone doing anything similar.
  • With (board 2) now correctly working I wanted to give you the results of the app compatibility test and so I started trying to explore the Weather4d responses again - but now using (board 2) and "simulation mode
  • At some point during these experiments all "stopped working" again..
  • At this point I was still able to re-flash the OTA preparation sketch using Arduino into board 2 again and could update the binary using either the exe or the :82 method.. BUT NOW, as soon as I upload the binary (v 34), I get the very strange IPhone disconnect sequence as described elsewhere. - It is possible that this is also what happened on the boat, but I did not actually see this effect at the time (as I was not looking for it).
  • At this point I stopped the experiments and wrote the second post and had supper....
Now for some new data..
After reading "recovery from lock down" it seemed as though my board was experiencing the same issue.. so I set my Iphone wifi settings to Configure IP: Manual :IP address 192.168.4.7 ;subnet mask 255.255.0.0; Router 192.168.4.1.
And the connection (with board 2) is now stable again :!:
I have been able to connect to the setup page and have reset to factory defaults.
Then I set TCP port to 3000 and switched on all sends to TCP.
I had to explore more so...new list of experiment and result---s:
  • with the Iphone wifi set to manual as above, the connection is stable.
  • I can open the 192.168.4.1 page in chrome and go to the simulation mode.
  • I can change back to auto IP and the "disconnect - 3 sec cycle" seems to be repeatable.
  • But all is not working fully.. With the Manual IP setting, I have used Seanav UK (as it has a nice simple TCP/UDP select with a view of any recieved data) to explore what data is being sent.
  • Short Summary: I can see "tcp" data on 192.168.4.1:3000,
  • But cannot see any udp data on port 2000 :cry:
(NB, on my PC I cannot open 192.168.4.1 in chrome, even though the nmea4WIFI wifi connection appears stable. I do not seem to be able to set the Manual IP settings (what DNS should I set?) but have done enough for tonight. )

Time for bed.. any thoughts gratefully accepted.. I have tried to give full explanations to help you follow what I have been doing- but I am sorry the resultant post is so long.


Cheers

Dagnall
Last edited by dagnall on Sat Aug 29, 2020 9:27 am, edited 1 time in total.

dagnall
Posts: 459
Joined: Wed Mar 04, 2020 6:36 pm

Re: How to Flash a Blank ESP32 module

Post by dagnall » Fri Aug 28, 2020 9:57 pm

Update- hopefully before you read this..
I did an update with V 1.0.0 and thought that it had cured the regular on off of the wifi, but checking again this morning, with my I pad, it did not.
IPad (auto IP ) locks into WIFI, then promptly disconnects.

Iphone, (with manual IP settings) can lock into the WIFI.
D

Post Reply