Trouble Running BasicPubSub on Startup

0

Hi,

I am trying to run the sample script basicPubSub.py. It runs fine if I start it manually from the command line.

But I want it to run continuously starting from boot time. When I put it in /etc/rc.local and reboot, I get the following error (below).

Has anyone seen this before? Also, is this the best way to run pub/sub so that it automatically starts when the system boots?

Thanks, -T

2022-02-25 10:53:31,550 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Initializing MQTT layer...
2022-02-25 10:53:31,551 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Registering internal event callbacks to MQTT layer...
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - MqttCore initialized
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Client id: basicPubSub
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Protocol version: MQTTv3.1.1
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Authentication type: TLSv1.2 certificate based Mutual Auth.
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring endpoint...
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring certificates...
2022-02-25 10:53:31,552 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring reconnect back off timing...
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Base quiet time: 1.000000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Max quiet time: 32.000000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Stable connection time: 20.000000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queueing: max queue size: -1
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring offline requests queue draining interval: 0.500000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring connect/disconnect time out: 10.000000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Configuring MQTT operation time out: 5.000000 sec
2022-02-25 10:53:31,553 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing sync connect...
2022-02-25 10:53:31,554 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Performing async connect...
2022-02-25 10:53:31,554 - AWSIoTPythonSDK.core.protocol.mqtt_core - INFO - Keep-alive: 600.000000 sec
2022-02-25 10:53:31,554 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event consuming thread started
2022-02-25 10:53:31,555 - AWSIoTPythonSDK.core.protocol.mqtt_core - DEBUG - Passing in general notification callbacks to internal client...
2022-02-25 10:53:31,555 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Filling in fixed event callbacks: CONNACK, DISCONNECT, MESSAGE
2022-02-25 10:53:31,559 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Cleaning up before stopping event consuming
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event queue cleared
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.clients - DEBUG - Stopping network I/O thread...
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Network thread stopped
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event callbacks cleared
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Event consuming thread stopped
2022-02-25 10:53:31,560 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Waiting for event consumer to completely stop
2022-02-25 10:53:31,564 - AWSIoTPythonSDK.core.protocol.internal.workers - DEBUG - Exiting dispatching loop...
2022-02-25 10:53:31,565 - 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
asked 2 years ago284 views
1 Answer
0

Just to be sure, are you running this script? It is adviced to use AWS IoT Python v2 SDK

Regarding how to run it at boot time, it depends on your operating system. If your OS supports systemd, you should use it, and register your script to run as a system service.

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions