We have upgraded the community system as part of the upgrade a password reset is required for all users before login in.

Communication with AWS Server



  • I want to send date that I recived from a Oxygen sensor(SDS011) using serial port. I want to send this values to the Amazon server using MQTT. My main code is the next:

    print("Importing Library")
    import time
    import sys  
    import datetime
    import paho.mqtt.client as paho
    import ssl
    import os
    import json
    print("Importing Done")
    
    def on_connect(client, userdata, flags, rc):
    global connflag
    connflag = True
    if rc == 0:
    	print("Connected")
    else:
    print("Connection returned result: " + str(rc) )
    
    def on_message(client, userdata, msg):
    print(msg.topic+" "+str(msg.payload))
    
    mqttc = paho.Client("Omega-C11B")
    mqttc.on_connect = on_connect
    mqttc.on_message = on_message
    print("Paho Client Setup Done")
    
    awshost = "a3rzs5flqm8tjk-ats.iot.ap-south-1.amazonaws.com"
    awsport = 8883
    clientId = "Omega-C11B"
    thingName = "Omega-C11B"
    caPath = "/root/root-CA.crt"
    certPath = "/root/496d95a10e-certificate.pem.crt"
    keyPath = "/root/496d95a10e-private.pem.key"
    
    mqttc.tls_set(caPath, certfile=certPath, keyfile=keyPath, cert_reqs=ssl.CERT_REQUIRED, 
    tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
    print("TLS Established")
    mqttc.connect(awshost, awsport, keepalive=60)
    print("Server Connected")
    mqttc.loop_start()
    
    while True:
    humidity = 60 #Supposing Data
    temperature = 30  #Supposing Data
    t = time.time();
    date = datetime.datetime.fromtimestamp(t).strftime('%Y%m%d%H%M%S')
    mqttc.publish("$aws/things/Omega-CF2D/shadow/update/", json.dumps({"time": date, 
        "temperature": temperature, "humidity": humidity}), qos=1)
    time.sleep(10)
    

    In my console I get that the connection was sucefull, but when I see the AWS server, I can´t find the data. I don't know if it's due to a code problem or caPath Certificate, beacuse I don't know where I can find. So I get it forn this link link text. In my console I get :

    daa9d182-5496-4a1f-8a29-c41770d816dd-image.png

    I'm sending data with a time to 10seconds.



  • @Victor-Lucio Take a look at my response in this thread. Paho is not great at exposing errors if you don't use the callbacks.

    https://community.onion.io/topic/3691/omega2-aws-connect-error-ssl-certificate-verify-failed/7



  • @crispyoz Which others changes I need to do?
    Thanks for responding 😉

    f232b060-e23d-4971-9bf0-1653cc52c874-image.png

    Could you explain me, what de you tried to say in this " I would also implement the on_publish callback.

    ¿This? Sorry if my question it's basic- I´m new using this module and sendding data to AWS.
    def on_publish(client, userdata, mid):
    print("Message published: " + message)

    # message published, disconnect
    client.disconnect()
    

    client.on_publish = on_publish"



  • @Victor-Lucio your on_log should print the buffer, it has no parameter named msg. buffer should contain any errors or warnings.



Looks like your connection to Community was lost, please wait while we try to reconnect.