import machine, ssd1306, time, vcr_osd, inkythin from writa import Writer d = machine.DHT(machine.Pin(33), machine.DHT.DHT2X) i2c = machine.I2C(1, sda=21, scl=22) oled = ssd1306.SSD1306_I2C(128, 64, i2c) oled.fill(0) oled.show() led = machine.Pin(2, machine.Pin.OUT) while True: d.read() time.sleep(0.5) result, temperature, humidity = d.read() if result == False: for i in range(5): led.value(1) time.sleep(.5) led.value(0) break oled.fill(0) itxt = Writer(oled, inkythin) vtxt = Writer(oled, vcr_osd) Writer.set_clip(True, True) Writer.set_textpos(0, 0) itxt.printstring(str(temperature) + "'C\n") vtxt.printstring(str(humidity) + ' %') oled.show() time.sleep(10)
time.sleep_ms(1000) now = time.ticks_ms() while True: if wifi.ifconfig()[0] != '0.0.0.0': print("Connected, IP: {}".format(wifi.ifconfig()[0])) break if time.ticks_ms() - now > timeout: break return wifi # wifi = init_wifi("signalhuset", "signal+huset2017") # wifi = init_wifi("HomeBox-10E0_5G", "a6cfdf567") wifi = init_wifi("AndroidAPAD82", "odon3187") dht = machine.DHT(machine.Pin(2), machine.DHT.DHT11) # dht.read() #Returns status, temperature (C) and humidity (%) local_name = 'diana-1' unique_id = 'diana246813' mqtt = network.mqtt( local_name, 'mqtt://broker.hivemq.com', clientid=unique_id, #optional callbacks here ) mqtt.start() while True: time.sleep(300)
def read_dht22_lobo(self, pin22): dht = machine.DHT(machine.Pin(pin22), machine.DHT.DHT2X) result, temperature, humidity = dht.read() return temperature, humidity
import machine pin = 14 dht = machine.DHT(machine.Pin(pin), machine.DHT.DHT2X) result, temperature, humidity = dht.read() x = result y = float(temperature) z = int(humidity) print(x) print(y) print(z) if not result: print('Failed!') else: print('t={} C'.format(temperature)) print('h={} % RH'.format(int(humidity)))
def read_dht11_lobo(self, pin11): dht = machine.DHT(machine.Pin(pin11), machine.DHT.DHT11) result, temperature, humidity = dht.read() return temperature, humidity