Using MQTT publish and subscribe in offline mode between devices connected to Greengrass core
nabeel-nasir opened this issue · 6 comments
I followed the Module 4 tutorial on Interacting with devices in an AWS IoT Greengrass group. I have a Raspberry Pi running the AWS IoT Greengrass Core. I have a group consisting of the core and the two devices (HelloWorld_Publisher, HelloWorld_Subscriber). The subscription rule is setup as mentioned in the tutorial. I have a laptop and the Raspberry Pi on the same local network. I fire up both the HelloWorld_Publisher and HelloWorld_Subscriber on my laptop using the basicPubSub.py sample. I am able to send and receive messages successfully.
Now, during the send, I cut off the Internet connection from my router to test offline connectivity. So the Internet is down but the local network is still working (I can ping from my laptop to the RPi). However, this makes the HelloWorld_Publisher crash with the following exception:
2020-09-02 23:15:33,683 - AWSIoTPythonSDK.core.protocol.mqtt_core - ERROR - Publish timed out
Traceback (most recent call last):
File "basicPubSub.py", line 120, in <module>
myAWSIoTMQTTClient.publish(topic, messageJson, 1)
File "/usr/local/lib/python2.7/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 628, in publish
return self._mqtt_core.publish(topic, payload, QoS, False) # Disable retain for publish by now
File "/usr/local/lib/python2.7/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 273, in publish
raise publishTimeoutException()
AWSIoTPythonSDK.exception.AWSIoTExceptions.publishTimeoutException
Why does this happen if the MQTT broker is running on the Greengrass Core on the RPi? Why is there a need for an Internet connection?
Is there some flag or something I can set to continue MQTT publish and subscribe in an offline mode?
In theory, your local-to-local connections shouldn't fail when you unplug your router from the wall. I've been meaning to get a GG core set up going locally for issue reproduction so I'm going to try and check this today. I assume that an SSH connection from the laptop to the Pi survived the disconnect just fine?
That's what I was also expecting that the local connections wouldn't fail.
Yes, the SSH connection did stay alive.
Oh wait, I just realized the issue. You linked the basic pub sub example (which sadly is also what the greengrass tutorial references by name) but that connects to IoT Core only. If you use the greengrass sample (https://github.com/aws/aws-iot-device-sdk-python/blob/master/samples/greengrass/basicDiscovery.py), that will use discovery to find and connect to your core and then do the pub/sub behaviors against the greengrass core and not IoT core. Your mqtt connections were remote and that's why they probably died the second you disconnected your router.
I've submitted an inaccurate documentation ticket for those two sections, hopefully that will get them fixed.
That makes sense. I will try it out with the other sample and check what the behavior is. Thank you for looking into this!
⚠️ COMMENT VISIBILITY WARNING⚠️
Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.