Here's my project. I have an electric gate I'm opening and closing by sending a GET request to WiServer. I've written a little iPhone app to send the GET request. Seems to work fine for several hours then the WiShield loses the connection to the access point and won't get it back. If I walk out to the gate, unscrew the cover, reach in and press the reset button it will reconnect and everything will work fine for a while.
I've done some scenario testing and here's what seems to be the case:
- Seems to sustain connection indefinitely with no problems when connected to USB sitting on desk
- Seems to have good WiFi signal with an SNR of around 22db
- Connected to Apple Airport Extreme (Have also tried a couple of Linksys APs with same results)
Couple of unique things that could be clues:
- No 120VAC power in this gate box, only 24VDC. So I built a little power supply and attached it to a shield I've stacked on top of the WiShield. My power supply is 100 uF capacitor -> 7805 regulator -> 10 uF capacitor -> .1 uF capacitor. No heatsink. No idea why this would be a problem, but I'm trying to point out everything non-standard.
- There are other electronics in the gate controller box. Two other RF frequencies. But, operating all the other RF I can't seem to find any combination that causes the WiShield to give up.
- My WiShield is V 1.0. Would 2.0 give me different results? Seems like maybe it's the same chipset with a little more memory than the v1.0 so probably wouldn't make a difference.
My guess is that my problem has something to do with my power supply or with my code. I probably need to isolate the power issue further by switching power supplies, but running an extension cord with 120VAC out to the gate and leaving it for while is sort of impractical. I might be able to figure something out.
So, I thought I'd post my code and see if anyone else has any ideas. Here's the code. I'd appreciate any thoughts.
#include <WiServer.h>
#define WIRELESS_MODE_INFRA 1
#define WIRELESS_MODE_ADHOC 2
#define gatePin1 6
// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,X,15}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,X,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 = {"myssid"}; // max 32 bytes
unsigned long eMillis = 0;
unsigned int pinState = 0;
unsigned char security_type = 2; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"XXXX"}; // max 64 characters
// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // 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;
// End of wireless configuration parameters ----------------------------------------
// This is our page serving function that generates web pages
boolean sendMyPage(char* URL) {
// Serial.println("Page printing begun");
if (URL[1] == '?' && URL[2] == 'G' && URL[3] == 'A' && URL[4] == 'T' && URL[5] == 'E') //url has a leading /
{
// Serial.println("Close Relay");
pinState = 1;
digitalWrite(gatePin1, pinState);
// Get the time we closed the relay. We use this in the loop to open the relay 1 sec later.
eMillis = millis();
//after having change state, return the user to the index page.
WiServer.print("<HTML><HEAD><meta http-equiv='REFRESH' content='0;url=/'></HEAD></HTML>");
return true;
}
// 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("<a href=?GATE>Actuate Gate</a>");
WiServer.print("</html>");
// URL was recognized
return true;
}
// URL not found
return false;
}
void setup() {
// Initialize WiServer and have it use the sendMyPage function to serve pages
pinMode(gatePin1, OUTPUT);
WiServer.init(sendMyPage);
// Enable Serial output and ask WiServer to generate log messages (optional)
// Serial.begin(9600);
WiServer.enableVerboseMode(true);
}
void loop(){
if ((millis() > (eMillis + 1000)) && (pinState)) {
pinState = 0;
digitalWrite(gatePin1, pinState);
}
// Run WiServer
WiServer.server_task();
delay(10);
}