Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By GregryCM
#29209 Hello,

I have attached a simple Access Point sketch that is giving me issues.
I am using version 1.6.5-947-g39819f0.

Each time that the simple web page is served, a message is sent giving the heap size and the uptime, in milliseconds:

Configuring Access Point...
AP IP address: 192.168.4.1
HTTP server started
Page: Root, Heap: 25608, UpTime: 56773
Page: Root, Heap: 25456, UpTime: 63588
Page: Root, Heap: 25608, UpTime: 65598
Page: Root, Heap: 25456, UpTime: 68781
Page: Root, Heap: 25304, UpTime: 71612
Page: Root, Heap: 25144, UpTime: 72212
Page: Root, Heap: 25608, UpTime: 76228
Page: Root, Heap: 25456, UpTime: 76995
Page: Root, Heap: 25608, UpTime: 134406
Page: Root, Heap: 25456, UpTime: 139721
Page: Root, Heap: 25608, UpTime: 141777
Page: Root, Heap: 25456, UpTime: 142364
Page: Root, Heap: 25304, UpTime: 142897
Page: Root, Heap: 25144, UpTime: 145445
Page: Root, Heap: 25136, UpTime: 146002
Page: Root, Heap: 25136, UpTime: 146539
Page: Root, Heap: 25136, UpTime: 148748

I have added serial commands so that system information and uptime(mS) from the ESP8266 is available.
sys and uptime commands give:

Free Heap: 25912
Boot Version: 31
CPU (MHz): 80
SDK Version: 1.2.0
Chip ID: 16047500
Flash Size(chip): 1048576
Flash Size(IDE): 524288
Flash Speed: 40000000

UpTime: 221394

I can start the AP, and connect two devices (Nexus 7, iTouch) to the access point without issue.
I can go to the address of 192.168.4.1 and load the webpage on each device, see the heap size decrease on each refresh.
If I continue to refresh about every second, the heap size will decrease to about 22k, then crash.

Once I reset the ESP, I can again connect the devices to the SimpleAP Wifi access point, and serve the static webpage without issue. If I let the devices go to sleep for several minutes, they usually stay connected to the AP. However, it seems that the longer that devices are asleep, the higher the chance that I'll have to select the SimpleAP WiFi again, before reloading the page in the browser.

After about 60 to 90 minutes, things deteriorate to the point that the SimpleAP access point no longer shows up in the list of available networks on either device.

According to the serial information, the ESP8266 has not crashed or reset. The ESP8266 still responds to serial commands, shows stack >24k, and has an uptime that is accurate.

Tonight, I reset the board, and it crashed on the 4th reload request with the following information:

Configuring Access Point...
AP IP address: 192.168.4.1
HTTP server started
Page: Root, Heap: 25368, UpTime: 30174
Page: Not Found
Page: Root, Heap: 24664, UpTime: 33548
Page: Root, Heap: 24752, UpTime: 34897

Exception (9):
epc1=0x40101802 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0c57a293 depc=0x00000000

ctx: sys
sp: 3ffffd50 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffef0: 00000046 3fff1f10 40210d60 3fff5ab8
3fffff00: 3fff5ab8 3fff4d70 3fff5f68 00000000
3fffff10: 3fff0001 4020ad04 00000003 00000003
3fffff20: 3fff5ab8 00000000 40210d3d 00000000
3fffff30: 4020e125 3ffebb80 00000011 0000002d
3fffff40: 00000000 000000c0 0204a8c0 3ffedd3c
3fffff50: 4020a7d9 3fff5ab8 3fff4d70 3ffedd3c
3fffff60: 3ffebb80 3ffedd50 3ffedd34 402105d3
3fffff70: 3fff4d70 00000014 40210b72 3fff5ab8
3fffff80: 3fff4d70 3fffdc90 3fff4e00 00000001
3fffff90: 402114d7 3fff5ab8 00000000 3fffdcc0
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49

Configuring Access Point...
AP IP address: 192.168.4.1
HTTP server started
Page: Root, Heap: 25608, UpTime: 56773
Page: Root, Heap: 25456, UpTime: 63588
Page: Root, Heap: 25608, UpTime: 65598
Page: Root, Heap: 25456, UpTime: 68781
Page: Root, Heap: 25304, UpTime: 71612
Page: Root, Heap: 25144, UpTime: 72212
Page: Root, Heap: 25608, UpTime: 76228
Page: Root, Heap: 25456, UpTime: 76995

I have a project configured as a station that has been running for over 300 hours, but my experience with an AP is not so good.

If the AP does not have any clients, does it go to sleep? Can it be kept from doing this?
What can I do to have a more stable and robust access point?

Thanks in advance for your help.
Greg
You do not have the required permissions to view the files attached to this post.
User avatar
By igrr
#29213 Hi Greg,
you seem to be hitting two issues here. One is related to the crash (https://github.com/esp8266/Arduino/issues/428), another one is related to the access point. The first one is not yet resolved. Regarding the second one, could you please try disabling sleep mode as follows:

add function declaration near the top of the sketch:
Code: Select allextern "C" bool wifi_set_sleep_type(int);


then call it from your setup() function:
Code: Select allwifi_set_sleep_type(0);


Let's see if this changes anything.
User avatar
By GregryCM
#29339 iggr, Thank your for your response.

I included the header for user_interface.h
Code: Select allextern "C" {
#include "user_interface.h"
}

I call wifi_get_sleep_type() in Setup(). It gave a value of 2, which is MODEM_SLEEP_T.
In Loop(), I set it to NONE_SLEEP_T if it does not equal NONE_SLEEP_T.

Code: Select allvoid loop( void )
{
  server.handleClient();
  yield();

  CommProcess();
  yield();

  if(  wifi_get_sleep_type() != NONE_SLEEP_T )
  {
    wifi_set_sleep_type( NONE_SLEEP_T );
    Serial.print( "Sleep Type set to NONE_SLEEP_T at " ); Serial.println(millis());
  }
}

So on start up, the serial output looks like this:
Configuring Access Point...
AP IP address: 192.168.4.1
HTTP server started
Sleep Type 2
Sleep Type set to NONE_SLEEP_T at 1207
Page: Root, Heap: 25544, UpTime: 17564
Page: Root, Heap: 25360, UpTime: 23773
Page: Root, Heap: 25512, UpTime: 26027
Page: Root, Heap: 25512, UpTime: 354808
Page: Root, Heap: 25360, UpTime: 356988

These changes have helped. The radio is still broadcasting its ssid, but the iTouch lost connection over night, and reconnected with default home wifi network. SimpleAP shows that it is available, but the iTouch is "Unable to Join". The same is true with the Nexus7.

Through the night, wifi_get_sleep_type() always equaled NONE_SLEEP_T.
The ESP still responds to serial commands for Uptime and system information.

Next steps?

Thank You,
Greg
User avatar
By igrr
#29409 I don't know for iPod, but my Android phone will not automatically reconnect to a network if it has detected that it provides no Internet connectivity. Not sure if it may be the case here.

It would make sense to check if the same behavior is observed with AT firmware. If this is the case, it may indicate an issue with the underlying SDK.