AWSIoTPythonSDK - OSError: [WinError 10038] An operation was attempted on something that is not a socket

0

Trying to connect to a IoT thing via code to simulate a device with Python. This code was working before and now I'm getting this error.

The code is straight forward.

import time as t
from datetime import datetime
import AWSIoTPythonSDK.MQTTLib as AWSIoTPyMQTT

def helloworld(self, params, packet):
    print(packet.payload)


myCLIENT = AWSIoTPyMQTT.AWSIoTMQTTClient('test_thing')
myCLIENT.configureEndpoint('myEndPoint', 8883)
myCLIENT.configureCredentials("Path to AmazonRootCA1.pem", "Path to private.pem.key", "Path to certificate.pem.crt")

myCLIENT.configureOfflinePublishQueueing(-1)  # Infinite offline Publish queueing
myCLIENT.configureDrainingFrequency(2)  # Draining: 2 Hz
myCLIENT.configureConnectDisconnectTimeout(10)  # 10 sec
myCLIENT.configureMQTTOperationTimeout(5)  # 5 sec

print('Connecting...')
myCLIENT.connect()
print('Connected')


def loop():
    temperature = 20
    humidity = 67

    while True:
        curr_dt = datetime.now()
        myCLIENT.publish(
            topic='test_thing/test',
            payload='{"timestamp": ' + str(int(round(curr_dt.timestamp()))) + ', "temperature": ' + str(temperature) + ', "humidity":' + str(humidity)+', "project_id": 1}',
            QoS=1)
        if temperature < 25:
            temperature += 0.01
            humidity += 0.005
        else:
            temperature -= 0.01
            humidity -= 0.005
        t.sleep(1)


if __name__ == '__main__':
    try:
        loop()
    except KeyboardInterrupt:
        myCLIENT.disconnect()

And I'm getting this error when trying to connect

test_thing.py:24: in <module>
    myCLIENT.connect()
..\..\Anaconda3\lib\site-packages\AWSIoTPythonSDK\MQTTLib.py:355: in connect
    return self._mqttCore.connect(keepAliveIntervalSecond)
..\..\Anaconda3\lib\site-packages\AWSIoTPythonSDK\core\protocol\mqttCore.py:282: in connect
    self._pahoClient.connect(self._host, self._port, keepAliveInterval)  # Throw exception...
..\..\Anaconda3\lib\site-packages\AWSIoTPythonSDK\core\protocol\paho\client.py:655: in connect
    return self.reconnect()
..\..\Anaconda3\lib\site-packages\AWSIoTPythonSDK\core\protocol\paho\client.py:807: in reconnect
    self._sock.setblocking(0)
E   OSError: [WinError 10038] An operation was attempted on something that is not a socket

Any ideas where the problem might be?

posta un anno fa61 visualizzazioni
Nessuna risposta

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande