Hi zusammen. Das von oSM runtergeladene Sketch führt im loop das submitValues() durch. Dieses sendet nur immer beim ersten Mal erfolgreich Daten. Zum zweiten Durchlauf läuft es immer in einen Timeout und connection failed und zum Restart der Box. Was ist anzupassen?
void submitValues() {
if (WiFi.status() != WL_CONNECTED) {
WiFi.disconnect();
delay(1000); // wait 1s
WiFi.begin(ssid, pass);
delay(5000); // wait 5s
}
// close any connection before send a new request.
// This will free the socket on the WiFi shield
if (client.connected()) {
client.stop();
delay(1000);
}
bool connected = false;
char _server[strlen_P(server)];
strcpy_P(_server, server);
for (uint8_t timeout = 2; timeout != 0; timeout--) {
Serial.println(F("connecting..."));
connected = client.connect(_server, 443);
if (connected == true) {
DEBUG(F("Connection successful, transferring..."));
// construct the HTTP POST request:
sprintf_P(buffer,
PSTR("POST /boxes/%s/data HTTP/1.1\nHost: %s\nContent-Type: "
"text/csv\nConnection: close\nContent-Length: %i\n\n"),
SENSEBOX_ID, server, num_measurements * 35);
DEBUG(buffer);
// send the HTTP POST request:
client.print(buffer);
// send measurements
writeMeasurementsToClient();
// send empty line to end the request
client.println();
uint16_t timeout = 0;
// allow the response to be computed
while (timeout <= 5000) {
delay(10);
timeout = timeout + 10;
if (client.available()) {
break;
}
}
while (client.available()) {
char c = client.read();
DEBUG_WRITE(c);
// if the server's disconnected, stop the client:
if (!client.connected()) {
DEBUG();
DEBUG("disconnecting from server.");
client.stop();
break;
}
}
DEBUG("done!");
// reset number of measurements
num_measurements = 0;
break;
}
delay(1000);
}
if (connected == false) {
// Reset durchführen
DEBUG(F("connection failed. Restarting System."));
delay(5000);
noInterrupts();
NVIC_SystemReset();
while (1)
;
}
}