-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using ESP8266 as MQTT broker and datalogger #77
Comments
I was able to achieve the desired result of accessing the last published payload in the serial output. I've used a mixed trial and error approach with the help of ChatGPT, with the following modification of the uMQTTBroker.h and uMQTTBroker.cpp files. Attaching the final version of the files |
#include "uMQTTBroker.h" uMQTTBroker *uMQTTBroker::TheBroker; // Get access to last payload F.Dallo
// end F.Dallo
// Get access to last payload F.Dallo
|
#ifndef MQTT_SERVER_H #include "user_interface.h" #ifndef ipv4_addr_t extern "C" { // Interface for starting the broker bool MQTT_server_start(uint16_t portno, uint16_t max_subscriptions, uint16_t max_retained_topics); // Callbacks for message reception, username/password authentication, and client connection typedef void (*MqttDataCallback)(uint32_t args, const char topic, uint32_t topic_len, const char *data, uint32_t lengh); void MQTT_server_onData(MqttDataCallback dataCb); // Interface for local pub/sub interaction with the broker bool MQTT_local_publish(uint8_t* topic, uint8_t* data, uint16_t data_length, uint8_t qos, uint8_t retain); // Interface to cleanup after STA disconnect void MQTT_server_cleanupClientCons(); // Interface for persistence of retained topics void clear_retainedtopics(); // Interface for getting some infos on the currently connected clients uint16_t MQTT_server_countClientCon(); class uMQTTBroker
// Get access to last payload F.Dallo public:
// Callbacks on client actions
// Infos on currently connected clients
// Interaction with the local broker
// Get access to last payload F.Dallo // Cleanup all clients on Wifi connection loss
}; #endif /* MQTT_SERVER_H */ |
1 similar comment
#ifndef MQTT_SERVER_H #include "user_interface.h" #ifndef ipv4_addr_t extern "C" { // Interface for starting the broker bool MQTT_server_start(uint16_t portno, uint16_t max_subscriptions, uint16_t max_retained_topics); // Callbacks for message reception, username/password authentication, and client connection typedef void (*MqttDataCallback)(uint32_t args, const char topic, uint32_t topic_len, const char *data, uint32_t lengh); void MQTT_server_onData(MqttDataCallback dataCb); // Interface for local pub/sub interaction with the broker bool MQTT_local_publish(uint8_t* topic, uint8_t* data, uint16_t data_length, uint8_t qos, uint8_t retain); // Interface to cleanup after STA disconnect void MQTT_server_cleanupClientCons(); // Interface for persistence of retained topics void clear_retainedtopics(); // Interface for getting some infos on the currently connected clients uint16_t MQTT_server_countClientCon(); class uMQTTBroker
// Get access to last payload F.Dallo public:
// Callbacks on client actions
// Infos on currently connected clients
// Interaction with the local broker
// Get access to last payload F.Dallo // Cleanup all clients on Wifi connection loss
}; #endif /* MQTT_SERVER_H */ |
Then in the Arduino code setup: myBroker.subscribe("windsled/thespecifictopicofinterest"); and loop: // Process the last received payload |
Thank you for developing this library. I've been using it to program ESP8266 devices with ESPHome for sensor data collection (including temperature, relative humidity, and air quality) and to transmit the data as MQTT payloads to an ESP8266 MQTT broker that also serves as the WiFi access point. This setup works flawlessly. However, I am now looking to enhance it by processing and storing the incoming messages on an SD card. Indeed, while I can handle the data in Python on my ubuntu system by reading the messages (mosquito_sub) and storing them in a dataframe, I am also interested in implementing this functionality directly on the ESP8266, saving measurements in an SD card and eventually using the sd.h library which I've used in the past. This would involve accessing the payload and storing it as a character array within the loop function. Since I am not very familiar with C, I am uncertain whether a function already exists in your library that I could use for this purpose or if I need to modify the onData() function in the uMQTTBroker.cpp file(?). Any guidance or suggestions you can provide would be greatly appreciated. Thank you for your support and again, great library! Best regards.
The text was updated successfully, but these errors were encountered: