drehschaltermodul merge requestshttps://es.technikum-wien.at/aignerb/drehschaltermodul/-/merge_requests2023-05-30T10:13:25Zhttps://es.technikum-wien.at/aignerb/drehschaltermodul/-/merge_requests/6Added webGUI, implemented communication API, save wifi credentials and genera...2023-05-30T10:13:25ZBenjamin KlausAdded webGUI, implemented communication API, save wifi credentials and general config to file# General info
* Added web GUI to folder: [SW/Web-Configurator](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/tree/adrian-wagner/SW/Web-Configurator)
* Added [WifiManager](https://es.technikum-wien.at/aignerb/drehschaltermodul...# General info
* Added web GUI to folder: [SW/Web-Configurator](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/tree/adrian-wagner/SW/Web-Configurator)
* Added [WifiManager](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/blob/adrian-wagner/SW/ESP32/Bedienpanel_demo/WifiManager.h) for managing configuration of wifi state
* Added Base64 library by `Arturo Guadalupi` directly to the project, because importing library with library manager didn't work, see [Base64Class.h ](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/blob/adrian-wagner/SW/ESP32/Bedienpanel_demo/Base64Class.h)
* changed [ConfigManager.cpp](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/blob/adrian-wagner/SW/ESP32/Bedienpanel_demo/ConfigManager.cpp) in order to be able to load config from file - WIP
# API
These are the implemented API commands:
* `setWifi <SSID> <password>`: sets the credentials to be used to connect with wifi
* `tts <text>`: plays the given text using text-to-speech
* `toggleWiFi <on | any>`: turn on wifi if agrument is `on`, otherwise turn off wifi
* `rm <filename>`: removes `<filename>.mp3` from SD card (in order to remove cached version of TTS)
* `wav <filename>`: plays `<filename>.wav` from SD card
* `mp3 <filename>`: plays `<filename>.mp3` from SD card
* `vol <0..100)>` sets sound volumne to given value
* `restart` or `reboot`: restarts the system
* `refreshtokens`: refreshes HomeConnect access tokens
* `checktokens`: check HomeConnect access tokens if they are valid
* `time`: prints current system time as timestamp
* `logheap` toggles printing current heap memory usage
* `wifiinfo`: returns currently used SSID
* `setConfiguration <configJSON>`: takes a JSON string representing the system configuration, saves it and reboots for using this configuration
* `callAPIEncoded <cmdName> <arg1> <arg2>`: possibility to call all other API commands with base64 encoded arguments. For instance `callAPIEncoded setWifi bXlXaWZp bXlQYXNzd29yZA==` will call `setWifi myWifi myPassword` internally.
Calling the API via `callAPIEncoded` is used for communication with the WebGUI in order to make it possible to send values including spaces, e.g. a wifi password.
# WifiManager
Some information about the new behaviour of WifiManager:
* credentials are read from file `WifiData.txt` from SD card
* connecting to Wifi is tried 3 times or at maximum 60 seconds, afterwards device is used without Wifi (new credentials could be set via API)
# Start WebGUI
Go to folder [SW/Web-Configurator](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/tree/adrian-wagner/SW/Web-Configurator) and run `npm install` and `npm run serve`, also see [Readme.md](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/blob/adrian-wagner/SW/Web-Configurator/README.md)
# Important notes for further development
* the API call `setConfiguration <configJSON>` currently isn't working, because we ran into memory issues. Config files currently are about 15000 characters long and raising the limits for API arguments and adding big arrays to `ConfigManager.cpp` for holding such big arrays led to boot loops of the M5Stack. See [this commit for fixing the reboot loop](https://es.technikum-wien.at/aignerb/drehschaltermodul/-/commit/43b07c838bfafab8698a28ab4b767846c9cb8f72).
* communication from `M5Stack -> WebGUI` is not finished. The WebGUI receives everything sent from M5Stack over Serial, but there is no mechanism to detect what is a result to a prior API call.