aws / aws-iot-device-sdk-python

SDK for connecting to AWS IoT from a device using Python.
Apache License 2.0
683 stars 426 forks source link

Automated start of basicPubSub.py example not working #304

Closed gamename closed 2 years ago

gamename commented 2 years ago

Hi,

I am able to start basicPubSub.py from the command line without any problems. But what I want to do is have it invoked at bootup. So, I added the invocation to /etc/rc.local like this:

sudo su tennis -c "python ~/aws-iot-device-sdk-python/samples/basicPubSub/basicPubSub.py -e ~/a3u37c52vq0b6j-ats.iot.us-east-1.amazonaws.com -r ~/root-CA.crt -c ~/garage-bot.cert.pem -k ~/garage-bot.private.key > /tmp/start.log 2>&1"

Now, I'm getting this error message on startup:

2022-02-26 07:36:40,599 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Initializing MQTT layer...
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Registering internal event callbacks to MQTT layer...
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - MqttCore initialized
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Client id: basicPubSub
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Protocol version: MQTTv3.1.1
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Authentication type: TLSv1.2 certificate based Mutual Auth.
2022-02-26 07:36:40,600 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring endpoint...
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring certificates...
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring reconnect back off timing...
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Base quiet time: 1.000000 sec
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Max quiet time: 32.000000 sec
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Stable connection time: 20.000000 sec
2022-02-26 07:36:40,601 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queueing: max queue size: -1
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queue draining interval: 0.500000 sec
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring connect/disconnect time out: 10.000000 sec
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring MQTT operation time out: 5.000000 sec
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync connect...
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing async connect...
2022-02-26 07:36:40,602 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Keep-alive: 600.000000 sec
2022-02-26 07:36:40,603 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event consuming thread started
2022-02-26 07:36:40,603 - AWSIoTPythonSDK.core.protocol.mqtt_core - DEBUG - Passing in general notification callbacks to internal client...
2022-02-26 07:36:40,603 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in fixed event callbacks: CONNACK, DISCONNECT, MESSAGE
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Cleaning up before stopping event consuming
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event queue cleared
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Stopping network I/O thread...
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Network thread stopped
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event callbacks cleared
2022-02-26 07:36:40,608 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event consuming thread stopped
2022-02-26 07:36:40,609 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Waiting for event consumer to completely stop
2022-02-26 07:36:40,613 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Exiting dispatching loop...
2022-02-26 07:36:40,613 - AWSIoTPythonSDK.core.protocol.mqtt_core - DEBUG - Event consumer stopped
Traceback (most recent call last):
  File "/home/tennis/aws-iot-device-sdk-python/samples/basicPubSub/basicPubSub.py", line 107, in <module>
    myAWSIoTMQTTClient.connect()
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/MQTTLib.py", line 513, in connect
    return self._mqtt_core.connect(keepAliveIntervalSecond)
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 196, in connect
    self.connect_async(keep_alive_sec, self._create_blocking_ack_callback(event))
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 223, in connect_async
    raise e
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/mqtt_core.py", line 211, in connect_async
    rc = self._internal_async_client.connect(keep_alive_sec, ack_callback)
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/internal/clients.py", line 122, in connect
    rc = self._paho_client.connect(host, port, keep_alive_sec)
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 665, in connect
    return self.reconnect()
  File "/home/tennis/.local/lib/python3.9/site-packages/AWSIoTPythonSDK/core/protocol/paho/client.py", line 789, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.9/socket.py", line 822, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.9/socket.py", line 953, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

Any ideas? My OS is Raspian.

Thanks, -T

gamename commented 2 years ago

nvm! I found the problem. :)

github-actions[bot] commented 2 years ago

⚠️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.