mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-25 19:27:28 +00:00
While connected to MQTT server, veto light-sleep (to keep wifi working)
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "mesh/Channels.h"
|
||||
#include "mesh/Router.h"
|
||||
#include "mesh/generated/mqtt.pb.h"
|
||||
#include "sleep.h"
|
||||
#include <WiFi.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -57,11 +58,12 @@ MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient)
|
||||
mqtt = this;
|
||||
|
||||
pubSub.setCallback(mqttCallback);
|
||||
|
||||
preflightSleepObserver.observe(&preflightSleep);
|
||||
}
|
||||
|
||||
void MQTT::reconnect()
|
||||
{
|
||||
// pubSub.setServer("devsrv.ezdevice.net", 1883); or 192.168.10.188
|
||||
const char *serverAddr = "mqtt.meshtastic.org"; // default hostname
|
||||
int serverPort = 1883; // default server port
|
||||
|
||||
@@ -78,7 +80,7 @@ void MQTT::reconnect()
|
||||
}
|
||||
pubSub.setServer(serverAddr, serverPort);
|
||||
|
||||
DEBUG_MSG("Connecting to MQTT server %s, port: %d\n", server.c_str(), serverPort);
|
||||
DEBUG_MSG("Connecting to MQTT server %s, port: %d\n", serverAddr, serverPort);
|
||||
auto myStatus = (statusTopic + owner.id);
|
||||
bool connected = pubSub.connect(owner.id, "meshdev", "large4cats", myStatus.c_str(), 1, true, "offline");
|
||||
if (connected) {
|
||||
|
||||
@@ -19,6 +19,9 @@ class MQTT : private concurrency::OSThread
|
||||
WiFiClient mqttClient;
|
||||
PubSubClient pubSub;
|
||||
|
||||
CallbackObserver<MQTT, void *> preflightSleepObserver =
|
||||
CallbackObserver<MQTT, void *>(this, &MQTT::preflightSleepCb);
|
||||
|
||||
public:
|
||||
MQTT();
|
||||
|
||||
@@ -53,6 +56,9 @@ class MQTT : private concurrency::OSThread
|
||||
|
||||
/// Called when a new publish arrives from the MQTT server
|
||||
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; }
|
||||
};
|
||||
|
||||
void mqttInit();
|
||||
|
||||
Reference in New Issue
Block a user