AWS iot socket create error: -8567



  • I have tried to connect my LoPy to AWS IoT follow this tutorial https://docs.pycom.io/chapter/tutorials/all/aws.html.

    The main.py I did not change and this is part of my config.py coding.

     # AWS general configuration
    AWS_PORT = 8883
    #AWS_HOST = 'aws_host_url'
    AWS_HOST = 'a2ny4s7pewp2cl.iot.ap-southeast-1.amazonaws.com'
    AWS_ROOT_CA = '/flash/cert/VeriSign-Class 3-Public-Primary-Certification-Authority-G5.pem'
    AWS_CLIENT_CERT = '/flash/cert/4aecbe1ac8-public.pem.key'
    AWS_PRIVATE_KEY = '/flash/cert/4aecbe1ac8-private.pem.key'
    
    ################## Subscribe / Publish client #################
    #CLIENT_ID = 'PycomPublishClient'
    CLIENT_ID = 'iotconsole-15215624106470-2'
    TOPIC = 'PublishTopic'
    OFFLINE_QUEUE_SIZE = -1
    DRAINING_FREQ = 2
    CONN_DISCONN_TIMEOUT = 10
    MQTT_OPER_TIMEOUT = 5
    LAST_WILL_TOPIC = 'PublishTopic'
    LAST_WILL_MSG = 'To All: Last will message'
    

    Below is the error i got. I have opened the port 8883

    alt text

    if I leave it, after few minutes it will become

    alt text

    Any idea what these errors mean? Thanks.



  • Hello,

    I bumped on this very same issue when executing the below (partial) code. The socket create error -8576 showed up upon every attempt of executing the loop:

    while not pycomAwsMQTTClient.connect():
        print("Waiting for AWS...")
        time.sleep(10)
    print('AWS connection succeeded!')
    

    Have found that the problem was on the root CA certificate. Just to recap, AWS "setup.py" file expects to work with three certificates as follows:

    AWS_ROOT_CA = "/flash/cert/root-CA.crt"
    AWS_CLIENT_CERT = "/flash/cert/thing.cert.pem"
    AWS_PRIVATE_KEY = "/flash/cert/thing.private.key"
    

    For some reason the root certificate was not created correctly upon instructions from AWS tutorials. To fix that, run the below command line on a Linux Terminal to download it again:

    curl https://www.amazontrust.com/repository/AmazonRootCA1.pem > root-CA.crt
    

    By doing so, my issue was fixed.



  • @timh hello timh. sorry for late reply. I didn't try using window to connect to aws iot because it seems complicated and difficult to me. However, I tried ubidots and adafruit mqtt. both work. :D



  • @timh thanks Timh for your suggestion. I don't have raspberrypi but I will try windows and let you know how it goes. Thanks a lot!



  • @vicky_ Do you have another platform from python (raspberrypi or windows) where you can check that you can connect to AWS IOT via mqtt using the same certs, hosts etc....

    The process is pretty much identical on any other python platform. https://github.com/aws/aws-iot-device-sdk-python

    If you can then you know you have your config correct. both locally and on AWS.

    I am connecting using MQTT over WIFI and LTE CAT-M1 to Losant successfully. But I am only using a ROOT_CA.



  • @timh yes, my home wifi, I also used my phone as Hotspot. both also give the same result. yes is working as you can see in the console the first line is 'WLAN connection succeded!" I also cant find out what -8567 is.



  • @vicky_ Oh. What is your network connection ? WIFI ?



  • @vicky_ Oh, if you haven't been able to publish, it means your connection isn't succeeding.

    It does retry for some time, hence the wait.

    I take it you have got a working network connection ?

    Not sure what -8567 is. Need to look at where in the socket lib that is coming from.



  • @timh Hi Timh. How can I reduce the keep alive interval? Reduce the loopcount in main.py or draining_Freq/ Conn_disconn_timeout/ Mqtt_oper_timeout in config.py? No, never publish any data to AWS successfully before. :(



  • @vicky_ Hi Vicky socket errors generally mean the connection to AWS has failed. . You could try reconnecting , or reducing the keep alive interval. Once you perform the initial connect have you been able to publish any data to AWS successfully



  • @timh thanks for your quick response! However, I am new to micropython, iot and LoRa, cant fully understand what you mean. Is there another way you can suggest me to connect my LoPy to the internet? I tried LoRaWAN nanogateway but the OTAA/ABP node script doesn't work for my region. Thanks :)



  • @vicky_ I have been playing with the core of this lib to talk to Losant.

    I found a few things that seem to have a problem. Firstly the msgHandler has no connect method (which is called when it tries to reconnect in verify_connection method).

    It also seems that if you disconnect the thread is still running trying to send keepalive packets. I had to make some changes so that if service is disconnected explicitly , that the thread exits, and then when you explicitly connect it recreates the thread. I am sure there are a few other corner cases in their in the event of disconnect.

    I am not really sure what the best way to re-structure the code at the moment so haven't suggested anything as yet.


Log in to reply
 

Pycom on Twitter