Most recent activity
-
After being away for a year it's nice to see all the progress on Espruino!
I did struggle for quite some time to update my stuff and to get my code working again under V2.01, so I thought I'd write up a quick how-to so I remember the next time I try to do something :-) Maybe it also helps someone else 'cause very little of this is spelled out anywhere that I could find (the best info is at http://www.espruino.com/Saving but that page is not linked to from any other page on http://www.espruino.com!)
Requirements:
- I have a bunch of apps that are fairly large and must run from flash.
- I use local modules.
- The apps must run auto-run at boot time.
- I prefer CLI over the IDE.
I couldn't do an OTA update from pre-V2 of Espruino to V2.x due to a changed flash layout (512 vs 1024KB partitions). I have esp-12e modules with 4MB flash, so I installed the official espressif tool https://github.com/espressif/esptool/ and flashed using:
esptool -p /dev/ttyUSB0 write_flash --flash_size 4MB-c1 --flash_mode qio 0 espruino_2v01_esp8266_4mb_combined_4096.bin
In the IDE I had to set the options SAVE_TO_FLASH to 1 and MODULE_AS_FUNCTION to true. But I don't want to use the IDE...
So I installed the espruino cli:
- Install node.js version 8 (old!), I'm using Linux and untarred the binary archive from the node.js site in
/home/sw/node-v8
(non-std location, use any dir you like) - Install espruino using
/home/sw/node-v8/bin/npm install espruino
In order to ensure that I can run the cli using node-v8, I created a little shell script I call
espruino-v8
:#! /bin/bash export NODEJS_HOME=/home/sw/node-v8/bin export PATH=$NODEJS_HOME:$PATH espruino --no-ble --config SAVE_ON_SEND=1 --config MODULE_AS_FUNCTION=true "$@"
To flash an application I have the main file in a
projects
subdirectory and the modules in amodules
subdirectory. I simplyrequire(...)
the module in the main file. The flashing command is:./expruino-v8 -p tcp://esp8266.local:23 -w -m projects/foo.js
The -w option means that espruino stays connected and shows me the console output.
The application uses an
onInit()
to start and that gets invoked automatically at the end of the upload. - I have a bunch of apps that are fairly large and must run from flash.
-
You can use the main UART to attach a peripheral, but it's somewhat tricky. You will get stuff printed on it at boot, so your periph better be able to ignore that. My onInit() function when using a nextion display attached to uart0 contains:
// change logging so we don't clobber the nextion display on uart0 esp8266.setLog(3); // log to memory and 2:uart0 3:uart1 console.log("Bye bye..."); Serial2.setConsole(false)
The way I use it is to upload the code using telnet, so I see the "Bye bye..." printed via telnet when I run onInit() manually. By setting Serial2 as console the characters get dropped. By not forcing the console to stick to Serial2 I can telnet into the espruino at any time and have the console back. This has worked quite well for me.
-
-
-
Mhh, I think some guy on the internet wrote a free book on the esp8266, I think he goes by 'nkolban', you should take a look at his book ;-)
The esp-01 modules have 512KB flash. The flash layout is described in https://github.com/espruino/EspruinoDocs/blob/master/boards/EspruinoESP8266.md#flash-map-and-access as far as I can tell, people, especially beginners are still using these routinely.
On larger modules we could use 1MB. On modules 2MB and up there's a layout that supports OTA with 1MB partitions. This is all described in Espressif's "user guide" or "OTA guide". But it's not just a matter of flipping a switch, there are a whole bunch of places that need changes, so to use that someone would really have to roll up their sleeves and make all the changes and get them reviewed. -
@MaBe, can you explain the advantages of your scheme over what I'm using? It's quite a bit of additional work.
Hmmm, my bad. I could swear that typing 'saving' into the search box brought up nothing, but now it does, so I must have been too tired to see it or something... I mainly looked around in the tips&tricks, tutorials, modules, and esp8266 pages.