WebREPL mode
As you may know, DAVEGA firmware is written in micropython. Micropython is very cool and the WebREPL is one of the builtin features that allows you to connect to the device and get an interactive prompt.
With v5.03, DAVEGA will boot into the WebREPL mode if you hold the up and down buttons simultaneously at start up (using the grip).
Here’s how it looks:
DAVEGA will tell you the name of the WiFi access point it has created. Note that once you connect you’ll no longer have Internet so before you do that, you’ll want to open the WebREPL client in your browser, which is available at http://micropython.org/webrepl/.
You’ll want to make sure you have http:// and NOT https:// since the connection won’t work over SSL (we won’t be transferring credit card numbers or bitcoin wallet private keys so don’t worry). Though this may be counter-intuitive, the “Not Secure” warning is actually what you want here.
Now you’re ready to connect to the DAVEGA WiFi:
Then you can hit the “Connect” button in the WebREPL client and it should connect to the DAVEGA. You’ll be asked for a password, which is agevad (I had to put something; it doesn’t work without a password).
Then you should get the Python command prompt and you’re ready to run Python on your DAVEGA. How cool is that?!
For example, here’s one toy thing you can try. Type:
from frozen.display import DISPLAY
DISPLAY.print("hi mum!")
And it will get printed on the DAVEGA display:
There’s also stuff you can do that’s actually useful. In particular the frozen.commands
module contains functions for archiving/restoring the DAVEGA data. On the right hand side of the WebREPL client there are widgets for transferring files to/from the DAVEGA.
If you combine this, here’s how you can get a data backup. Type:
from frozen.commands import backup
backup()
This will archive all the DAVEGA data into a single filed called /backup.dfs
. If you then type /backup.dfs
into the “Get a file” text field and click on “Get from device”, the file gets transferred to your computer.
The other direction is also possible. Say that you have a backup file called backup_from_another_davega.dfs
that you either downloaded from https://davega.eu/backups or created using WebREPL the way I just showed.
In the “Send a file” widget, look up the file on your disk and click “Send to device”. The file name will be retained and it will be put in the root directory, so in this particular case the file path will be:
/backup_from_another_davega.dfs
Now we can go ahead and restore that backup as follows:
from frozen.commands import restore
restore('/backup_from_another_davega.dfs')
Last, the .dfs
files are now stored in the DAVEGA flash memory. We may want to clean it up. Here’s one way of listing the files in the root directory:
import os
os.listdir('/')
Here’s how to remove the files:
os.remove('/backup.dfs')
os.remove('/backup_from_another_davega.dfs')
(The leading slash is not strictly necessary since we’re working from the root directory.)
Being able to run custom code on DAVEGA opens the door for tinkering if you know what you’re doing. Some other things one could potentially do include:
- accessing VESC data programmatically
- changing VESC settings
- accessing smart BMS data programmatically
- changing smart BMS settings
- changing DAVEGA settings (including hidden settings)
- adjusting DAVEGA odometers
- writing DAVEGA plug-ins
Obviously none of this is straightforward and it’s not for everyone. It’s also riding completely without seatbelts and you can easily mess things up if you’re not careful. (Still if you backup everything first, there’s not a lot to worry about.)
Currently there’s no documentation for the DAVEGA APIs and I don’t intend to write and maintain complete documentation. However, if people come up with interesting use cases I’m happy to document relevant parts of the APIs and/or write up guidelines/tutorials.