Honestly I didn't have a clear view at the beginning of the coding work, but I believe a friendly UI is always needed. As I go deeper, I found some suitable tools to achieve this goal.
The diagram below shows the architecture behind this.
There are several ways to interact with PiSugar 2:
- shell script: if you are familiar with linux, or you want write some program that needs information from the battery, you can access it with shell scripts. It's based on UDS and you know have to go across the network layer.
- web UI : you can manage PiSugar2 through a web page. Although pi zero is able to run a desktop but I use it without screens in most of time. Web UI is accessble for other machines in the same local network.
- electron UI: electron is one of my favourites. It can build a really nice desktop app written in html5, also I can use the same code to generate the web UI. Double kill! The problem is that electron does not support armv6l (pi zero). Never mind, I can still use the web UI on pi zero.
- system tray: if you have a desktop raspbian, I do think a battery tray icon indicating power level is necessary. For compatibility with armv6l, I use pyQt5 to build the icon. ( I had tried Qt to build the main window, although it can run on pi zero, it's cumbersome. )
The http sever is just for hosting html and js files, most of the UI communication is based on websocket, which mean we can get realtime data such as button events, whether the RTC alarm is triggered, etc.
To be continue...