Hi,
I realize this is a common topic and some of the suggestions but this sketch has string variables and I don't know how to eliminate them (many have suggested this as a possible problem)
The sketch uses an Arduino UNO and a DHT temp/humidity sensor to send that data via WiFi to a local Coldfusion Server but it makes no difference where the data is sent (locally or to an Internet address), it still locks up after about the same length of time. Maybe it's the HEAP and memory fragmentation? How do I check that? It seems the WiFi is still connected but the sketch just stops looping.
Thank you for your suggestions
#include <DHT.h>
#include <DHT_U.h>
#include <DHT.h>;
#include<Timer.h>
Timer t;
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 3);
//#define dht_dpin 12
#define DHTPIN 12
#define heart 13
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
const char *workaround="OK";
static char postUrl[150];
float humi;
float tem;
//int tem,humi;
float temConv;
float humiConv;
void httpGet(String ip, String path, int port=80);
void setup()
{
Serial1.begin(57600);
Serial.begin(57600);
Serial.println("Delay: 5Min(300000ms), ESP8266-10, DHT22-2");
Serial.println("Connecting Wifi....");
connect_wifi("AT",1000);
connect_wifi("AT+CWMODE=1",1000);
connect_wifi("AT+CIPSTA=\"192.168.xxx.xxx\",\"192.168.xxx.xxx\",\"255.255.255.000\"",10000);
connect_wifi("AT+CWQAP",1000);
connect_wifi("AT+RST",5000);
connect_wifi("AT+CWJAP=\"SSID\",\"PIN\"",10000);
Serial.println("Wifi Connected");
pinMode(heart, OUTPUT);
delay(2000);
t.oscillate(heart, 1000, LOW);
t.every(300000, send2server); // 50000 = 1 minute
}
void loop()
{
humi = dht.readHumidity();
tem= dht.readTemperature();
// DHT.read11(DHTPIN);
//humi=DHT.humidity;
// tem=DHT.temperature;
delay(2000);
t.update();
}
void send2server()
{
char tempStr[8];
char humidStr[8];
char idStr[8];
temConv=(tem*1.8)+32;
temConv=temConv-3.5; //Correction for DHT22-2
// Humidity Calibrations
// if ((humi <= 47) && (humi > 40)) humiConv=humi+1;
// if ((humi <= 40) && (humi > 39)) humiConv=humi+2;
// if ((humi <= 39) && (humi > 36)) humiConv=humi+3;
// if ((humi <= 36) && (humi > 34)) humiConv=humi+4;
// if (humi <= 34) humiConv=humi+5;
humiConv=humi; //For DHT22 -2
dtostrf(temConv, 5, 3, tempStr);
dtostrf(humiConv, 5, 3, humidStr);
sprintf(postUrl, "temphumid/temphumid.cfm?humidity=%s&temperature=%s&ID=TH-1",humidStr,tempStr,idStr);
httpGet("192.168.xxx.xxx", postUrl, 80);
}
void httpGet(String ip, String path, int port)
{
int resp;
String atHttpGetCmd = "GET /"+path+" HTTP/1.0\r\n\r\n";
String atTcpPortConnectCmd = "AT+CIPSTART=\"TCP\",\""+ip+"\","+port+"";
connect_wifi(atTcpPortConnectCmd,2000);
int len = atHttpGetCmd.length();
String atSendCmd = "AT+CIPSEND=";
atSendCmd+=len;
connect_wifi(atSendCmd,3000);
connect_wifi(atHttpGetCmd,3000);
}
void connect_wifi(String cmd, int t)
{
int temp=0,i=0;
while(1)
{
Serial.println(cmd);
Serial1.println(cmd);
while(Serial1.available())
{
if(Serial1.find("OK"))
i=8;
}
delay(t);
if(i>5)
break;
i++;
}
if(i==8)
{
Serial.println("OK");
}
else
{
Serial.println("Error");
}
}