Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 2 months ago.
MQTT async implementation
Hi all,
I'm trying to get the async version of MQTT to run but fail with the implementation of the callbacks. What I did so far is creating a header for my application with:
CommunicationManager.h
#define MQTTCLIENT_QOS2 1 #include "mbed.h" #include "rtos.h" #include "ModemManager.h" #include "MQTTAsync.h" #define MQTTMGR_SERVERNAME "test.domain" #define MQTTMGR_SERVERPORT 1883 #define MQTTMGR_CLIENTID "user_001" #define MQTTMGR_USERNAME "user_001" #define MQTTMGR_PASSWORD "test1234" class CommunicationManager { public: CommunicationManager(); void run(); private: MQTT::Async<ModemManager, Countdown, Thread, Mutex>* mqttClient; }; void resultHandler(MQTT::Result*);
Then I implemnt this as follows:
CommunicationManager.cpp
#include "CommunicationManager.h" CommunicationManager::CommunicationManager() { } void CommunicationManager::run() { // Connect to MQTT Broker MQTTPacket_connectData connData = MQTTPacket_connectData_initializer; connData.MQTTVersion = 3; // Version 3 = MQTT version 3.1 connData.clientID.cstring = MQTTMGR_CLIENTID; connData.username.cstring = MQTTMGR_USERNAME; connData.password.cstring = MQTTMGR_PASSWORD; connData.keepAliveInterval = 120; connData.cleansession = 0; ret = connect(resultHandler, connData); while (true){ // TO IMPLEMENT } } void resultHandler(MQTT::Result* res) { // TO IMPLEMENT }
Whit this code I get the following compile errors:
- Incomplete type is not allowed "void resultHandler(MQTT::Result*);"
- Namespace "MQTT" has no member "Result" "void resultHandler(MQTT::Result*)"
- Expected an expression "void resultHandler(MQTT::Result*)"
Any ideas on how to correctly implement the async MQTT version are appreciated! Christoph
I figured it out in the meantime andit seems to work: