Community
OpenEnergyMonitor

OpenEnergyMonitor Community

Programming ESP32 on linux

Hi all,

Has anyone successfully programmed an ESP32 on linux? Stuarts video says to use nodemcu-pyflasher but there isn’t a linux build.

Thanks
Julian

From within PlatformIO use the default upload option. You may need to remove the upload_port declaration from the platformio.ini file though.

Thanks Mike but could you give me the idiots guide? I’m a hardware guy & have little clue with software & really struggle with toolchains.
I’ve downloaded the esp32 master .zip from github and dropped it into vscode but how do I make it active? When I switch to platformIO (hit the ant head on the left) there’s no folder under Project Tasks for the ESP32. The other indicator something isn’t set up right is the env: selector in the status bar at the bottom of vscode, the ESP32 isn’t in the list that brings up.

@stuart can you assist here?

Success! But yeah if Stuart happens to see this perhaps he can fill any mistakes in the below. I’m putting this here in case it is of use to anyone similarly stuck.

  1. In VSCodium close all open workspaces (File → Close Workspace)
  2. Download the source from github (See Stuarts videos for how to do this, I did it the ‘download zip’ method which I think was in an older video)
  3. Unzip on your local machine (path must not have a space in it, DAHIKT). I put it in ~\build.
  4. In VSCodium File → Open Workspace & navigate to the workspace file in the top level of the source folders just unzipped.
  5. In the blue status bar at the bottom of VSCodium click on env:somethingsomething. This opens a droplist of the available environments. Click on env:esp32-devkitc.
  6. In the folder tree collapse all the branches except ESPController and then double click platformio.ini. This opens the .ini file for editing.
  7. Find and comment out (put a semicolon in front of) upload_port (Thanks again Mike)
  8. Click on the ant / alien head symbol at the left of VSCodium
  9. Plug your ESP32 in.
  10. Under Project Tasks → esp32-devkitc → General click Upload

I got a few warnings during the compile but it worked and I now have the controller board flashing its LED red/white at me so I’m off to re-watch the next part of the video.

Ah, I’m not there after all :frowning:
red / white must be an error state. In putty it says:

E (69) esp_littlefs: mount failed (-84)
E (73) esp_littlefs: Failed to initialise LittleFS
[E]{LITTLEFS.cpp:90] begin(): Mounting LITTLEFS failed! Error: -1
[E][main.cpp:3322] setup(): LITTLEFS mount failed, did you upload the file system image?
[E][HAL_ESP32.h:181] Halt(): SYSTEM HALTED

I’m guessing there’s more to the hex file uploaded to github by Stuart than just the program. I was wondering about that but I thought the module images might be missing working this way. I didn’t know enough to realise there’s be a filesystem image needed.

That ones easy to fix - use the VSCode UPLOAD FILE SYSTEM IMAGE option, along with the upload code option.

Got it thanks @stuart, I have a working controller :slightly_smiling_face: However, as suspected the module images are missing

I looked at the readme in /data and jumped to what I now think is a wrong conclusion. I thought by putting the module image I need into data/avr/ it would get included in the filesystemimage .bin. That didn’t work.

I can’t figure it out from the github actions file either, I can’t see how the compiled bins or hexes in /OUTPUT/Modules/ end up within the objects referenced by the esptool command.

OK, I now understand how the module hex files get into the controller filesystemimage :slight_smile:
I also understand that putting the .hex file into /data/avr is correct and why it didn’t work for me :slight_smile:
All has been revealed by the GenerateBinaryFile.py script but there’s a problem running that locally :slightly_frowning_face:

This line in the buildscript_versioning.py causes the V421 code build to halt (before any compilation is done because it is a pre: script)

env.Append(git_sha_short=git_sha[32:])

I’ll raise an issue. I think the line is failing because git_sha=None. It shouldn’t, I have git installed but the case should be handled.

Another way is to use the pre-compiled binary file and the ESPTOOL python script.

If you look at this page [diyBMSv4ESP32/ProgrammingHardware.md at master · stuartpittaway/diyBMSv4ESP32 · GitHub]

You can see the actual command line the NodeMCU flash tool uses - the esptool.py is a generic script which works on LINUX.

esptool.py --port COM4 --baud 921600 --after no_reset write_flash --flash_mode dout 0x00000 esp32-controller-firmware-complete.bin --erase-all

Cheers again Stuart.

I was looking for that command so thanks, I’ll try that way too. I have now successfully built the controller with the V421 module in it.

I thought git_sha might be not Null if I got the code via git:clone instead of downloading the .zip. Well, cloning the code worked but not for the reason I expected. Pulling the code gives a different buildscript_versioning.py to what is in the master .zip. It was all downhill from there.