|
|
|
|
@ -10,6 +10,8 @@
|
|
|
|
|
|
|
|
|
|
#define POWER_BUTTON_HOLD_MS 300
|
|
|
|
|
|
|
|
|
|
#define POWER_NO_COMMS_TIMEOUT_MS 1000 * 60 * 5 // 5 minutes
|
|
|
|
|
|
|
|
|
|
EspMQTTClient mqtt_client("devtest", // Wifi SSID
|
|
|
|
|
"87usc6rs", // WiFi password
|
|
|
|
|
"10.9.2.101", // MQTT Broker server ip
|
|
|
|
|
@ -124,6 +126,7 @@ motor_control_group_t motor_control_group;
|
|
|
|
|
unsigned long now = 0;
|
|
|
|
|
unsigned long last_motor_status = 0;
|
|
|
|
|
unsigned long last_heartbeat = 0;
|
|
|
|
|
unsigned long no_comms_timeout_start = 0;
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
now = millis();
|
|
|
|
|
@ -133,14 +136,21 @@ void loop() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Comms LED is solid blue if everything connected
|
|
|
|
|
if (mqtt_client.isConnected()){
|
|
|
|
|
if (mqtt_client.isConnected()) {
|
|
|
|
|
digitalWrite(GPIO_ACT_LED, HIGH);
|
|
|
|
|
} else if (mqtt_client.isWifiConnected()){
|
|
|
|
|
no_comms_timeout_start = now;
|
|
|
|
|
} else if (mqtt_client.isWifiConnected()) {
|
|
|
|
|
// If WiFi is connected but MQTT is not, blinks with a period of 3 Hz
|
|
|
|
|
digitalWrite(GPIO_ACT_LED, (now % 333)<167);
|
|
|
|
|
digitalWrite(GPIO_ACT_LED, (now % 333) < 167);
|
|
|
|
|
no_comms_timeout_start = now;
|
|
|
|
|
} else {
|
|
|
|
|
// If no WiFi, blinks with a period of 1 Hz
|
|
|
|
|
digitalWrite(GPIO_ACT_LED, (now % 1000)<501);
|
|
|
|
|
digitalWrite(GPIO_ACT_LED, (now % 1000) < 501);
|
|
|
|
|
|
|
|
|
|
// If its been long enough without comms, turn power off
|
|
|
|
|
if ((now - no_comms_timeout_start) > POWER_NO_COMMS_TIMEOUT_MS) {
|
|
|
|
|
digitalWrite(GPIO_SYS_EN, LOW);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (now - last_motor_status > MOTOR_STATUS_UPDATE_PERIOD_MS) {
|
|
|
|
|
|