Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. bmtd111
    3. Topics
    B
    • Continue chat with bmtd111
    • Start new chat with bmtd111
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups

    Topics created by bmtd111

    • B

      Initiating connection to AWS
      UIFlow • • bmtd111

      4
      0
      Votes
      4
      Posts
      143
      Views

      B

      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('BesserMITTAG-IOT', "Zsip-uwYpDe'") 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
    • B

      How can an atom lite listen forever to a mqtt topic?
      UIFlow • • bmtd111

      2
      0
      Votes
      2
      Posts
      155
      Views

      B

      On a side-note, this is the programm im running on a seperate atom lite using the same UIFlow version. It just sends a request every once in a while. My code: May be somebody has some thoughts for this as well. Kind regards TD
    • B

      Possible Problems with MQTT?
      UIFlow • • bmtd111

      6
      0
      Votes
      6
      Posts
      962
      Views

      If the Atom is not connected to the host computer as it is when testing, you will need to add the WIFI AP and Password blocks to the start of the program.