octopusengine / octopuslab

octopusLAB - for devBoard ESP8266/32 - NodeMcu (LoLin) and octopus ESP-interface-board
29 stars 16 forks source link

Enhancement: wifi.json config structure #25

Open vasekch opened 5 years ago

vasekch commented 5 years ago

Currently we have two version of wifi.json

original - single network

{
  "wifi_enabled": true,
  "wifi_ssid": "mynet",
  "wifi_pass": "mypass"
}

latest version 2 - multiple networks

{
  "networks": {
    "mynet": "mypass", 
    "mynet2": "mypass2"
  },
 "version": 2
}

Version 2 is great, but there may be more predictable structure of the json file (and parsed Python object), it's common to have list of dictionaries in such cases and have stable keys across different network settings. using dict ket to store value is a bad practice.

here is proposed version 3

{
  "networks": [
    {
      "ssid": "mynet",
      "psk": "mypass"
    },
    {
      "ssid": "mynet2",
      "psk": "mypass2"
    }
  ],
  "version": 3
}

I understand that version 2 is actually more size efficient and is working well, so there is just little benefit of redoing it, but it would be more Pythonic :).

TomasRoj commented 5 years ago

From python side I totally agree and I would implement this feature.

petrkr commented 5 years ago

Yes you are right, @vasekch , but in version 3 you will miss function "in".

Like when I looking for available networks, I asking if I have it in my config by using "ssid in config.networks" that would not work if that will be list and I will need do for in for satement where I have to do much more iterations than now.

check https://github.com/octopusengine/octopuslab/blob/68bbabe1b4913dfb818cb5b50da0c2179ebbcbf7/esp32-micropython/util/wifi_connect.py#L139

or redone this to be effective in embedded too. Maybe you have some fast trick how to achieve this in list of dicts too.