diff --git a/nudelmaschine/esp/esp.ino b/nudelmaschine/esp/esp.ino index 85d455d..3889a07 100644 --- a/nudelmaschine/esp/esp.ino +++ b/nudelmaschine/esp/esp.ino @@ -33,10 +33,13 @@ void setup() { void reportStatus() { ser.print("s"); - ser.print("WLAN: "); + ser.print(statusbits & STATUS_WLAN ? "W" : "w"); + ser.print(statusbits & STATUS_SERVICE ? "S" : "s"); + ser.print("\0");//EOT + /*ser.print("WLAN: "); ser.print(statusbits & STATUS_WLAN ? "y" : "n"); ser.print(" Service: "); - ser.print(statusbits & STATUS_SERVICE ? "y" : "n"); + ser.print(statusbits & STATUS_SERVICE ? "y" : "n");*/ } void setStatus(unsigned char mask, bool newstat) { @@ -50,6 +53,10 @@ void setStatus(unsigned char mask, bool newstat) { } } +void handleData(const char* data, size_t length) { + +} + void loop() { //logic //TODO: @@ -71,33 +78,40 @@ void loop() { //do reciving stuff while(!client.available()) delay(1000); - + + Serial.println("Data available"); + if(client.available()) {//never enters this state, why? Serial.println("recive stuff"); - lastping = millis(); + lastping = millis();//reset lastping unsigned char ch = static_cast(client.read()); // read the size + Serial.print("awaiting: "); + Serial.println(ch, DEC); char* buff = new char[ch]; for(unsigned char i = 0; i < ch; i++) { if(client.available()) { buff[i] = static_cast(client.read()); + Serial.print(buff[i], HEX); } else { buff[i] = 0; break; } } //done reciving processing - Serial.print("recived: "); + Serial.print("\nrecived: "); Serial.println(buff); - //handle ? + handleData(buff, ch); } - if( (millis() - lastping) > PINGREQUIRED) { + if( (millis() - lastping)/1000 > PINGREQUIRED) { //request ping - client.print("ping"); - } else if((millis() - lastping) > PINGTIMEOUT) { + client.print("\x01p"); + Serial.println("ping sent"); + } else if((millis() - lastping)/1000 > PINGTIMEOUT) { //timeout + Serial.println("timedout"); client.stop(); } - } else { + } else {//client.connected() //try to reconnect to server setStatus(STATUS_SERVICE, false); Serial.println("connect to server"); @@ -105,8 +119,10 @@ void loop() { Serial.println("connection failed"); delay(5000); } else { + client.setNoDelay(true); Serial.println("connected"); - client.println("hello"); + client.println("\x01h"); + client.setTimeout(60*5000);//5min } } } else { diff --git a/nudelmaschine/main/main.ino b/nudelmaschine/main/main.ino index 0a48f94..b63c744 100644 --- a/nudelmaschine/main/main.ino +++ b/nudelmaschine/main/main.ino @@ -83,8 +83,16 @@ void handleWLAN() { char first = wlan.read(); if(first == 's') { //status update + bool ava = true; for(unsigned char i = 0; i < 20; i++) { - status[i] = wlan.available() ? wlan.read() : ' '; + status[i] = ' '; + if(wlan.available() && ava) { + status[i] = wlan.read(); + if(status[i] == '\0') { + ava = false; + status[i] = ' '; + } + } } } }