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