I'm trying to use an HTTP GET request to communicate with SQL Server Express 2014. Using the code below, which is supposed to hit my database every 4 seconds if everything works correctly, I'm only seeing a successful entry to the database every minute or so.
I've been working on this for quite a while now and have been on the spark community forums and found the SPARK_WLAN_Loop(); from this thread.
My code here:
byte server[] = {
192, 168, 1, 8 }; // Google
int location = 1;
int voltage = 1;
int ampere = 1;
unsigned long lastUpdate = millis();
void setup()
{
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
Serial.begin(9600);
SPARK_WLAN_Loop();
}
void loop()
{
digitalWrite(7, HIGH);
// while(!Serial.available()) SPARK_WLAN_Loop();
Serial.println("connecting...");
if (millis() - lastUpdate > 4000){
//SPARK_WLAN_Loop();
if (client.connect(server, 80))
{
Serial.println("connected");
client.print("GET /go/LogArduinoData.aspx?Location=");
client.print(location);
digitalWrite(7, LOW);
client.print("&Voltage=");
client.print(voltage);
client.print("&Ampere=");
client.println(ampere);
client.println("Host: 192.168.1.8");
client.println("Content-Length: 0");
// client.println();
Serial.println("Sent");
}
else
{
Serial.println("connection failed");
}
}
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// client.flush();
delay(4000);
}
}
My database shows
ID TimeStamp LocationVoltage Ampere
90917 2014-12-14 20:33:39.127 1 1 1
90916 2014-12-14 20:32:30.470 1 1 1
90915 2014-12-14 20:31:52.787 1 1 1
90914 2014-12-14 20:30:44.130 1 1 1
90913 2014-12-14 20:28:36.007 1 1 1
90912 2014-12-14 20:27:27.390 1 1 1
90911 2014-12-14 20:26:38.230 1 1 1
90910 2014-12-14 20:25:51.153 1 1 1
90909 2014-12-14 20:24:42.520 1 1 1
90908 2014-12-14 20:23:43.780 1 1 1
90907 2014-12-14 20:22:47.447 1 1 1
90906 2014-12-14 20:21:38.730 1 1 1
90905 2014-12-14 20:20:42.413 1 1 1
90904 2014-12-14 20:19:33.680 1 1 1
90903 2014-12-14 20:19:10.560 1 1 1
90902 2014-12-14 20:18:05.430 1 1 1
90901 2014-12-14 20:17:08.787 1 1 1
90900 2014-12-14 20:16:00.083 1 1 1
My serial monitor shows the spark trying to connect but only some made it through:
disconnecting.
connecting...
connected
Sent
Dconnecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connected
Sent
Dconnecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connection failed
disconnecting.
connecting...
connected
Sent
Dconnecting...
connection failed
Any suggestions on getting the spark to communicate on 4 second intervals? Thanks!