status request working

This commit is contained in:
mrbesen 2019-06-17 15:27:09 +02:00
parent 96d8f731af
commit 8d02b30818
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 30 additions and 6 deletions

View File

@ -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

View File

@ -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();
}