chmorgan / libesphttpd

Libesphttpd - web server for ESP8266 / ESP32
Mozilla Public License 2.0
128 stars 45 forks source link

add cgi functions for WiFi to set AP ssid and password. #72

Closed phatpaul closed 5 years ago

phatpaul commented 5 years ago

I added cgi functions for WiFi to set AP ssid and password.
Also improved error handling for WiFi mode changes.

See example usage in example repo.

chmorgan commented 5 years ago

Hi @phatpaul. Just a few minor things and I saw the dashboard and it looked good.

I have some proprietary code for managing network, wifi settings, and retrieving the system partitions I could share with you if you were interested. This code is using cJSON and may be slightly cleaner than the functions in the system today. I haven't worked in the esp32 codebase for a while so I'm not sure I'll ever get around to open sourcing the parts that could be. I would say that it won't be a drop in though.

phatpaul commented 5 years ago

Thanks @chmorgan I still have to add IP network and BLE settings GUI for my application. I would would be interested in seeing your solution for ideas.
I feel like IP settings could be useful to add to the example project, but BLE settings are probably outside the scope. (There are several BLE stacks available for ESP32 anyway)

tidklaas commented 5 years ago

As everybody seems to have their own solutions for the shortcomings of the WiFi config interface, I might well throw mine into the ring, too ;).

I moved the whole network configuration management into a separate component that allows querying and setting the config in a stateless manner. The repo is here. I have also made some necessary changes to libesphttpd and esphttpd-freertos.

The whole thing is still work in progress and not very well tested, but I think it simplifies the network configuration handling immensely.

chmorgan commented 5 years ago

@tidklaas that does look like a reasonable move. For my commercial product code I ended up doing something similar to manage wifi state.

@phatpaul thoughts on combining efforts here with @tidklaas?

phatpaul commented 5 years ago

Yeah it makes sense to separate the WiFi code from this repo as it is getting rather complicated. But I think it is essential to offer a working out-of-the-box example for new users.

It doesn't look like you included any GUI controls for it (in esphttpd-freertos example), or did I miss that? I'd be happy to adjust my gui additions to make use of your new component.

BTW, have you seen the new wifi-provisioning component included in the ESP-IDF v3.3? Does that functionality overlap with your component?

tidklaas commented 5 years ago

Hi Paul, you are right in that the project is still lacking documentation and examples. It is still very much work in progress. My goal so far has mainly been to remove the complexity from the esp32_wifi CGI, as you can see here tidklaas/libesphttpd@50e6aaa411e453a4052af8f65a62fe1d175c6116.

I looked at the provisioning component some time ago and, if I remember correctly, configuration is done via its own protocol. The user has to install a special tool to configure the device instead of simply using a web browser. It also seems to only cover retrieving WiFi credentials and can not handle non-DHCP based configurations.

chmorgan commented 5 years ago

@tidklaas @phatpaul should we merge @phatpaul's pull request now or hold off for other integration? I'd hate for improvements to be stuck behind what may never be future improvements but I'd like to get both of your opinions about it.

tidklaas commented 5 years ago

As far as I am concerned, you can go ahead and merge @phatpaul's changes. It should be easy enough for me to rebase and adapt my code.

chmorgan commented 5 years ago

@phatpaul, @tidklaas I'd also mention that imo code has been mixing together frontend and backend implementations. A better approach, again imo, would be to present a restful interface to the wifi settings and then a separate .html file with javascript to interact with it. That would let us avoid reloading the page. @tidklaas I haven't taken a look at your code so maybe this is the approach but if we moved that direction I think things would be a bit simpler.

phatpaul commented 5 years ago

@chmorgan I agree that the Wifi implementation is messy and I thought about changing parts of it to more conventional REST + AJAX approach. But I also see that it is showcasing the templating capabilities of libesphttpd, so I just extended the current implementation.

But we should design the APIs so they can also be used with a conventional AJAX GUI. I considered adding an additional example GUI page which does not use templating, just AJAX. But I don't have the bandwidth to do it now.

I see it's already merged, thanks.