🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Initiating connection to AWS

    UIFlow
    2
    7
    5.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bmtd111
      last edited by

      Dear People
      I am currently working on a System that needs to connect to AWS. Sadly i get the following Error messages when I Execute my code: 0_1679405029035_Support.PNG

      I am using an ATOM Lite and UIFlow 1.11.3

      I hope you guys can help me

      With kind regards,
      TD

      1 Reply Last reply Reply Quote 0
      • B
        bmtd111
        last edited by

        Line 51 in my code is just aws.start() and it seems to call functions in the libraries. Maybe there is a bug in IoTCloud/AWS.py?

        1 Reply Last reply Reply Quote 0
        • ajb2k3A
          ajb2k3
          last edited by

          Please post all the python code.
          errors don't always apply to a specific line and also don't count empty lines.
          IIRC (and there's a possibility I don't as it was last year) have you set up the digital twin and permissions on AWS for the code to connect?

          UIFlow, so easy an adult can learn it!
          If I don't know it, be patient!
          I've ether not learned it or am too drunk to remember it!
          Author of the WIP UIFlow Handbook!
          M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

          1 Reply Last reply Reply Quote 0
          • B
            bmtd111
            last edited by ajb2k3

            Thank you for your reply!

            Here is my Pythoncode:

            from m5stack import *
            from m5ui import *
            from uiflow import *
            import machine
            import wifiCfg
            from IoTcloud.AWS import AWS
            import ntptime
            import json
            PingCounter = None
            ThingsName = None
            currentDoorState = None
            lastDoorState = None
            from numbers import Number

            @timerSch.event('AWSTimer')
            def tAWSTimer():
            global PingCounter, ThingsName, currentDoorState, lastDoorState, pin1
            if wifiCfg.wlan_sta.isconnected():
            PingCounter = (PingCounter if isinstance(PingCounter, Number) else 0) + 1
            aws.publish(str('DoorState/ping'),str((json.dumps(({'time':(ntp.formatDatetime('-', ':')),'ping':PingCounter,'reconnect':False})))))
            else:
            wifiCfg.doConnect('BesserMITTAG-IOT', "Zsip-uwYpDe'")
            PingCounter = (PingCounter if isinstance(PingCounter, Number) else 0) + 1
            aws.publish(str('DoorState/ping'),str((json.dumps(({'ping':PingCounter,'time':(ntp.formatDatetime('-', ':')),'reconnect':True})))))
            pass

            @timerSch.event('restartTimer')
            def trestartTimer():
            global PingCounter, ThingsName, currentDoorState, lastDoorState, pin1
            machine.reset()
            pass

            import gc
            wifiCfg.doConnect('blank', "blank'")
            ntp = ntptime.client(host='de.pool.ntp.org', timezone=1)
            timerSch.run('restartTimer', 10800000, 0x00)
            PingCounter = 0
            ThingsName = 'D30002'
            aws = AWS(things_name=ThingsName, host='hostName', port=8883, keepalive=1000, cert_file_path="/flash/res/certificate.pem.crt", private_key_path="/flash/res/private.pem.key")
            aws.start()
            gc.collect()
            aws.publish(str('DoorState/connect'),str((json.dumps(({'connect':'request'})))))
            timerSch.run('AWSTimer', 900000, 0x00)
            pin1 = machine.Pin(26, mode=machine.Pin.IN, pull=machine.Pin.PULL_UP)
            currentDoorState = pin1.value()
            while True:
            lastDoorState = currentDoorState
            currentDoorState = pin1.value()
            if lastDoorState == 1 and currentDoorState == 0:
            rgb.setColorAll(0x33cc00)
            aws.publish(str('DoorState/test'),str((json.dumps(({'open':(ntp.formatDatetime('-', ':')),'Message':'15','TopicArn':'arn:aws:sns:eu-central-1:684143602652:L-from-device','MessageAttributes':({'DataType':'String','StringValue':'door-opened'}),'DeviceID':({'DataType':'String','StringValue':'A1005'})})))))
            elif lastDoorState == 0 and currentDoorState == 1:
            rgb.setColorAll(0xff0000)
            aws.publish(str('DoorState/test'),str((json.dumps(({'close':(ntp.formatDatetime('-', ':')),'Message':'16','TopicArn':'arn:aws:sns:eu-central-1:684143602652:L-from-device','MessageAttributes':({'DataType':'String','StringValue':'door-closed'}),'DeviceID':({'DataType':'String','StringValue':'A1005'})})))))
            wait_ms(2)

            I have set everything up in AWS, the connection was already established and worked fine.
            Do you mean a device shadow with digital twin? I dont see how that could resolve the issue.

            With kind regards,
            TD

            1 Reply Last reply Reply Quote 0
            • ajb2k3A
              ajb2k3
              last edited by

              If I read correctly it means that the MQTT connection to AWS wasn't acknowledge which meant permission was refused.
              Have you restarted the ATOM or has AWS changed anything?
              Sorry, I haven't used AWS in a while

              UIFlow, so easy an adult can learn it!
              If I don't know it, be patient!
              I've ether not learned it or am too drunk to remember it!
              Author of the WIP UIFlow Handbook!
              M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

              1 Reply Last reply Reply Quote 0
              • B
                bmtd111
                last edited by

                I tried restarting it, that didnt change anything.

                @ajb2k3 said in Initiating connection to AWS:

                If I read correctly it means that the MQTT connection to AWS wasn't acknowledge which meant permission was refused.
                Have you restarted the ATOM or has AWS changed anything?
                Sorry, I haven't used AWS in a while

                Were did you read that the connection wasnt established?

                1 Reply Last reply Reply Quote 0
                • ajb2k3A
                  ajb2k3
                  last edited by

                  Combination of error 09 (authentication acknowledgment error) and OS error shown in the command terminal

                  UIFlow, so easy an adult can learn it!
                  If I don't know it, be patient!
                  I've ether not learned it or am too drunk to remember it!
                  Author of the WIP UIFlow Handbook!
                  M5Black, Go, Stick, Core2, and so much more it cant be fit in here!

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post