aws / amazon-freertos

DEPRECATED - See README.md
https://aws.amazon.com/freertos/
MIT License
2.54k stars 1.1k forks source link

Publish MQTT messages to AWS IoT Core using the Greengrass Discovery library. #2119

Closed BasemTarek closed 4 years ago

BasemTarek commented 4 years ago

I am using ESP-32 as my FreeRTOS device, and Raspberry Pi3 as my Greengrass Core device.

And I am trying to publish MQTT messages to Greengrass core device then to AWS IoT Core, so I used the Greengrass Discovery library to discover the Greengrass Core device and the discovery process was done successfully, but when the code reach the part of publishing the message, errors appeared.


I am using this project (https://github.com/teuteuguy/amazon-freertos-workshop) to develop my application. And we edited the _establishMqttConnection() and lab_run() functions in the lab_connection.c file to be able to discover the Greengrass Core device and to publish my messages to my topic.

Then, the Greengrass device was discovered successfully, but no messages were received and the following errors appeared:

54 8555 [iot_thread] [ERROR][NET][85550] Error -27648 while sending data. 55 8555 [iot_thread] [ERROR][MQTT][85550] (MQTT connection 0x3ffb5f44) Failed to send PINGREQ. 56 8555 [iot_thread] [WARN ][NET][85550] Failed to close connection.

And to make sure that there is no problem with the Greengrass Core device itself, I tried to run AWS IoT Greengrass discovery demo application on my FreeRTOS device (ESP-32), and it worked successfully.

I expected to receive a message when I subscribed to the configured topic, but this error Failed to send PINGREQ appeared and no message was received.

Thank you!

dachalco commented 4 years ago

Hello @BasemTarek,

I'm unfamiliar with the Lab_1 project you've baselined, though from what I've read thus far, it appears that application uses FreeRTOS to implement a button, and publishes the state of the button to IoT Core. To double-check, this application worked as intended?

Secondly, you were able to run the GreenGrass discovery demo successfully?

It's a good sign if both apps worked as it confirms your hardware, the app, and the demo can implement individual components of interest, and now it's just a matter of correctly splicing these components to a single app.

At a high-level, that suggests there's likely missing code to get the GreenGrass interface working with your Lab_1 application -- code that is present in the working GreenGrass Discovery Demo.

At a low-level, I see that the PINGREQ error report likely comes from this code. You could put a breakpoint at the ->send function, and dive deeper into the stack to collect more details i.e. breadcrumbs that could lead us to the root cause. The PINGREQ is used in the linked code to send keepalives. There are several ways a send could fail, so more details can help limit the suspects.

BasemTarek commented 4 years ago

Thank you @dachalco, your comment helped me but I didn't catch the root cause yet, also there are an error message 54 8555 [iot_thread] [ERROR][NET][85550] Error -27648 while sending data. which precedes PINGREQ error, I found that this error comes from this IotNetworkAfr_Send(), so I am trying to catch the cause of this error.

I found that these two errors may be related to each other, because this ->send actually is a call to this IotNetworkAfr_Send().

Also if you check the attached logs file, there is an info message I (85847) lab_connection: LABCONNECTION_MQTT_DISCONNECTED inform that the MQTT connection disconnected which precedes all the error messages, I had tried to find the cause of this "disconnecting action", it is likely that this disconnecting action might be the reason of the mentioned errors..! Still don't know the cause of this disconnecting action.

muneebahmed10 commented 4 years ago

Hi @BasemTarek,

I notice that your logs indicate that the connection to your Greengrass Core was successful. Also, the failure happens when trying to send a keep alive PINGREQ, which would happen after the expiry of the 60 second keep alive interval. If no MQTT packet is being sent for 60 seconds, is your application getting stuck somewhere?

Additionally, I'd suggest enabling debug logs, and either running the mqtt demo, or replacing the Greengrass endpoint and cert in your code with that of the AWS IoT broker, in order to determine if the issue lies with the use of Greengrass discovery, or elsewhere.

BasemTarek commented 4 years ago

Thank you @muneebahmed10,

is your application getting stuck somewhere?

sure it stuck somewhere, can you help on that..!?

running the mqtt demo, or replacing the Greengrass endpoint and cert in your code with that of the AWS IoT broker, in order to determine if the issue lies with the use of Greengrass discovery, or elsewhere.

I don't know how this will be helpful, the Greengrass demo worked successfully, and the mqtt demo worked successfully, but separately.

BasemTarek commented 4 years ago

Are there any updates..

muneebahmed10 commented 4 years ago

Hi @BasemTarek ,

If the MQTT and Greengrass discovery demos are each working successfully for you, then I only have enough information to offer suggestions in debugging the errors you're encountering in your implementation.

Have you stepped through the code in a debugger, and found anywhere it's getting stuck? Could your code be waiting on a mutex or semaphore that isn't being incremented? I notice that after you call MQTT's publish, your code waits on a clean up semaphore, that only gets posted to when there's a LABCONNECTION_MQTT_DISCONNECTED event. Could your application be stuck there?

leegeth commented 4 years ago

@BasemTarek ,

Did you get a chance to follow the steps mentioned in the above comment? Please let us know if there are any updates and if you need any further assistance on this issue.

yanjos-dev commented 4 years ago

@BasemTarek This topic has become inactive so I'm going to close the issue. Please reopen this if you have any questions or need any further assistance.