mirror of
https://github.com/meshtastic/firmware.git
synced 2026-01-08 19:07:26 +00:00
MQTT is working over ethernet
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
#include "mesh/generated/mqtt.pb.h"
|
||||
#include "mesh/generated/telemetry.pb.h"
|
||||
#include "sleep.h"
|
||||
#if HAS_WIFI
|
||||
#include <WiFi.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <json11.hpp>
|
||||
|
||||
@@ -189,7 +191,12 @@ bool MQTT::wantsLink() const
|
||||
}
|
||||
}
|
||||
|
||||
#if HAS_WIFI
|
||||
return hasChannel && WiFi.isConnected();
|
||||
#endif
|
||||
#if HAS_ETHERNET
|
||||
return hasChannel && (Ethernet.linkStatus() == LinkON);
|
||||
#endif
|
||||
}
|
||||
|
||||
int32_t MQTT::runOnce()
|
||||
@@ -346,9 +353,9 @@ std::string MQTT::downstreamPacketToJson(MeshPacket *mp)
|
||||
msgPayload = Json::object{
|
||||
{"time", (int)decoded->time},
|
||||
{"pos_timestamp", (int)decoded->timestamp},
|
||||
{"latitude_i", decoded->latitude_i},
|
||||
{"longitude_i", decoded->longitude_i},
|
||||
{"altitude", decoded->altitude}
|
||||
{"latitude_i", (int)decoded->latitude_i},
|
||||
{"longitude_i", (int)decoded->longitude_i},
|
||||
{"altitude", (int)decoded->altitude}
|
||||
};
|
||||
} else {
|
||||
DEBUG_MSG("Error decoding protobuf for position message!\n");
|
||||
@@ -371,8 +378,8 @@ std::string MQTT::downstreamPacketToJson(MeshPacket *mp)
|
||||
{"description", decoded->description},
|
||||
{"expire", (int)decoded->expire},
|
||||
{"locked", decoded->locked},
|
||||
{"latitude_i", decoded->latitude_i},
|
||||
{"longitude_i", decoded->longitude_i},
|
||||
{"latitude_i", (int)decoded->latitude_i},
|
||||
{"longitude_i", (int)decoded->longitude_i},
|
||||
};
|
||||
} else {
|
||||
DEBUG_MSG("Error decoding protobuf for position message!\n");
|
||||
|
||||
@@ -5,7 +5,12 @@
|
||||
#include "concurrency/OSThread.h"
|
||||
#include "mesh/Channels.h"
|
||||
#include <PubSubClient.h>
|
||||
#if HAS_WIFI
|
||||
#include <WiFiClient.h>
|
||||
#endif
|
||||
#if HAS_ETHERNET
|
||||
#include <EthernetClient.h>
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Our wrapper/singleton for sending/receiving MQTT "udp" packets. This object isolates the MQTT protocol implementation from
|
||||
@@ -16,7 +21,12 @@ class MQTT : private concurrency::OSThread
|
||||
// supposedly the current version is busted:
|
||||
// http://www.iotsharing.com/2017/08/how-to-use-esp32-mqtts-with-mqtts-mosquitto-broker-tls-ssl.html
|
||||
// WiFiClientSecure wifiClient;
|
||||
#if HAS_WIFI
|
||||
WiFiClient mqttClient;
|
||||
#endif
|
||||
#if HAS_ETHERNET
|
||||
EthernetClient mqttClient;
|
||||
#endif
|
||||
PubSubClient pubSub;
|
||||
|
||||
// instead we supress sleep from our runOnce() callback
|
||||
|
||||
Reference in New Issue
Block a user