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') { if (in == 's') {
reportStatus(); reportStatus();
} else if(in == 'r') {//report } else if(in == 'r') {//report
D("read status:")
char* buffer = new char[64]; char* buffer = new char[64];
size_t i = 0; size_t i = 0;
for(; i < 64 && ser.available(); i++) { for(; i < 64 && ser.available(); i++) {
buffer[i] = ser.read(); 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.print('r');
client.write(buffer, i); client.write(buffer, i-1);
client.println();
client.flush();
delete[] buffer;
D("sending complete")
} else if(in == 'a') { } else if(in == 'a') {
//TODO: forword to Service //TODO: forword to Service
} }
@ -92,6 +101,7 @@ void handleData(const char* data, size_t length) {
case 'h': //hello case 'h': //hello
D("Hello recived") D("Hello recived")
ser.print('r');//get status ser.print('r');//get status
D("status requested")
break; break;
case 'g': //go (start) case 'g': //go (start)
case 'r'://request report case 'r'://request report

View File

@ -14,10 +14,12 @@ long lastLCDupdate = millis();
boolean lcdchanged = true; boolean lcdchanged = true;
int temp = 0; 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 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 long heating = -1;//millis() value when heater started
int starttemp = 0; int starttemp = 0;
char status[21] = "--------------------";//dont forget \0 at the end 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 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() { void setup() {
pinMode(2, OUTPUT); pinMode(2, OUTPUT);
@ -96,6 +98,8 @@ void sendStatus() {
wlan.print(cancelcause);//error? wlan.print(cancelcause);//error?
wlan.print('.');//delimiter wlan.print('.');//delimiter
wlan.print(temp);//temp wlan.print(temp);//temp
wlan.print('.');//delimiter
wlan.print(state);
wlan.print('\0');//EOT wlan.print('\0');//EOT
} }
@ -163,7 +167,7 @@ void checkHeater() {
setheater(false); 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; cancelcause = 4;
setheater(false); setheater(false);
} }
@ -171,7 +175,7 @@ void checkHeater() {
bool presed = false; bool presed = false;
void loop() { void loop() {
delay(25); delay(5);
handleWLAN(); handleWLAN();
@ -179,7 +183,7 @@ void loop() {
int old = temp; int old = temp;
temp = getTemp() / 100; temp = getTemp() / 100;
/* if(old != temp) /* if(old != temp)
lcdchanged = true;*/ lcdchanged = true;*/ //cause random lcd turn on
} }
if ((millis() - lastLCDupdate) > 500) { //reprint LCD every 1/2 seconds if ((millis() - lastLCDupdate) > 500) { //reprint LCD every 1/2 seconds
@ -203,15 +207,25 @@ void loop() {
if (heating > 0) if (heating > 0)
checkHeater(); checkHeater();
if(temp >= cookingtemp && state == 1) {
//coocking temp reached!
//go !
state = 2;
sendStatus();
//TODO: trigger servo
}
} }
void setheater(bool on) { void setheater(bool on) {
heating = on ? millis() : -1; heating = on ? millis() : -1;
if (on) { if (on) {
cancelcause = 0; cancelcause = 0;
starttemp = temp; starttemp = temp;
} }
digitalWrite(2, on); digitalWrite(2, on);
digitalWrite(13, on); digitalWrite(13, on);
lcdchanged = true; lcdchanged = true;
state = on; // on = true -> state = 1 (heating); on = false -> state = 0 (idle)
sendStatus();
} }