Last active
September 18, 2022 12:21
-
-
Save ariesmcrae/fa2ef111a0f4b4fa527c82698844475e to your computer and use it in GitHub Desktop.
M5Stack M5StickC-PLUS ESP32 Python. Pumps temperature/humidity data regularly to AWS Core IoT MQTT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from m5stack import * | |
from m5ui import* | |
from uiflow import * | |
import time | |
import unit | |
from IoTcloud.AWS import AWS | |
import json | |
setScreenColor(0x111111) | |
environmentSensor = unit.get(unit.ENV3, unit.PORTA) | |
temperatureValue = M5TextBox(8, 20, "10", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0) | |
humidityValue = M5TextBox(8, 157, "50", lcd.FONT_DejaVu72, 0xFFFFFF, rotate=0) | |
temperatureLabel = M5TextBox(115, 192, "%", lcd.FONT_Default, 0xFFFFFF, rotate=0) | |
humidityLabel = M5TextBox(118, 61, "C", lcd.FONT_Default, 0xFFFFFF, rotate=0) | |
temperture = None | |
humidity = None | |
aws = AWS(things_name="bed_downstairs_thing", host="XXXXXXXXXX-ats.iot.ap-southeast-2.amazonaws.com", port=8883, keepalive=60, cert_file_path="/flash/res/c.pem.crt", private_key_path="/flash/res/p.pem.key") | |
aws.start() | |
while True: | |
temperature = "{:.0f}".format(environmentSensor.temperature) | |
humidity = "{:.0f}".format(environmentSensor.humidity) | |
temperatureValue.setText(temperature) | |
humidityValue.setText(humidity) | |
temperatureLabel.setText("C") | |
humidityLabel.setText("%") | |
aws.publish(str("downstairs/bed1/1A2B345C"),str((json.dumps(({"temperature":(temperature),"humidity":(humidity)}))))) | |
wait(10) # seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment