Last active
September 17, 2022 02:48
-
-
Save ariesmcrae/02ea18458cce91c2b658cf446c6aa15a to your computer and use it in GitHub Desktop.
M5Stack Core2 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 m5stack_ui import * | |
from uiflow import * | |
import time | |
import unit | |
from IoTcloud.AWS import AWS | |
import json | |
screen = M5Screen() | |
screen.clean_screen() | |
screen.set_screen_bg_color(0x000000) | |
environmentSensor = unit.get(unit.ENV3, unit.PORTA) | |
temperatureLabel = M5Label('Temp:', x=12, y=44, color=0xffffff, font=FONT_MONT_38, parent=None) | |
humidityLabel = M5Label('Hum:', x=27, y=133, color=0xffffff, font=FONT_MONT_38, parent=None) | |
temperatureLabel.set_text('Temp:') | |
humidityLabel.set_text('Hum:') | |
temperatureValue = M5Label('17', x=154, y=44, color=0x00ff5f, font=FONT_MONT_38, parent=None) | |
humidityValue = M5Label('49', x=154, y=133, color=0x24ff00, font=FONT_MONT_38, parent=None) | |
aws = AWS(things_name='masterbed_thing', host='XXXXXXXXXX-ats.iot.ap-southeast-2.amazonaws.com', port=8883, keepalive=60, cert_file_path="/flash/res/masterbed2-certificate.pem.crt", private_key_path="/flash/res/masterbed2-private.pem.key") | |
aws.start() | |
while True: | |
temperature = environmentSensor.temperature | |
humidity = environmentSensor.humidity | |
formattedTemperature = "{:.2f} C".format(temperature) | |
formattedHumidity = "{:.0f} %".format(humidity) | |
temperatureValue.set_text(formattedTemperature) | |
humidityValue.set_text(formattedHumidity) | |
aws.publish(str('masterbed'),str((json.dumps(({'temperature':(temperature),'humidity':(humidity)}))))) | |
wait(2) # seconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment