Hi Guys…
my core stops running after a while (may be 5 minuts to max 45 minutes)
what I’m doing is reading from several analog / digital inputs, putting them in a JSONlike string and post it once a minute to my server via TCPIPClient
I use the RGBled as some kind of visual heartbeat, Sometimes I noticed a whatchdog reboot, after this the code has continued…but sometimes the code will stop and the core looks like an idle one??
Another point I was wondering about was that I have to use unsigned int pin1=A1
if int
i got an ugly Character when concatenating to my logString
e.G. X1234
instead of 1234
the hex value of the ugly thing is 14??
Is there a method to trigger the watchdog api??
Is there a chance to finding out what’s going on? Any Idea welcome!
KR
Pitt
code follows:
int di02=D2;
int di03=D3;
//D0: SDA (Serial Data Line)
//D1: SCL (Serial Clock)
int do04=D4;
int do05=D5;
int led=D6;
int errled=D7;
int ai00 = A0;
int ai01 = A1;
// A3 - A5 may be used by SPI
int ai06 = A6;
const int ai07 = A7;
String logString;
unsigned int tmp=0; //??
unsigned int prs=0;
unsigned int alt=0;
unsigned int dis=0;
unsigned int btn=0;
unsigned int bln=0; // ??
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
bool lastConnected = false; // state of the connection last time through the main loop
const unsigned long postingInterval = 1 *60*1000; // delay between updates, in milliseconds
TCPClient client;
const IPAddress server(192,168,2,111); // address for couchdb server (NOT using DNS)
const char key[]= "xxxxxxxxx";
String getData() {
tmp=analogRead(ai00);// "12.5";
prs=analogRead(ai01);
dis=analogRead(ai06);
alt=analogRead(ai07);
btn=digitalRead(di02);
bln=digitalRead(di03);
logString = "{\"type\":";
logString += "\"logRecord\",";
logString += "\"pressure\":";
logString += prs;
logString +=",";
logString += "\"temperature\":";
logString += tmp;
logString +=",";
logString += "\"altitude\":";
logString += alt;
logString +=",";
logString += "\"digitalBtn\":";
logString += btn;
logString +=",";
logString += "\"digitalBln\":";
logString += bln;
logString +=",";
logString += "\"distance\":";
logString += dis;
logString += "}";
Serial.println(logString);
return logString;
}
void setup() {
Serial.begin(19200);
pinMode(led,OUTPUT);
pinMode(errled,OUTPUT);
pinMode(di02,INPUT);
pinMode(di03,INPUT);
pinMode(do04,OUTPUT);
pinMode(do05,OUTPUT);
digitalWrite(errled,HIGH);
delay(200);
digitalWrite(errled,LOW);
delay(200);
digitalWrite(errled,HIGH);
delay(200);
digitalWrite(errled,LOW);
Serial.println("core ready...");
sendData(getData());
}
void loop() {
if(millis() - lastConnectionTime > postingInterval) {
sendData(getData());
}
RGB.control(true);
// red, green, blue, 0-255
RGB.color(0, 20, 0);
// wait one second
delay(1000);
// resume normal operation
RGB.control(false);
}
void sendData(String logString ){
lastConnectionTime = millis();
int lng = logString.length() +1;
char logRecord[lng];
logString.toCharArray(logRecord, lng);
if (client.connect(server, 5984)) {
digitalWrite(led,HIGH);
Serial.println("connecetd...");
client.print("POST ");
client.print("/emon/ "); // couchdatabase
client.println("HTTP/1.1");
client.print("Authorization: ");
client.println(key);
client.println("Content-Type: application/json");
client.println("Host: home.dewaard.de"); // ??
client.print("Content-Length: ");
client.println(strlen(logRecord));
client.println();
client.println(logRecord);
client.println("User-Agent: sparkyOne");
client.println("Connection: close");
client.println();
// note the time that the connection was made:
delay(1000);
digitalWrite(led,LOW);
client.flush();
client.stop();
}
else {
// you didn't get a connection to the server:
digitalWrite(errled,HIGH);
Serial.println("connection failed");
//Serial1.println("disconnecting.");
client.flush();
client.stop();
delay(1000);
digitalWrite(errled,LOW);
delay(1000);
}
}