Skip to content

Commit

Permalink
Receive ping message
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewturner committed Oct 26, 2023
1 parent 7f605ac commit 735c59d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ void setup()
{
Serial.begin(115200);

// pinMode(BT_RECEIVE_PIN, INPUT);
// pinMode(BT_TRANSMIT_PIN, OUTPUT);
// bluetoothSerial.begin(9600);
pinMode(BT_RECEIVE_PIN, INPUT);
pinMode(BT_TRANSMIT_PIN, OUTPUT);
bluetoothSerial.begin(9600);

pinMode(WIFI_RECEIVE_PIN, INPUT);
pinMode(WIFI_TRANSMIT_PIN, OUTPUT);
Expand All @@ -28,22 +28,37 @@ void setup()

wifiCommandListener.when("set-schedule", (EvtCommandAction)relaySetSchedule);
wifiCommandListener.when("set", (EvtCommandAction)relaySet);
wifiCommandListener.when("ping", (EvtCommandAction)pingReceived);

// mgr.addListener(&bluetoothCommandListener);
mgr.addListener(&bluetoothCommandListener);
mgr.addListener(&wifiCommandListener);
mgr.addListener(&stateMachine);

attachInterrupt(digitalPinToInterrupt(SHOW_PIN), onInterrupt, FALLING);

Serial.println(F("Setup complete. Continuing..."));
Serial.println(F("Setup complete. Waiting for wifi..."));

wifiSerial.listen();
while (wifiSerial.available() > 0)
{
Serial.print((char)wifiSerial.read());
}

Serial.println(F("Wifi is connected"));
}

bool idle()
{
Serial.println(F("Sleeping..."));
Serial.flush();
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
SPI_OFF, USART0_OFF, TWI_OFF);
// Serial.println(F("Sleeping..."));
// Serial.flush();
// LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF,
// SPI_OFF, USART0_OFF, TWI_OFF);
return true;
}

bool pingReceived()
{
Serial.println(F("Ping received!"));
return true;
}

Expand All @@ -69,9 +84,9 @@ bool relaySet(IEvtListener *, IEvtContext *, long data)
{
Serial.println(F("Relaying set command..."));

// bluetoothSerial.print(F(">set:"));
// bluetoothSerial.print(data);
// bluetoothSerial.println(F("!"));
bluetoothSerial.print(F(">set:"));
bluetoothSerial.print(data);
bluetoothSerial.println(F("!"));

return true;
}
Expand All @@ -80,15 +95,20 @@ bool relaySetSchedule(IEvtListener *, IEvtContext *, long data)
{
Serial.println(F("Relaying set-schedule command..."));

// bluetoothSerial.print(F(">set-schedule:"));
// bluetoothSerial.print(data);
// bluetoothSerial.println(F("!"));
bluetoothSerial.print(F(">set-schedule:"));
bluetoothSerial.print(data);
bluetoothSerial.println(F("!"));

return true;
}

void loop()
{
bluetoothSerial.listen();
mgr.loopIteration();

wifiSerial.listen();

mgr.loopIteration();
}

Expand Down
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ bool sending();
bool relayRequestSync();
bool relaySet(IEvtListener *, IEvtContext *, long data);
bool relaySetSchedule(IEvtListener *, IEvtContext *, long data);
bool pingReceived();

#endif

0 comments on commit 735c59d

Please sign in to comment.