from m5stack import *
from m5ui import *
from uiflow import *
import wifiCfg
from m5mqtt import M5mqtt
import json
import time
import unit
setScreenColor(0x000000)
earth_4 = unit.get(unit.EARTH, unit.PORTB)
env3_3 = unit.get(unit.ENV3, unit.PAHUB1)
pbhub_2 = unit.get(unit.PBHUB, unit.PAHUB0)
wifiCfg.doConnect('Ok noted with thanks', 'password124')
Light = M5TextBox(163, 27, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Humidity = M5TextBox(163, 128, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Moisture = M5TextBox(163, 76, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label3 = M5TextBox(17, 28, "Light", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label4 = M5TextBox(17, 76, "Moisture", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label5 = M5TextBox(15, 128, "Humidity", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label6 = M5TextBox(15, 177, "Temperature", lcd.FONT_Default, 0xFFFFFF, rotate=0)
Temp = M5TextBox(155, 177, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
label8 = M5TextBox(49, 218, "STOP", lcd.FONT_Default, 0xFFFFFF, rotate=0)
if wifiCfg.wlan_sta.isconnected():
m5mqtt = M5mqtt('f55f2957-ce72-4a2a-b9e4-00bc501a2f4e', 'broker.qubitro.com', 1883, 'f55f2957-ce72-4a2a-b9e4-00bc501a2f4e', '173943995150490178251d255b10320f0511a9dc23200534e765f3276794bcc682371cefb18ff4675205b0915ad9a2e76a3', 300)
m5mqtt.start()
while True:
if (env3_3.temperature) > 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water the plant')
Light.setText('Light has issue')
Humidity.setText('On Humidifier')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water the plant')
Light.setText('Light is stable')
Humidity.setText('On Humidifier')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water level stable')
Light.setText('Light has issue')
Humidity.setText('On Humidifier')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water level stable')
Light.setText('Light is stable')
Humidity.setText('On Humidifier')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water the plant')
Light.setText('Light has issue')
Humidity.setText('Humidity level stable')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water the plant')
Light.setText('Light is stable')
Humidity.setText('Humidity level stable')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water level stable')
Light.setText('Light has issue')
Humidity.setText('Humidity level stable')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) > 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water level stable')
Light.setText('Light is stable')
Humidity.setText('Humidity level stable')
Temp.setText('On Aircon')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water the plant')
Light.setText('Light has issue')
Humidity.setText('On Humidifier')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water the plant')
Light.setText('Light is stable')
Humidity.setText('On Humidifier')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water level stable')
Light.setText('Light has issue')
Humidity.setText('On Humidifier')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) < 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water level stable')
Light.setText('Light is stable')
Humidity.setText('On Humidifier')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water the plant')
Light.setText('Light has issue')
Humidity.setText('Humidity level stable')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) < 50 and (pbhub_2.analogRead(0)) < 600:
Moisture.setText('Water the plant')
Light.setText('Light is stable')
Humidity.setText('Humidity level stable')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
elif (env3_3.temperature) < 25 and (env3_3.humidity) > 80 and (earth_4.analogValue) > 50 and (pbhub_2.analogRead(0)) > 600:
Moisture.setText('Water level stable')
Light.setText('Light has issue')
Humidity.setText('Humidity level stable')
Temp.setText('Temperature is stable')
rgb.setColorAll(0xff0000)
speaker.tone(1800, 200)
wait_ms(200)
else:
Moisture.setText('Water level stable')
Light.setText('Light is stable')
Humidity.setText('Humidity level stable')
Temp.setText('Temperature is stable')
rgb.setColorAll(0x33ff33)
m5mqtt.publish(str('f55f2957-ce72-4a2a-b9e4-00bc501a2f4e'), str((json.dumps(({'Light':(pbhub_2.analogRead(0)),'Moisture':(earth_4.analogValue),'Humidity':(env3_3.humidity),'Temp.':(env3_3.temperature)})))), 0)
wait_ms(2)
Comments