This commit is contained in:
mrbesen 2019-01-14 16:00:31 +01:00
parent ef58f6e5cf
commit c4fdec48f5
Signed by: MrBesen
GPG Key ID: 596B2350DCD67504
2 changed files with 36 additions and 12 deletions

View File

@ -33,10 +33,13 @@ void setup() {
void reportStatus() { void reportStatus() {
ser.print("s"); 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(statusbits & STATUS_WLAN ? "y" : "n");
ser.print(" Service: "); ser.print(" Service: ");
ser.print(statusbits & STATUS_SERVICE ? "y" : "n"); ser.print(statusbits & STATUS_SERVICE ? "y" : "n");*/
} }
void setStatus(unsigned char mask, bool newstat) { 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() { void loop() {
//logic //logic
//TODO: //TODO:
@ -71,33 +78,40 @@ void loop() {
//do reciving stuff //do reciving stuff
while(!client.available()) while(!client.available())
delay(1000); delay(1000);
Serial.println("Data available");
if(client.available()) {//never enters this state, why? if(client.available()) {//never enters this state, why?
Serial.println("recive stuff"); Serial.println("recive stuff");
lastping = millis(); lastping = millis();//reset lastping
unsigned char ch = static_cast<unsigned char>(client.read()); // read the size unsigned char ch = static_cast<unsigned char>(client.read()); // read the size
Serial.print("awaiting: ");
Serial.println(ch, DEC);
char* buff = new char[ch]; char* buff = new char[ch];
for(unsigned char i = 0; i < ch; i++) { for(unsigned char i = 0; i < ch; i++) {
if(client.available()) { if(client.available()) {
buff[i] = static_cast<char>(client.read()); buff[i] = static_cast<char>(client.read());
Serial.print(buff[i], HEX);
} else { } else {
buff[i] = 0; buff[i] = 0;
break; break;
} }
} }
//done reciving processing //done reciving processing
Serial.print("recived: "); Serial.print("\nrecived: ");
Serial.println(buff); Serial.println(buff);
//handle ? handleData(buff, ch);
} }
if( (millis() - lastping) > PINGREQUIRED) { if( (millis() - lastping)/1000 > PINGREQUIRED) {
//request ping //request ping
client.print("ping"); client.print("\x01p");
} else if((millis() - lastping) > PINGTIMEOUT) { Serial.println("ping sent");
} else if((millis() - lastping)/1000 > PINGTIMEOUT) {
//timeout //timeout
Serial.println("timedout");
client.stop(); client.stop();
} }
} else { } else {//client.connected()
//try to reconnect to server //try to reconnect to server
setStatus(STATUS_SERVICE, false); setStatus(STATUS_SERVICE, false);
Serial.println("connect to server"); Serial.println("connect to server");
@ -105,8 +119,10 @@ void loop() {
Serial.println("connection failed"); Serial.println("connection failed");
delay(5000); delay(5000);
} else { } else {
client.setNoDelay(true);
Serial.println("connected"); Serial.println("connected");
client.println("hello"); client.println("\x01h");
client.setTimeout(60*5000);//5min
} }
} }
} else { } else {

View File

@ -83,8 +83,16 @@ void handleWLAN() {
char first = wlan.read(); char first = wlan.read();
if(first == 's') { if(first == 's') {
//status update //status update
bool ava = true;
for(unsigned char i = 0; i < 20; i++) { 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] = ' ';
}
}
} }
} }
} }