From 8d02b30818a8f1079b564b0592eeea580c66cf83 Mon Sep 17 00:00:00 2001 From: mrbesen Date: Mon, 17 Jun 2019 15:27:09 +0200 Subject: [PATCH] status request working --- nudelmaschine/esp/esp.ino | 14 ++++++++++++-- nudelmaschine/main/main.ino | 22 ++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/nudelmaschine/esp/esp.ino b/nudelmaschine/esp/esp.ino index 6ee9580..c7c7a44 100644 --- a/nudelmaschine/esp/esp.ino +++ b/nudelmaschine/esp/esp.ino @@ -64,14 +64,23 @@ void handleSerial() { if (in == 's') { reportStatus(); } else if(in == 'r') {//report + D("read status:") char* buffer = new char[64]; size_t i = 0; for(; i < 64 && ser.available(); i++) { buffer[i] = ser.read(); } - client.write(i+1); + D("status recived, sending") + D(buffer) + D("i:") + D(i) + client.write((i+1)-1); client.print('r'); - client.write(buffer, i); + client.write(buffer, i-1); + client.println(); + client.flush(); + delete[] buffer; + D("sending complete") } else if(in == 'a') { //TODO: forword to Service } @@ -92,6 +101,7 @@ void handleData(const char* data, size_t length) { case 'h': //hello D("Hello recived") ser.print('r');//get status + D("status requested") break; case 'g': //go (start) case 'r'://request report diff --git a/nudelmaschine/main/main.ino b/nudelmaschine/main/main.ino index 5ac69d7..6f1564f 100644 --- a/nudelmaschine/main/main.ino +++ b/nudelmaschine/main/main.ino @@ -14,10 +14,12 @@ long lastLCDupdate = millis(); boolean lcdchanged = true; int temp = 0; byte cancelcause = 0; //why is the heater off? -> 0= None, 1 = canceled (btn), 2= temp, 3=to long on, 4=tempmovement, 5=abort(inet) +byte state = 0; //current satate -> 0 = idle, 1 = heating, 2 = cooking long heating = -1;//millis() value when heater started int starttemp = 0; char status[21] = "--------------------";//dont forget \0 at the end const byte padd = 6;//used in updateLCD(), used to determine how far left the right part of the screen should be +const byte cookingtemp = 98; //desired start temp void setup() { pinMode(2, OUTPUT); @@ -96,6 +98,8 @@ void sendStatus() { wlan.print(cancelcause);//error? wlan.print('.');//delimiter wlan.print(temp);//temp + wlan.print('.');//delimiter + wlan.print(state); wlan.print('\0');//EOT } @@ -163,7 +167,7 @@ void checkHeater() { setheater(false); } - if (millis() - heating > 60000 && starttemp >= temp - 1) { //on for 60s and no temp did not change + if (millis() - heating > 60000 && starttemp >= temp - 1) { //on for 60s and temp did not change cancelcause = 4; setheater(false); } @@ -171,7 +175,7 @@ void checkHeater() { bool presed = false; void loop() { - delay(25); + delay(5); handleWLAN(); @@ -179,7 +183,7 @@ void loop() { int old = temp; temp = getTemp() / 100; /* if(old != temp) - lcdchanged = true;*/ + lcdchanged = true;*/ //cause random lcd turn on } if ((millis() - lastLCDupdate) > 500) { //reprint LCD every 1/2 seconds @@ -203,15 +207,25 @@ void loop() { if (heating > 0) checkHeater(); + + if(temp >= cookingtemp && state == 1) { + //coocking temp reached! + //go ! + state = 2; + sendStatus(); + //TODO: trigger servo + } } void setheater(bool on) { heating = on ? millis() : -1; if (on) { cancelcause = 0; - starttemp = temp; + starttemp = temp; } digitalWrite(2, on); digitalWrite(13, on); lcdchanged = true; + state = on; // on = true -> state = 1 (heating); on = false -> state = 0 (idle) + sendStatus(); }