Hallo allerseits,
mein Heizduino Projekt läuft recht gut, die bisherigen Probleme sind beseitigt und der Mega stürzt (bisher) nicht mehr ab.
Ich habe aber Schwierigkeiten mit dem Übermitteln der Daten zu Cosm. Den Arduino-Client habe ich in meinen Sketch eingebaut, es läuft nach den Strart ganz gut. Nach einigen Stunden/Tagen kommt bei Cosm aber nichts mehr an. Arduino läuft aber weiterhin ohne Absturz weiter, die Temperaturen werden im LCD-Display weiterhin neu angezeigt und mein rudimentäre Fehlerstatus läuft durch (kein Aufhängen).
Nun das Ungewöhnliche: Wenn ich das USB-Kabel anschliesse und den seriellen Monitor starte, sehe ich den String zu COSM und die Werte beginnen wieder bei Cosm einzugehen.
Unten habe ich die von der Loop aufgerufenen Funktionen zusammengefaßt.
Habt Ihr vielleicht eine Idee, warum es diese Abbrüche gibt?
Grüße
Michael
Zuerst die Variablen
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
// assign an IP address for the controller:
IPAddress ip(192,168,178,46);
// initialize the library instance:
EthernetClient client;
char server[] = "api.cosm.com";
//IPAddress server(216,52,233,121);
byte gateway[] = {
192,168,178,1};
byte subnet[] = {
255, 255, 255, 0};
Daten zu Cosm senden, die KEys etc. sind zuvor definiert
void sendData() // zu COSM
{lcd.setCursor(5,0); lcd.print(F("p"));
// this method makes a HTTP connection to the server:
// if there's a successful connection:
if (client.connect(server, 80))
{
Serial.println(F("connecting..."));
// send the HTTP PUT request:
client.print(F("PUT /v2/feeds/"));
client.print(FEEDID);
client.println(F(".csv HTTP/1.1"));
client.println(F("Host: api.pachube.com"));
client.print(F("X-PachubeApiKey: "));
client.println(APIKEY);
client.print(F("User-Agent: "));
client.println(USERAGENT);
client.print(F("Content-Length: "));
client.println(strlen(temp_string), DEC);
// war client.println(temp_string.length(), DEC);
// last pieces of the HTTP PUT request:
client.print(F("Content-Type: text/csv\n"));
client.println(F("Connection: close\n"));
// here's the actual content of the PUT request:
Serial.println(temp_string);
client.println(temp_string);
// note the time that the connection was made:
lastConnectionTime = millis();
}
else
{
// if you couldn't make a connection:
Serial.println(F("connection failed"));
Serial.println();
Serial.println(F("disconnecting."));
client.stop();
}
lcd.setCursor(5,0); lcd.print(F("P"));
}
void daten_zu_cosm()
{lcd.setCursor(5,0); lcd.print(F("q"));
// if there's incoming data from the net connection.
// send it out the serial port. This is for debugging
// purposes only:
while (client.available())
{
char c = client.read();
Serial.print(c);
}
// if there's no net connection, but there was one last time
// through the loop, then stop the client:
if (!client.connected() && lastConnected)
{
Serial.println();
Serial.println(F("disconnecting.."));
client.stop();
}
// if you're not connected, and ten seconds have passed since
// your last connection, then connect again and send data:
if(!client.connected() && (millis() - lastConnectionTime > postingInterval))
{
cosm_daten_zusammenstoepseln();
sendData(); // temp_string wird verschickt
}
// store the state of the connection for next time through
// the loop:
lastConnected = client.connected();
lcd.setCursor(5,0); lcd.print(F("Q"));
}
Der Ausschnitt des Setup
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0)
{
Serial.println(F("Failed to configure Ethernet using DHCP"));
// DHCP failed, so use a fixed IP address:
Ethernet.begin(mac, ip);
}
// -----------------------------------------
Wire.begin(); // für den Anschluss der Expander-Karte
delay(1000);