HASwitchPlate/openHASP

Uploading config.json via HTTP

markusressel opened this issue · 1 comments

Hey there, this is a really awesome project, thx!

To make it a bit easier for myself to manage the configuration of the plates in my home, I wrote a small helper to apply some preprocessing to the *.jsonl files and upload them to a plate in one single command.

To upload files I took a look at how the webserver saves changes made in the browser and replicated that HTTP request. This works pretty well so far, except for the config.json.

Uploading a file to the /config.json path succeeds, but the resulting file on the device was completely empty, resulting in what is essentially a factory reset after rebooting the plate.

So the Question is:

Is there a way to upload a modified config.json?
Or is it not possible on purpose?
If so it should probably return an error instead of writing an empty file 😅

I saw that there is ongoing progress on the HTTP website itself ( #246 ) and also for implementing an FTP server ( #427 ), I guess both of these should be linked to this question.

Links

You can find the source to my tool here: openhasp-config-manager

The config.json is read into memory at boot and overwritten from the running configuration at reboot.
There is no code to handle uploads of config.json like that. It is only used to temporarily store the settings between reboots. It wasn't intended to be changed on-the-fly. Use the api calls in the web server to emulate the Configuration forms.

In the future this file will likely disappear from the filesystem. The settings should be moved to the NVS partition to prevent reading/writing it like that. The FTP server could now read sensitive contents of config.json, which shouldn't be possible...