Action Item #1186
closedPort imlightsw to arduino-cli
100%
Description
The README.md tells how to clone repos.
I can switch this to use submodules for all remote repo dependencies.
Alternatively, I can just use a submodule for makeEspArduino and then have the user clone Arduino repos to external directories.
Also alternatively, I could have the user install the Arduino CLI and utilize that to install required libraries.
- Online programming tool from espressif (doesn't work on my box)
- Arduino ESP Getting Started Guide
- MakeESPArduino
- ESPTool Releases
Updated by Hammel 10 days ago
- % Done changed from 0 to 10
First step: try to reproduce old build.
This works if I following the README.md to the letter (changing "arduino" to "Arduino" in paths in the source Makefile), and also symlink the old xtensa gcc toolchain under the new Arduino/tools tree, as in:
ln -s ~/.arduino15.old/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2 xtensa-lx106-elf
This is .arduino15.old because the arduino-cli created a new one when I installed it.
The build completed but at this point I'm missing the esptool:
/bin/sh: 1: /home/mjhammel/src/ximba/arduino/esp8266/Arduino//tools/esptool/esptool: not found
So it's a path problem again, most likely.
Updated by Hammel 9 days ago
Downloaded esptool 4.8.1, which is a binary release (not python). Unpacked it under /home/mjhammel/src/ximba/arduino/esp8266/Arduino//tools/ and moved the toplevel directory to "esptool", which is where the build seems to want it.
I then had to change the perms on esptool/esptool because, out of the archive, the binary had 644 perms. Changing to 755 allowed it to be run. However, the build still fails because the version of makeEspArduino I installed doesn't work with that version of esptool.
usage: esptool [-h]
[--chip {auto,esp8266,esp32,esp32s2,esp32s3beta2,esp32s3,esp32c3,esp32c6beta,esp32h2beta1,esp32h2beta2,esp32c2
,esp32c6,esp32c61,esp32c5,esp32c5beta3,esp32h2,esp32p4}]
[--port PORT] [--baud BAUD] [--port-filter PORT_FILTER]
[--before {default_reset,usb_reset,no_reset,no_reset_no_sync}]
[--after {hard_reset,soft_reset,no_reset,no_reset_stub}] [--no-stub] [--trace]
[--override-vddsdio [{1.8V,1.9V,OFF}]] [--connect-attempts CONNECT_ATTEMPTS]
{load_ram,dump_mem,read_mem,write_mem,write_flash,run,image_info,make_image,elf2image,read_mac,chip_id,flash_i
d,read_flash_status,write_flash_status,read_flash,verify_flash,erase_flash,erase_region,read_flash_sfdp,merge_bin,get_securit
y_info,version}
...
esptool: error: argument operation: invalid choice: '/home/mjhammel/src/ximba/arduino/esp8266/Arduino//bootloaders/eboot/eboo
t.elf' (choose from 'load_ram', 'dump_mem', 'read_mem', 'write_mem', 'write_flash', 'run', 'image_info', 'make_image', 'elf2i
mage', 'read_mac', 'chip_id', 'flash_id', 'read_flash_status', 'write_flash_status', 'read_flash', 'verify_flash', 'erase_fla
sh', 'erase_region', 'read_flash_sfdp', 'merge_bin', 'get_security_info', 'version')
make: *** [/home/mjhammel/src/ximba/arduino/esp8266/makeEspArduino/makeEspArduino.mk:260: /home/mjhammel/src/ximba/xarduino/l
ightsw/bld/imlightsw.bin] Error 2
The problem is in makeEspArduino.mk:260, which calls ELF2BIN_COM. Printing that out in showconfig I get this.
ELF2BIN_COM : /home/mjhammel/src/ximba/arduino/esp8266/Arduino//tools/esptool/esptool -eo /home/mjhammel/src/ximba/arduino/esp8266/Arduino//bootloaders/eboot/eboot.elf \
-bo /home/mjhammel/src/ximba/xarduino/lightsw/bld/imlightsw.bin -bm qio -bf 40 -bz 1M -bs .text -bp 4096 -ec -eo /home/mjhammel/src/ximba/xarduino/lightsw/bld/imlightsw.elf \
-bs .irom0.text -bs .text -bs .data -bs .rodata -bc -ec
The args used don't come close to matching what the tools wants. I'm guessing esptool needs to be the python version instead. A python version is available in
/home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/esptool
So I could symlink that to
/home/mjhammel/src/ximba/arduino/esp8266/Arduino//tools/esptool/
and see if that works (though esptool is not there - it's esptool.py).
Updated by Hammel 8 days ago
esptool was installed by bump Arduino from 2.1 to 3.1.2. Doing this create esptool directory, but that directory is empty.
But that doesn't matter, yet. By bumping to 3.1.2 the build no longer works. It fails with this.
sqrt32.cpp
core_esp8266_waveform_pwm.cpp
In file included from /home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/Arduino.h:234:0,
from /home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/core_esp8266_waveform_pwm.cpp:42:
/home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/mmu_iram.h:119:4: warning: #warning "MMU_IRAM_SIZE was undefi
ned, setting to 0x8000UL!" [-Wcpp]
#warning "MMU_IRAM_SIZE was undefined, setting to 0x8000UL!"
^
In file included from /home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/Arduino.h:292:0,
from /home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/core_esp8266_waveform_pwm.cpp:42:
/home/mjhammel/src/ximba/arduino/esp8266/Arduino//cores/esp8266/pgmspace.h:8:26: fatal error: sys/pgmspace.h: No such file or
directory
#include <sys/pgmspace.h>
^
compilation terminated.
make: *** [/home/mjhammel/src/ximba/arduino/esp8266/makeEspArduino/makeEspArduino.mk:122: /home/mjhammel/src/ximba/xarduino/l
ightsw/bld/obj/core_esp8266_waveform_pwm.cpp.o] Error 1
Looks at Arduino/coresw/esp8255/pgmspace.h we see that sys/pgmspace.h is no longer included in esp8266:
// This file's contents have been moved to newlib. This file simply
// includes the newlib pgmspace file as well as some ets headers
// to preserve backwards compatibility
// current source: https://github.com/earlephilhower/newlib-xtensa/blob/xtensa-4_0_0-lock-arduino/newlib/libc/sys/xtensa/sys/pgmspace.h
So I have to find that library (newlib) and install it too.
At this point I can either continue down the path of upgrading everything starting with Arduino and makeEspArduino.mk to latest versions, or I can just try to migrate the build to use arduino-cli. The latter might be easier. I need to review the getting started video to see how to install external libraries.
Updated by Hammel 8 days ago
I tried it with arduino-cli (aliased to ac ). The first caveat is that the directory is passed to the compile command and the "main" needs to be named the same thing, as in PiBox/PiBox.ino.
$ ac compile -b esp8266:esp8266:generic PiBox
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino:25:10: fatal error: AES.h: No such file or directory
25 | #include <AES.h>
| ^~~~~~~
compilation terminated.
Used library Version Path
ESP8266WiFi 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WiFi
ESP8266WebServer 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WebServer
ESP8266HTTPClient 1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266HTTPClient
WiFiManager 2.0.17 /home/mjhammel/Arduino/libraries/WiFiManager
DNSServer 1.1.1 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/DNSServer
Used platform Version Path
esp8266:esp8266 3.1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2
Error during build: exit status 1
Not a bad start. So I need to find out how to add libraries to the cli.
Update 1¶
- Show libraries installed: ac lib list
- Find libraries (and show extended details for them) that have this string in their name: ac lib search "string"
- Show just the library names: ac lib search "string" | grep Name
- Install library by name: ac lib install "name"
To install a library that is not known by Library Manager you need to use --git-url . However, before you can use that it must be enabled in the yaml configuration. Add the following lines to ~/.arduino15/arduino-cli.yaml.
library: enable_unsafe_install: true
And then run the following command to install a library.
ac lib install --git-url <url to git repository of library>
Doing this for the AES library worked, and I got a little further.
$ ac compile -b esp8266:esp8266:generic PiBox
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino:26:10: fatal error: Timer.h: No such file or directory
26 | #include <Timer.h>
| ^~~~~~~~~
compilation terminated.
Used library Version Path
ESP8266WiFi 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WiFi
ESP8266WebServer 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WebServer
ESP8266HTTPClient 1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266HTTPClient
WiFiManager 2.0.17 /home/mjhammel/Arduino/libraries/WiFiManager
DNSServer 1.1.1 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/DNSServer
AES /home/mjhammel/Arduino/libraries/AES
Used platform Version Path
esp8266:esp8266 3.1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2
Error during build: exit status 1
So now I can install all the libraries I'm using this way.
Updated by Hammel 8 days ago
- % Done changed from 10 to 20
I fixed most of the build errors. There were all pretty easy - end of non-void function, const char vs char, etc. One caveat: I can't find a way to pass a compiler -D flag that sets a string with spaces in it. So the IMDESC has spaces set to underscores. I can deal with that later, even stripping them out when Ironman uses them.
Here is where it stands now.
$ ac compile -b esp8266:esp8266:generic --build-property compiler.cpp.extra_flags="-DIMTYPE=\"light_switch\" -DIMDESC=\"Toggle_light_switch\"" PiBox
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino: In function 'int pairPing()':
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino:647:15: error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
647 | http.begin(url);
| ~~~~~~~~~~^~~~~
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino: In function 'int handleRegistration()':
/home/mjhammel/src/ximba/xarduino/lightsw/src/PiBox/PiBox.ino:569:15: error: call to 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url)
569 | http.begin(url);
| ~~~~~~~~~~^~~~~
Used library Version Path
ESP8266WiFi 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WiFi
ESP8266WebServer 1.0 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266WebServer
ESP8266HTTPClient 1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/ESP8266HTTPClient
WiFiManager 2.0.17 /home/mjhammel/Arduino/libraries/WiFiManager
DNSServer 1.1.1 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/libraries/DNSServer
AES /home/mjhammel/Arduino/libraries/AES
Timer /home/mjhammel/Arduino/libraries/Timer
aJson /home/mjhammel/Arduino/libraries/aJson
base64 1.0.0 /home/mjhammel/Arduino/libraries/base64
Used platform Version Path
esp8266:esp8266 3.1.2 /home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2
Error during build: exit status 1
I just need to fix the usage for the begin() method and that should complete the compile. Then I can try to push it to an ESP8266.
I should not use the one I have that I can see currently runs with the old code. I need to mark it and then get another ESP01 to program with the updated build.
Updated by Hammel 7 days ago
- Subject changed from Port imlightsw to use submodules to Port imlightsw to arduino-cli
- % Done changed from 20 to 30
Fixed. Just need a WiFiClient added, even if we don't use it.
WiFiClient wifiClient;
Now the compile looks like this.
$ ac compile -b esp8266:esp8266:generic --build-property compiler.cpp.extra_flags="-DIMTYPE=\"light_switch\" -DIMDESC=\"Toggle_light_switch\"" PiBox
. Variables and constants in RAM (global, static), used 32532 / 80192 bytes (40%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1516 initialized variables
╠══ RODATA 3272 constants
╚══ BSS 27744 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60015 / 65536 bytes (91%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 27247 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 375368 / 1048576 bytes (35%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 375368 code in flash
Now it's ready to try flashing the ESP01. But I need to make sure I have it hooked up correctly and the setup is in the "flash" mode correctly.
Updated by Hammel 7 days ago
One more thing: The above commands put the build someplace I don't know about. But that's easily fixed with --output-dir <build>.
$ ac compile -b esp8266:esp8266:generic --output-dir build --build-property compiler.cpp.extra_flags="-DIMTYPE=\"light_switch\" -DIMDESC=\"Toggle_light_switch\"" PiBox
...
$ ls build
PiBox.ino.bin PiBox.ino.elf PiBox.ino.map
Updated by Hammel 7 days ago
Decided to test a sample program first, so I added a "blink program": in a PBTest directory and compiled it.
Then I used this command to try to flash the board.
ac upload -b esp8266:esp8266:generic -v -p /dev/ttyUSB5 --build-path $(pwd)/build
I got this in response.
$ ac upload -b esp8266:esp8266:generic -v -p /dev/ttyUSB5 --build-path $(pwd)/build
"/home/mjhammel/.arduino15/packages/esp8266/tools/python3/3.7.2-post1/python3" -I "/home/mjhammel/.arduino15/packages/esp8266/hardware/esp8266/3.1.2/tools/upload.py" --chip esp8266 --port "/dev/ttyUSB5" --baud "115200" "" --before default_reset --after hard_reset write_flash 0x0 "/home/mjhammel/src/ximba/xarduino/lightsw/src/build/PBTest.ino.bin"
esptool.py v3.0
Serial port /dev/ttyUSB5
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header
New upload port: /dev/ttyUSB5 (serial)
This only works if the RESET switch is enabled on my programmer board. I think something isn't setup correctly. Might be that the board is in backwards, though I don't think so.
Update:
I think the problem was I had minicom on that port at the same time. I had to exit that and enable the FLASH switch on the programmer and it acted like it was programming, but failed with the same message.
Updated by Hammel 6 days ago
Discovered that I'm using 3rd party libs wrong. While I CAN add them with arduino-cli lib install --git-url <>, it's probably better to use submodules so I can patch the libraries. That's the case with the aJson library that I use with imlightsw (which is now called pwrctrl).
The structure of an Arduino "sketch" (re: directory of source compiled via arduino-cli) requires requires a src directory with a named-library directory under which a src directory contains the source for the library. That library directory may not need the src directory, which will be useful since not all 3rd party libraries will have the proper format.
I can also use tarballs and unpack them as part of the build, but I like submodules better. I can always mirror the libraries in use to make sure they don't go away.
Updated by Hammel 6 days ago
- Status changed from New to Closed
- % Done changed from 30 to 100
Switch to submodules went smoothly. I've now got clean builds of both pwrctrl (the old lightsw app) and pbtest (a new test application to make sure we can talk to the device).
I've pushed both to the ESP01 using
make PORT=<> <app>-upload
Both apps work as expected. I had to compile pwrctrl with the SERIAL=1 option but once that was done and I switched minicom to an ANSI terminal type I can see the debug output. Awesome!
The code was pushed to a branch and then merged via GitLab merge request. That went smoothly too. I've rebuilt from the master branch and it built fine. I think I can call this one good.
Code committed, pushed and merged.
Closing issue.