Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By shoelessone
#36478 Hello all!

I'm creating (nearly complete with the hardware/circuit actually) a project that connects to the internet via mqtt and also allows for configuration of the "device" via a wifi network configuration menu (similar to many projects it seems these days). In other words, when the device starts up it creates a wireless network that allows you to connect and configure the device.

But, I've had VERY unreliable and mostly unusable connection with my setup. You can see my code here: https://github.com/develpr/mitchine

Basically what seems to happen is I connect to the wireless network (which sometimes works, sometimes doesn't and I have to reconnect a few times before it "sticks"), and then generally when I try to get to the appropriate page (say 192.168.4.1/config.html) the ESP will seem to reset or just not respond. I say "reset" but I'm not sure that's what's really happening. I get kicked off the wireless network and have to reconnect, generally, and perhaps it is resetting, but theother code running seems to start back up quickly and I'm generally able to reconnect to the network almost immediately).

EVENTUALLY, with luck, I can connect to the thing and actually configure things. But by "eventually" I sometimes mean after trying 15 times (literally). And sometimes I can't connect at all.

I'm wondering if there is an issue with my code perhaps?

I want to point out that if I manually (via code) configure my wireless network then the board runs super reliably, connecting to an MQTT server every 5 seconds and sending a "heartbeat" - so wifi on the board seems to work, and the connection seems semi-reliable.

Also, I made a custom PCB and here is the schematic: http://i.imgur.com/BXTPrhe.png

At this point I'm guessing/wondering if it's a problem with my code. Possibly because I keep the wifi network going at the same time I'm trying to connect to mqtt and do a bunch of other things? Would I have less issues if I, say, for the first 5 minutes ran the web server, then shut it off after 5 minutes and went about doing the "normal" activities?

Any advice on making things with the web server/wifi network more reliable?

Another option is to very much simplify the wifi configuration part so that that it's a single step process where I just configure everything via a single GET request/query string parameters (i.e. http://192.168.4.1?ssid=my_ssid&pass=password or whatever)

Thank you!
User avatar
By martinayotte
#36483 At first quick look, I see that you are using PROGMEM for HTML pages, but you are sending them with server.send() instead of server.send_P(), which can lead to several crashes.
Secondo, looking at your Network server page, I see that the field table doesn't handle any POST, but using a GET instead without any "action" URL to be called when submit button is pressed.
So, I'm not sure how you can get the sketch working.
User avatar
By shoelessone
#36485 I was not aware of send() vs send_P() - I'll give that a shot! This was (not surprisingly) a lot of copy/paste and dissection of other "sketches".

As for the second part (method="get" without an action="" value), I believe most browsers will use the current URL to submit the form. And GET will (as you probably know) append the parameters to the query string. This part isn't super "great" by modern web standards, but it does work!

I'll give this a shot now and report back! Thanks as always Martin!

edit: apparently the compiler doens't like send_P :(

Image
User avatar
By martinayotte
#36487 If you look in ESP8266WebServer.h, you will find those :
Code: Select all  void send_P(int code, PGM_P content_type, PGM_P content);
  void send_P(int code, PGM_P content_type, PGM_P content, size_t contentLength);

If they are not there, it is because you are using old version, "stable" is pretty old, back in July, "staging" is currently pointer to version 2.0.0-rc2.
Also, send_P() is for sending PROGMEM, but if you are concatenate them into a String, they are not PROGMEM any more and use a lot of RAM. send_P() is for transmit PROGMEM directly from Flash to Network, and both arguments need to be PROGMEM, even the "text/plain" string.