#from machine import reset
#reset()
##soft reboot ctrl + d meg igy is jo a consolba
#help()
#help('modules')
#print('HELLO WORLD')
#led cez wifi modul
#from machine import Pin
#led = Pin('LED', Pin.OUT)
#alebo led = Pin(25, Pin.OUT)
#led.on()
#led.off()
#led.value()#vypise ci je zapnute 1 alebo vypnute led 0
#led.value(1)#zapnem
#led.toggle() # == led.value(not led.value())
#from time import sleep
#sleep(5)
#blikanie pico
#######################################################
#from time import sleep
#from machine import Pin
#led = Pin(25, Pin.OUT)
#while True:
# led.on()
# sleep(1)
# led.off()
# sleep(0.5)
#ctrl + c prerusit
#internet pripojenie esp32
#########################################################
#do boot.py
def do_connect(ssid, password):
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
print('connecting to network...')
wlan.connect(ssid, password)
while not wlan.isconnected():
pass
print('network config:', wlan.ifconfig())
#do terminal do_connect('name of network','password')
#terminal do_connect('Wokwi-GUEST','')
#do terminalu import upip
#do terminalu upip.install('umqtt.simple')
# do mqtt_client.py
from umqtt.robust import MQTTClient
from machine import Pin
def on on_message(topic, message):
topic = topic.decode('utf-8')
message = message.decode('utf-8')
print(f'{topic}{message}')
if message == 'on':
print('Truning the led on')
led.on()
elif message == 'of':
print('Truning the led off')
led.off()
mqtt = MQTTClient('akos','broker.hivemq.com')
mqtt.set_callback(on_message)
mqtt.connect()
#do terminal mqtt.publish('kpi/iot/messages','akos')
mqtt.subscribe('kpi/iot/lights/akos')
#ezzel az osszeset be ki lehet kapcsolni ha oda kuldesz uzenetet mqtt.subscribe('kpi/iot/lights')
while True:
print('waiting for message...')
mqtt.wait_msg()
##do helpers.py
from machine import ADC
def get_temperature():
# read the temperature
sensor = ADC(4)
conversion_factor = 3.3 / (65535)
reading = sensor.read_u16() * conversion_factor
temperature = 27 - (reading - 0.706)/0.001721
return temperature