Though I feel a little alone here… I made a test using the simple server example. I just write a message every minute and try to reconnect if the connection is lost.
What I see is that either the reconnection never ends or the controller just hangs because “heartbeat” messages stop after this connection loss.
#define DEBUG
#define DEBUG_VERBOSE
#include <WiServer.h>
extern "C" {
#include <g2100.h>
}
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {
192,168,1,87}; // IP address of WiShield
unsigned char gateway_ip[] = {
192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {
255,255,255,0}; // subnet mask for the local network
char ssid[] = {
"MyNetwork"}; // max 32 bytes
unsigned char security_type = 4; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2; 4 - WPA Precalc; 5 - WPA2 Precalc
// Depending on your security_type, uncomment the appropriate type of security_data
// 0 - None (open)
//const prog_char security_data[] PROGMEM = {
//};
// 1 - WEP
// UIP_WEP_KEY_LEN. 5 bytes for 64-bit key, 13 bytes for 128-bit key
// Only supply the appropriate key, do not specify 4 keys and then try to specify which to use
//const prog_char security_data[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, };
// 2, 3 - WPA/WPA2 Passphrase
// 8 to 63 characters which will be used to generate the 32 byte calculated key
// Expect the g2100 to take 30 seconds to calculate the key from a passphrase
//const prog_char security_data[] PROGMEM = {"xxxxxxxxxx"};
// 4, 5 - WPA/WPA2 Precalc
// The 32 byte precalculate WPA/WPA2 key. This can be calculated in advance to save boot time
// http://jorisvr.nl/wpapsk.html
const prog_char security_data[] PROGMEM = {
MYPASSWD
};
// setup the wireless mode
// WIRELESS_MODE_INFRA - connect to AP
// WIRELESS_MODE_ADHOC - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
// End of wireless configuration parameters ----------------------------------------
long heartbeat = 60000;
long nextHeartbeat = 0;
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
// Check if the requested URL matches "/"
if (strcmp(URL, "/") == 0) {
// Use WiServer's print and println functions to write out the page content
WiServer.print("<html>");
WiServer.print("Hello World!");
WiServer.print("</html>");
// URL was recognized
return true;
}
// URL not found
return false;
}
void setup() {
Serial.begin(9600);
// Initialize WiServer and have it use the sendMyPage function to serve pages
Serial.println("Connecting");
WiServer.init(sendMyPage);
Serial.println("Connected");
}
void loop(){
if (nextHeartbeat < millis()){
Serial.print("Still alive after ");
Serial.print(millis()/60000);
Serial.println("mn");
nextHeartbeat = millis() + heartbeat;
}
if (zg_get_conn_state() == 0){ // disconnected
Serial.println("Disconnected...");
WiServer.init(sendMyPage);
}
// Run WiServer
WiServer.server_task();
delay(10);
}
After some time here is what I see:
Connecting
Connected
Still alive after 0mn
Still alive after 1mn
Still alive after 2mn
[...]
Still alive after 105mn
Disconnected...
I made no connection to the server, it’s just looping happily. I left it all day, and when I came back I saw no other print (meaning no print for 4h).