update esp mqtt library
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClient.h>
|
||||
|
||||
@@ -47,11 +46,13 @@ void connectToMqtt() {
|
||||
}
|
||||
|
||||
void onWiFiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
(void) event;
|
||||
Serial.println("Connected to Wi-Fi.");
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWiFiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
(void) event;
|
||||
Serial.println("Disconnected from Wi-Fi.");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Updater.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClient.h>
|
||||
|
||||
@@ -37,11 +36,13 @@ void connectToMqtt() {
|
||||
}
|
||||
|
||||
void onWiFiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
(void) event;
|
||||
Serial.println("Connected to Wi-Fi.");
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWiFiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
(void) event;
|
||||
Serial.println("Disconnected from Wi-Fi.");
|
||||
}
|
||||
|
||||
@@ -109,6 +110,7 @@ void handleUpdate(const uint8_t* payload, size_t length, size_t index, size_t to
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) properties;
|
||||
if (strcmp(UPDATE_TOPIC, topic) != 0) {
|
||||
Serial.println("Topic mismatch");
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClient.h>
|
||||
|
||||
@@ -89,6 +88,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClient.h>
|
||||
|
||||
@@ -32,11 +31,13 @@ void connectToMqtt() {
|
||||
}
|
||||
|
||||
void onWiFiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
(void) event;
|
||||
Serial.println("Connected to Wi-Fi.");
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWiFiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
(void) event;
|
||||
Serial.println("Disconnected from Wi-Fi.");
|
||||
}
|
||||
|
||||
@@ -83,6 +84,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
@@ -18,6 +18,7 @@ build_flags =
|
||||
-pthread
|
||||
-Wall
|
||||
-Wextra
|
||||
-Werror
|
||||
|
||||
[env:native]
|
||||
platform = native
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClientAsync.h>
|
||||
|
||||
@@ -89,6 +88,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClientAsync.h>
|
||||
|
||||
@@ -32,11 +31,13 @@ void connectToMqtt() {
|
||||
}
|
||||
|
||||
void onWiFiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
(void) event;
|
||||
Serial.println("Connected to Wi-Fi.");
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWiFiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
(void) event;
|
||||
Serial.println("Disconnected from Wi-Fi.");
|
||||
}
|
||||
|
||||
@@ -83,6 +84,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#include <WiFi.h>
|
||||
#include <Ticker.h>
|
||||
|
||||
#include <espMqttClient.h>
|
||||
|
||||
@@ -16,7 +15,8 @@ const char rootCA[] = \
|
||||
" add your certificate here \n" \
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
espMqttClientSecure mqttClient;
|
||||
espMqttClientSecure mqttClient(espMqttClientTypes::UseInternalTask::NO);
|
||||
static TaskHandle_t taskHandle;
|
||||
bool reconnectMqtt = false;
|
||||
uint32_t lastReconnect = 0;
|
||||
|
||||
@@ -93,6 +93,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
@@ -116,6 +117,12 @@ void onMqttPublish(uint16_t packetId) {
|
||||
Serial.println(packetId);
|
||||
}
|
||||
|
||||
void networkingTask() {
|
||||
for (;;) {
|
||||
mqttClient.loop();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
@@ -137,6 +144,8 @@ void setup() {
|
||||
mqttClient.setServer(MQTT_HOST, MQTT_PORT);
|
||||
mqttClient.setCleanSession(true);
|
||||
|
||||
xTaskCreatePinnedToCore((TaskFunction_t)networkingTask, "mqttclienttask", 5120, nullptr, 1, &taskHandle, 0);
|
||||
|
||||
connectToWiFi();
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,13 @@ void connectToMqtt() {
|
||||
}
|
||||
|
||||
void onWiFiConnect(const WiFiEventStationModeGotIP& event) {
|
||||
(void) event;
|
||||
Serial.println("Connected to Wi-Fi.");
|
||||
connectToMqtt();
|
||||
}
|
||||
|
||||
void onWiFiDisconnect(const WiFiEventStationModeDisconnected& event) {
|
||||
(void) event;
|
||||
Serial.println("Disconnected from Wi-Fi.");
|
||||
}
|
||||
|
||||
@@ -86,6 +88,7 @@ void onMqttUnsubscribe(uint16_t packetId) {
|
||||
}
|
||||
|
||||
void onMqttMessage(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total) {
|
||||
(void) payload;
|
||||
Serial.println("Publish received.");
|
||||
Serial.print(" topic: ");
|
||||
Serial.println(topic);
|
||||
|
||||
Reference in New Issue
Block a user