- Thu Nov 13, 2014 11:55 am
#176836
I am designing a car counter. I am using an Arduino Uno and a Wifly shield that I purchased about 4 years ago. A set of long distance photoeyes is wired to the Arduino to detect when a car passes then sends the speed and direction to my webserver (WCF Service running on IIS). It's a simple project but I cannot get the Wifly to maintain a connection with the webserver for more than a couple of hours. It works perfect during those few hours where as soon as a car passes, it sends the URI to the webserver and the webserver stores that information in a sql database. When it's working fine, the status light on the Wifly is solid green but starts to slowly blink (like it's connected to an AP) when it stops working. I don't really care if the server responds so I didn't clutter my code with response retrieval. I just want to send the /GET.
1. Does anybody have any ideas why it's disconnecting?
2. How long can I, under normal conditions, keep an active connection alive (i.e. is my approach even doable)?
Below is the Arduino Code (like I said, very simple). Any ideas would be much appreciated.
BTW...the IIS log file indicates that the GET requests stop arriving at the same time the solid green light switches to a slow blink.
1. Does anybody have any ideas why it's disconnecting?
2. How long can I, under normal conditions, keep an active connection alive (i.e. is my approach even doable)?
Below is the Arduino Code (like I said, very simple). Any ideas would be much appreciated.
BTW...the IIS log file indicates that the GET requests stop arriving at the same time the solid green light switches to a slow blink.
Code: Select all
// (Based on Ethernet's WebClient Example)
#include "SPI.h"
#include "WiFly.h"
#include "Credentials.h"
byte server[] = { 192, 168, 1, 100 };
// this constant won't change:
const int buttonPin = 2; // the pin that the pushbutton is attached to
// Variables will change:
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
//WiFlyClient client("google.com", 80);
WiFlyClient client(server, 8083);
void setup() {
Serial.begin(115200);
Serial.println("In Setup Mode");
//WiFly.configure(WIFLY_BAUD, 9600);
WiFly.begin();
Serial.println("Wifly begin");
//WiFly.configure(WIFLY_BAUD, 38400);
pinMode(13, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.println("connecting...");
if (client.connect())
{
Serial.println("connected");
client.println("GET /Arduino/CarCount.svc/RoadInfo?dir=start&spd=0 HTTP/1.1");
client.println("Host: 192.168.1.100:8083");
client.println("Connection: keep-alive");
client.println("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8");
client.println("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36");
client.println("Accept-Encoding: gzip,deflate,sdch");
client.println("Accept-Language: en-US,en;q=0.8");
client.println();
//client.stop();
} else {
Serial.println("connection failed");
Serial.println(client.connect());
client.connect();
}
}
void loop() {
// read the pushbutton input pin:
buttonState = digitalRead(buttonPin);
while (client.connected())
{
htmlReq();
Serial.println("connected");
delay(10000);
}
client.stop();
delay(10000);
client.connect();
}
void htmlReq()
{
client.println("GET /Arduino/CarCount.svc/RoadInfo?dir=ard1&spd=0 HTTP/1.1");
client.println("Host: 192.168.1.100:8083");
client.println("Connection: keep-alive");
client.println("Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8");
client.println("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36");
client.println("Accept-Encoding: gzip,deflate,sdch");
client.println("Accept-Language: en-US,en;q=0.8");
client.println();
}