Tuesday, December 12, 2023

0000 0000 1101 1001

Remote Updates

You know those moments when you are stuck thousands of kilometres from your home (computer) and you need to change the code on an ESP32 chugging along on doing some ground breaking science?

Well in that situation, how would you update the code? How might you download any stored data? How is it possible for you upload a new file (e.g. the html interface) to the LittleFS file system onboard?

I have thought about this quite a bit, and in fact I've chatted with ChatGPT about this over a few months now, and here is what I/we've come up with:


  • Your ESP32 IoT device is out there in the field doing its thing.
  • The code needs to be changed, but the device is a long way away from a network
  • Make the new code and then export it as a bin file back at your home/lab/office
  • There are maybe some other files that also need to be uploaded/downloaded
  • A mobile device is then used to hold the new bin file and other files
  • You go find your device (using a boat?) and log in securely
  • Upload your new code
  • Upload/download any new files from the LittleFS filesystem
  • Return triumphantly to your home/lab/office.
  • Enjoy a cleansing ale

Further to this idea, it's not fun to look in one single large code file to make the necessary changes, it is better to have the code as modular as possible and only find/change what is necessary. Here's another picture to help explain this aspect.


So the file architecture is as follows:

  • The main ino file that contains all of my code to make this remote loading possible - there should be minimal changes to this file
  • MyMain.h is a file that contains YOUR project code - whether that be a simple blinky or something sophisticated that for instance measures and stores data and also responds to that data. I'm thinking here of measuring temperature and...er...blinking an LED!
  • A data folder that is used in a LittleFS filesystem which contains:
    • the main.html file where you can introduce any normal html structures suitable for your project - this file should always contain a link to...
    • the upload.html file where you can upload a new binary file, or indeed upload/download any files needed in the project (including this one!)
    • an access.html file which can upload/download and delete files from the LittleFS file system on the ESP
    • a style sheet in case you want to change all styles simultaneously
    • any other files for the project (e.g. a file of collected data, or an mp3 file, or pictures, etc), held in the LittleFS. I've used a little avatar picture from my YT channel as an example.
I think the important thing is to have an overview of how this project could work for you. Maybe go straight to the video below and let me know what you think in the YouTube comments section.

Further work to be explored perhaps includes:

1. A deeper dive into the code including some exploration of how both cores of the ESP32 are used (one for the main.h code and one for the OTA update code)

2. A look at security issues including LittleFS encryption and password management.

3. Error checking on file uploads/deletions and partition management

5. Binary production and distribution

6. A discussion about what happened to point 4, above.

All the code is on the github site for you to download and play with - have at it!

So now let's dive into the video and maybe come back in a 2nd and maybe 3rd episode/post for all the juicy deets.




4 comments:

  1. Hello, first off great idea(I'm a fellow Aussie). I am trying to implement your code, I can see and join the network created by the ESP32 but when I go to the IP address my browser tells me I can not connect. I have have uploaded the data files to the ESP32. Please any ideas as to why I can't reach the web pages?

    ReplyDelete
    Replies
    1. If you follow the comments under the YT vid, there seems to be some issue with some versions of the LittleFS java uploader. I'm pretty sure I used this one (https://github.com/lorol/LITTLEFS) and uploaded via the Arduino 1.x.x version of the IDE. Getting the combo right for your hardware is pretty crucial, particularly when the software keeps being updated. Please try that and then leave a comment under the YT blog. Whichever way it goes I think I might need to post a new video and blog on the software/hardware combo that worked for me.

      Delete
    2. Turns out it was a browser issue, if I use Microsoft Edge every thing works!

      Delete
    3. Excellent news - I've updated the YT description for the "working" java file just in case. Good luck with your project!

      Delete