Hi everyone,
I have been using Arduino WiFi shield to log sensor values to google spreadsheet. It logs perfectly.
But when I try to run it for a longer period it just stops sending. sometimes it stops after 20 minutes and sometimes it stops after 4-5 hours. The code is below. By the way the firmware version of Arduino WiFi shield is 1.1.0. I usually connect it the laptop to run the code, so I can see the serial monitor. There were no errors shown. For the last two tests I connected it to a 12V power supply.
#include <dht.h>
#include <SPI.h>
#include <WiFi.h>
#define dht_dpin A0
dht DHT;
char ssid[] = "mywifi";
int status = WL_IDLE_STATUS;
char server[] = "api.pushingbox.com";
WiFiClient client; //define 'client' as object
boolean DEBUG= true;
void setup()
{
Serial.begin(9600);
while (!Serial) {
;
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv != "1.1.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to open SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid);
delay(10000);
}
Serial.print("You're connected to the network");
}
void loop()
{
DHT.read11(dht_dpin);
double temp = DHT.temperature;
double hum = DHT.humidity;
delay(5000);
Serial.println("connecting...");
if(temp>=30)
{
if (client.connect(server, 80))
{
logData();
delay(70);
DEBUG = true;
}
else
{
Serial.println("connection failed");
}
// loop
while(DEBUG)
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
Serial.print("Current temperature = ");
Serial.println(DHT.temperature);
Serial.print("Current humidity = ");
Serial.println(DHT.humidity);
client.stop();
DEBUG=false;
}
if (client.connect(server, 80))
{
sendtemptoPushBullet();
delay(70);
DEBUG=true;
}
while(DEBUG)
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if(!client.connected())
{
Serial.println("disconnecting from pushbullet");
client.stop();
DEBUG=false;
}
}
}
}
else
{
if (client.connect(server, 80))
{
logData();
delay(70);
DEBUG = true;
}
else
{
Serial.println("connection failed");
}
// loop
while(DEBUG)
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if (!client.connected())
{
Serial.println();
Serial.println("disconnecting.");
Serial.print("Current temperature = ");
Serial.println(DHT.temperature);
Serial.print("Current humidity = ");
Serial.println(DHT.humidity);
client.stop();
DEBUG=false;
}
}
}
if(hum>=90)
{
if(client.connect(server, 80))
{
sendhumtoPushBullet();
delay(70);
DEBUG=true;
}
while(DEBUG)
{
if (client.available())
{
char c = client.read();
Serial.print(c);
}
if(!client.connected())
{
Serial.println("disconnecting from pushbullet");
client.stop();
DEBUG=false;
}
}
}
delay(120000);
}
void logData()
{
double temp= DHT.temperature;
double hum = DHT.humidity;
delay(1000);
Serial.println("connected");
client.print("GET /pushingbox?devid=");
client.print("mydeviceid");
client.print("&tempData=");
client.print(temp);
client.print("&humData=");
client.print(hum);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("User-Agent: Arduino");
client.println();
}
void sendtemptoPushBullet()
{
Serial.print("Sending notification to pushbullet");
client.print("GET /pushingbox?devid=");
client.print("mydeviceid");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("User-Agent: Arduino");
client.println();
}
void sendhumtoPushBullet()
{
Serial.print("Sending notification to pushbullet");
client.print("GET /pushingbox?devid=");
client.print("mydeviceid");
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("User-Agent: Arduino");
client.println();
}
Please give some suggestions.
Thank you