setup() {
Wiserver.init(myPage); // normal init, don't care if this blocks.
}
unsigned long connectonCheckTime = 120000;
loop() {
if (millis()>=connectionCheckTime) {
connectionCheckTime+=120000; // check the connection every 2 minutes
if (!WiServer.connection_up()) { // if it's down, restart it
serverUp = WiServer.async_init(wvHome,1);
Serial.println("fixing");
Serial.println((int)serverUp);
}
else {
Serial.println("good");
}
}
doStuff(); // make some HTTP requests
if (serverUp) {
WiServer.server_task(); // Run WiServer
}
else {
serverUp = WiServer.async_init(wvHome,0); // continue to restart server
}
}
then at worst we could do a hardware reset of the arduino triggered by software. That's definitely a brute force solution
aerodyno wrote:Hruska, can you post a complete code sample of what you have working? (sorry to bug you).
Thought: if we can determine, through code, whether the connection has gone down, then at worst we could do a hardware reset of the arduino triggered by software. That's definitely a brute force solution, but something I'm thinking about. Or perhaps I should dig in to g2100.c.
-s
#include "WiServer.h"
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
//Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = { 10, 1, 1, 125 }; // IP address of WiShield
unsigned char gateway_ip[] = { 10, 1, 1, 1 }; // router or gateway IP address
unsigned char subnet_mask[] = { 255, 255, 255, 0 }; // subnet mask for the local network
const prog_char ssid[] PROGMEM = { "RCH" }; // max 32 bytes
unsigned char security_type = 1; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = { "12345678" }; // max 64 characters
// WEP 128-bit keys (modified to be 64 bit in library g2100.c func zg_write_wep_key()
prog_uchar wep_keys[] PROGMEM = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00,
0x00,
0x00,
0x00, // Key 0
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0x00,
0x00, // Key 1
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
0x00, // Key 2
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00 }; // Key 3
// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------
unsigned int current_millis_value = 0;
unsigned int previous_millis_value = 0;
unsigned int m = 0;
unsigned int minutes = 0;
unsigned int seconds = 0;
unsigned int hours = 0;
char wireless_stat = 'N';
int server_up = 0;
int retry_seconds = 0;
#define WIFI_RETRY_KICK_TIME 45
void setup() {
Serial.begin(57600);
Serial.println("Setup");
server_up = WiServer.async_init(sendMyPage, 1);
}
void loop() {
// Run any code you need to run that is not WiServer related
update_time();
// This is the logic to establish / re-establish the wireless connection.
// setup() begins the process by calling async_init with the reset flag set.
//
// During loop() the reset flag is not set and the reset will not
// be done.
//
// Once connection is established, connection_up is checked continuously. If the
// connection goes down, the async_init is called again with the reset flag set
// and the process starts over.
if (!server_up) {
server_up = WiServer.async_init(sendMyPage, 0);
} else {
if (!WiServer.connection_up()) {
server_up = WiServer.async_init(sendMyPage, 1);
} else {
retry_seconds = 0;
WiServer.server_task();
}
}
}
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
// Check if the requested URL matches "/" and if so give generic info page
if (strcmp(URL, "/") == 0) {
WiServer.print("<html>");
WiServer.print("You are connected to the WiServer ");
WiServer.println(seconds);
WiServer.print("</html>");
return true;
}
}
void hours_tick() {
}
void minutes_tick() {
Serial.println("Minutes tick");
}
// Run this every second. Inside it could also have static counters to run things on
// other multiples of seconds.
void seconds_tick() {
char line[60];
if (WiServer.connection_up()) {
wireless_stat = 'Y';
} else {
wireless_stat = 'N';
if (retry_seconds++ > WIFI_RETRY_KICK_TIME) {
// For some reason if the wifi init runs for too long without getting a connection
// it will not work when a connection becomes available. This allows the process
// to start over from scratch after a long timeout intercal.
Serial.println("Kicking wifi init");
server_up = WiServer.async_init(sendMyPage, 1);
retry_seconds = 0;
}
}
sprintf(line, "Secs=%d Wireless=%c\n", seconds, wireless_stat);
Serial.print(line);
}
void update_time() {
static unsigned char last_seconds = 0;
static unsigned char last_minutes = 0;
static unsigned char last_hours = 0;
current_millis_value = millis();
m += current_millis_value - previous_millis_value;
seconds += m / 1000;
minutes += seconds / 60;
hours += minutes / 60;
if (seconds > last_seconds) {
last_seconds = seconds % 60;
seconds_tick();
}
if (minutes > last_minutes) {
last_minutes = minutes % 60;
minutes_tick();
}
if (hours > last_hours) {
last_hours = hours % 24;
hours_tick();
}
m = m % 1000;
seconds = seconds % 60;
minutes = minutes % 60;
hours = hours % 24;
previous_millis_value = current_millis_value;
}
Users browsing this forum: No registered users and 1 guest