small changes
This commit is contained in:
parent
03b66fc9ac
commit
ea5b999b41
|
@ -33,7 +33,9 @@ unsigned long lastping = 0;
|
||||||
void setup() {
|
void setup() {
|
||||||
pinMode(LED, OUTPUT);
|
pinMode(LED, OUTPUT);
|
||||||
ser.begin(9600);
|
ser.begin(9600);
|
||||||
|
#if DEBUG > 0
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
#endif
|
||||||
wifi_station_set_hostname("NudelMaschine");
|
wifi_station_set_hostname("NudelMaschine");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +64,14 @@ void handleSerial() {
|
||||||
if (in == 's') {
|
if (in == 's') {
|
||||||
reportStatus();
|
reportStatus();
|
||||||
} else if(in == 'r') {//report
|
} else if(in == 'r') {//report
|
||||||
|
char* buffer = new char[64];
|
||||||
|
size_t i = 0;
|
||||||
|
for(; i < 64 && ser.available(); i++) {
|
||||||
|
buffer[i] = ser.read();
|
||||||
|
}
|
||||||
|
client.write(i+1);
|
||||||
|
client.print('r');
|
||||||
|
client.write(buffer, i);
|
||||||
} else if(in == 'a') {
|
} else if(in == 'a') {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -70,7 +79,7 @@ void handleSerial() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleData(const char* data, size_t length) {
|
void handleData(const char* data, size_t length) {
|
||||||
Serial.println("handle");
|
D("handle");
|
||||||
char type = data[0];
|
char type = data[0];
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'c': //close connection
|
case 'c': //close connection
|
||||||
|
@ -99,11 +108,13 @@ void connectWLAN() {
|
||||||
setStatus(STATUS_SERVICE, false);
|
setStatus(STATUS_SERVICE, false);
|
||||||
//try to connect to wifi
|
//try to connect to wifi
|
||||||
LEDOFF
|
LEDOFF
|
||||||
Serial.println("Connect to WiFi");
|
D("Connect to WiFi");
|
||||||
|
|
||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
|
#ifndef DHCP
|
||||||
WiFi.config(ip, gateway, subnet, gateway);
|
WiFi.config(ip, gateway, subnet, gateway);
|
||||||
|
#endif
|
||||||
while (WiFi.status() != WL_CONNECTED) delay(500);
|
while (WiFi.status() != WL_CONNECTED) delay(500);
|
||||||
D("IP address: ");
|
D("IP address: ");
|
||||||
D(WiFi.localIP());
|
D(WiFi.localIP());
|
||||||
|
@ -112,13 +123,13 @@ void connectWLAN() {
|
||||||
void connectService() {
|
void connectService() {
|
||||||
//try to reconnect to server
|
//try to reconnect to server
|
||||||
setStatus(STATUS_SERVICE, false);
|
setStatus(STATUS_SERVICE, false);
|
||||||
Serial.println("connect to server");
|
D("connect to server");
|
||||||
if (!client.connect(host, port)) {
|
if (!client.connect(host, port)) {
|
||||||
Serial.println("connection failed");
|
D("connection failed")
|
||||||
delay(5000);
|
delay(5000);
|
||||||
} else {
|
} else {
|
||||||
client.setNoDelay(true);
|
client.setNoDelay(true);
|
||||||
Serial.println("connected");
|
D("connected")
|
||||||
client.println("\x01h");
|
client.println("\x01h");
|
||||||
client.setTimeout(60 * 5000); //5min
|
client.setTimeout(60 * 5000); //5min
|
||||||
}
|
}
|
||||||
|
@ -128,10 +139,10 @@ void checkTimeout() {
|
||||||
if ( (millis() - lastping) / 1000 > PINGREQUIRED) { //TODO: check if ping allready sent
|
if ( (millis() - lastping) / 1000 > PINGREQUIRED) { //TODO: check if ping allready sent
|
||||||
//request ping
|
//request ping
|
||||||
client.println("\x01p");
|
client.println("\x01p");
|
||||||
Serial.println("ping sent");
|
D("ping sent")
|
||||||
} else if ((millis() - lastping) / 1000 > PINGTIMEOUT) {
|
} else if ((millis() - lastping) / 1000 > PINGTIMEOUT) {
|
||||||
//timeout
|
//timeout
|
||||||
Serial.println("timedout");
|
D("timedout")
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,14 +172,14 @@ void loop() {
|
||||||
handleSerial();
|
handleSerial();
|
||||||
}
|
}
|
||||||
|
|
||||||
Serial.println("Data available");
|
D("Data available")
|
||||||
|
|
||||||
if (client.available()) {
|
if (client.available()) {
|
||||||
Serial.print("\nrecive stuff ");
|
D("\nrecive stuff ");
|
||||||
lastping = millis();//reset lastping
|
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.print("awaiting: ");
|
||||||
Serial.println(ch, DEC);
|
D(ch);
|
||||||
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()) {
|
||||||
|
|
|
@ -117,7 +117,7 @@ void handleWLAN() {
|
||||||
if (first == 's') {
|
if (first == 's') {
|
||||||
//status update
|
//status update
|
||||||
bool ava = true;
|
bool ava = true;
|
||||||
for (unsigned char i = 0; i < 20; i++) {
|
for (unsigned char i = 0; i < 20; i++) { //does somehow not exit this loop???
|
||||||
char old = status[i];
|
char old = status[i];
|
||||||
char new_ = ' ';
|
char new_ = ' ';
|
||||||
if (wlan.available() && ava) {
|
if (wlan.available() && ava) {
|
||||||
|
|
|
@ -22,3 +22,4 @@ struct Data {
|
||||||
Data(byte t) : type(t), data('\0') {};
|
Data(byte t) : type(t), data('\0') {};
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue