If MQTT connected don't let the board enter LS state

1.2-legacy
Kevin Hester 2021-08-02 21:34:14 -07:00
rodzic 2af4c619e1
commit 28af18389b
4 zmienionych plików z 16 dodań i 6 usunięć

Wyświetl plik

@ -70,7 +70,7 @@ lib_deps =
https://github.com/meshtastic/esp8266-oled-ssd1306.git#35d796226b853b0c0ff818b2f1aa3d35e7296a96 ; ESP8266_SSD1306
https://github.com/geeksville/OneButton.git ; OneButton library for non-blocking button debounce
1202 ; CRC32, explicitly needed because dependency is missing in the ble ota update lib
https://github.com/meshtastic/arduino-fsm.git#829e967b8a95c094f73c60ef8dacfe66eae38940
https://github.com/meshtastic/arduino-fsm.git
https://github.com/meshtastic/SparkFun_Ublox_Arduino_Library.git#31015a55e630a2df77d9d714669c621a5bf355ad
https://github.com/meshtastic/RadioLib.git#80ed10d689a0568782c5bd152906b0f97d2bce93
https://github.com/meshtastic/TinyGPSPlus.git#f0f47067ef2f67c856475933188251c1ef615e79

Wyświetl plik

@ -27,6 +27,7 @@ static bool isPowered()
static void sdsEnter()
{
DEBUG_MSG("Enter state: SDS\n");
// FIXME - make sure GPS and LORA radio are off first - because we want close to zero current draw
doDeepSleep(getPref_sds_secs() * 1000LL);
}
@ -112,6 +113,7 @@ static void lsIdle()
static void lsExit()
{
DEBUG_MSG("Exit state: LS\n");
// setGPSPower(true); // restore GPS power
if (gps)
gps->forceWake(true);
@ -119,6 +121,7 @@ static void lsExit()
static void nbEnter()
{
DEBUG_MSG("Enter state: NB\n");
screen->setOn(false);
setBluetoothEnable(false);
@ -133,6 +136,7 @@ static void darkEnter()
static void serialEnter()
{
DEBUG_MSG("Enter state: SERIAL\n");
setBluetoothEnable(false);
screen->setOn(true);
screen->print("Serial connected\n");
@ -145,6 +149,7 @@ static void serialExit()
static void powerEnter()
{
DEBUG_MSG("Enter state: POWER\n");
if (!isPowered()) {
// If we got here, we are in the wrong state - we should be in powered, let that state ahndle things
DEBUG_MSG("Loss of power in Powered\n");
@ -174,6 +179,7 @@ static void powerExit()
static void onEnter()
{
DEBUG_MSG("Enter state: ON\n");
screen->setOn(true);
setBluetoothEnable(true);
@ -202,7 +208,9 @@ static void screenPress()
screen->onPress();
}
static void bootEnter() {}
static void bootEnter() {
DEBUG_MSG("Enter state: BOOT\n");
}
State stateSDS(sdsEnter, NULL, NULL, "SDS");
State stateLS(lsEnter, lsIdle, lsExit, "LS");

Wyświetl plik

@ -4,6 +4,7 @@
#include "mesh/Channels.h"
#include "mesh/Router.h"
#include "mesh/generated/mqtt.pb.h"
#include "PowerFSM.h"
#include "sleep.h"
#include <WiFi.h>
#include <assert.h>
@ -59,7 +60,7 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient)
pubSub.setCallback(mqttCallback);
preflightSleepObserver.observe(&preflightSleep);
// preflightSleepObserver.observe(&preflightSleep);
}
void MQTT::reconnect()
@ -151,6 +152,7 @@ int32_t MQTT::runOnce()
pubSub.disconnect();
}
powerFSM.trigger(EVENT_CONTACT_FROM_PHONE); // Suppress entering light sleep (because that would turn off bluetooth)
return 20;
}
}

Wyświetl plik

@ -19,8 +19,8 @@ class MQTT : private concurrency::OSThread
WiFiClient mqttClient;
PubSubClient pubSub;
CallbackObserver<MQTT, void *> preflightSleepObserver =
CallbackObserver<MQTT, void *>(this, &MQTT::preflightSleepCb);
// instead we supress sleep from our runOnce() callback
// CallbackObserver<MQTT, void *> preflightSleepObserver = CallbackObserver<MQTT, void *>(this, &MQTT::preflightSleepCb);
public:
MQTT();
@ -58,7 +58,7 @@ class MQTT : private concurrency::OSThread
void onPublish(char *topic, byte *payload, unsigned int length);
/// Return 0 if sleep is okay, veto sleep if we are connected to pubsub server
int preflightSleepCb(void *unused = NULL) { return pubSub.connected() ? 1 : 0; }
// int preflightSleepCb(void *unused = NULL) { return pubSub.connected() ? 1 : 0; }
};
void mqttInit();