Hi!
General premises:
I’m programming an Espressif microcontroller, the esp32-wroom-32, and I’ve followed the getting started guide (https://docs.aws.amazon.com/it_it/freertos/latest/userguide/getting_started_espressif.html) and downloaded the amazon-freertos directory with all the demos and specific vendors folders.
I’ve tested the MQTT, HTTPS Upload Async and HTTPS Download Async demos succesfully. But I need my own demo, so I’ve created a “my_demo” folder inside “demos” folder where I’ve put my file “iot_my_demo.c”, mantaining the structure of the directories. In this file I have the demo entry function “RunMyDemo” called by “iot_demo_freertos.c”, where I have a state machine to handle a Uart communication with another host. I’ve tried to copy all the demo entry function of MQTT and HTTPS demos (RunMqttDemo, RunHttpsAsyncUploadDemo, RunHttpsAsyncDownloadDemo) and call them in some states of my state machine and it works. I’m able, on commands arriving from Uart, to publish data into topics and to download or upload towards Amazon S3. So I succeeded to replicate the behavior of the demos merging them into a single file.
Note: with my state machine I connect to Wi-Fi only once and I reuse the same Network information for all demos function (MQTT, HTTPS).
I have 1 issue:
It is related to topic subscription callback; the MQTT demo code establishes the MQTT connection, subscribes into topics, publishes into the same topics and waits for incoming publish messages, as it knows the number of messages published it waits to receive all messages and finally the demo disconnects the MQTT connection. With the demo code I’m able to see the subscription callback call when it publishes into topics (I see on serial debug some IotLogInfo, for example the payload of the publish message received…).
But then I’ve tried to separate the MQTT connection, disconnection, publish, subscribe, desubscribe, making functions for each of them and a single global variable “IotMqttConnection_t mqttConnectionHandle = IOT_MQTT_CONNECTION_INITIALIZER;” to handle the MQTT connection.
With this approach I’ve succesfully tried (on commands from Uart) to connect to MQTT broker, to publish into topic (seeing the messages from the IoT Core console), to sub or desub to topics and to disconnect from MQTT broker when I want. But when I succesfully subscribe to a topic, calling the “_modifySubscriptions” function I add the “_mqttSubscriptionCallback” to the “IotMqttSubscription_t pSubscriptions[ TOPIC_FILTER_COUNT ] = { IOT_MQTT_SUBSCRIPTION_INITIALIZER };” with “pSubscriptions[ i ].callback.function = _mqttSubscriptionCallback;” and “pSubscriptions[ i ].callback.pCallbackContext = pCallbackParameter;”.
But the callback seems that is never invoked. In effect I succesfully subscribe to a topic (“test/w-block-interation”), but trying to publish to the same topic from the MQTT client provided by AWS IoT Core console, I never see some response on my monitor serial debug, as I saw trying the demo code with some print about the incoming publish messages.
In the following image I’ve reported my “_modifySubscriptions” initial code.
Thanks in advance for your attention.