Initiating connection to AWS
- 
					
					
					
					
 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: I am using an ATOM Lite and UIFlow 1.11.3 I hope you guys can help me With kind regards, 
 TD
- 
					
					
					
					
 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? 
- 
					
					
					
					
 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?
- 
					
					
					
					
 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()
 passimport 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
- 
					
					
					
					
 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
- 
					
					
					
					
 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 whileWere did you read that the connection wasnt established? 
- 
					
					
					
					
 Combination of error 09 (authentication acknowledgment error) and OS error shown in the command terminal 
