diff --git a/src/main.cpp b/src/main.cpp index 535c494..fcc7bdf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ void setup() pinMode(WIFI_RECEIVE_PIN, INPUT); pinMode(WIFI_TRANSMIT_PIN, OUTPUT); wifiSerial.begin(9600); + wifiSerial.listen(); pinMode(SHOW_PIN, INPUT_PULLUP); @@ -29,6 +30,7 @@ void setup() wifiCommandListener.when("set-schedule", (EvtCommandAction)relaySetSchedule); wifiCommandListener.when("set", (EvtCommandAction)relaySet); wifiCommandListener.when("ping", (EvtCommandAction)pingReceived); + wifiCommandListener.when("pong", (EvtCommandAction)pongReceived); mgr.addListener(&bluetoothCommandListener); mgr.addListener(&wifiCommandListener); @@ -36,15 +38,9 @@ void setup() attachInterrupt(digitalPinToInterrupt(SHOW_PIN), onInterrupt, FALLING); - Serial.println(F("Setup complete. Waiting for wifi...")); - - wifiSerial.listen(); - while (wifiSerial.available() > 0) - { - Serial.print((char)wifiSerial.read()); - } + Serial.println(F("Setup complete. Continuing...")); - Serial.println(F("Wifi is connected")); + wifiSerial.println(F(">ping!")); } bool idle() @@ -59,6 +55,13 @@ bool idle() bool pingReceived() { Serial.println(F("Ping received!")); + pingLastReceived = millis(); + return true; +} + +bool pongReceived() +{ + Serial.println(F("Pong received!")); return true; } @@ -104,11 +107,6 @@ bool relaySetSchedule(IEvtListener *, IEvtContext *, long data) void loop() { - bluetoothSerial.listen(); - mgr.loopIteration(); - - wifiSerial.listen(); - mgr.loopIteration(); } diff --git a/src/main.h b/src/main.h index f980727..48532b7 100644 --- a/src/main.h +++ b/src/main.h @@ -29,6 +29,8 @@ SoftwareSerial wifiSerial(WIFI_RECEIVE_PIN, WIFI_TRANSMIT_PIN); EvtCommandListener bluetoothCommandListener(&bluetoothSerial, 20); EvtCommandListener wifiCommandListener(&wifiSerial, 20); +unsigned long pingLastReceived = 0; + void onInterrupt(); bool idle(); bool sending(); @@ -37,5 +39,6 @@ bool relayRequestSync(); bool relaySet(IEvtListener *, IEvtContext *, long data); bool relaySetSchedule(IEvtListener *, IEvtContext *, long data); bool pingReceived(); +bool pongReceived(); #endif \ No newline at end of file