def leituraDHT(): leitura = dht.DHT11(machine.Pin(4)) leitura.measure() #leitura.humidity() temp1 = leitura.temperature() time.sleep(60) leitura = dht.DHT11(machine.Pin(4)) leitura.measure() #leitura.humidity() temp2 = leitura.temperature() if (temp2 - temp1) >= 8: alarme()
def get_dht(): d = dht.DHT11(machine.Pin(12)) measure = d.measure() temperature = d.temperature() humidity = d.humidity() display.text("local_temp:{0}".format(temperature), 5, 40) display.text("local_humi:{0}%".format(humidity), 5, 50)
def main(): wlan = network.WLAN(network.STA_IF) wlan.active(True) wlan.connect('Amarilla', 'rocktheworld') d = dht.DHT11(machine.Pin(2)) def http_get(url): _, _, host, path = url.split('/', 3) addr = socket.getaddrinfo(host, 80)[0][-1] s = socket.socket() s.connect(addr) s.send( bytes('GET /%s HTTP/1.0\r\nHost: %s\r\n\r\n' % (path, host), 'utf8')) while True: data = s.recv(100) if data: print(str(data, 'utf8'), end='') else: break s.close() while True: d.measure() temp = d.temperature() hum = d.humidity() http_get("https://dweet.io/dweet/for/rezza-dryer?temp=" + str(temp) + "&hum=" + str(hum)) sleep_ms(10000)
def get_H(): sensor = dht.DHT11(Pin(4)) sensor.measure() #update data H = sensor.humidity() #print("Temperature:",T,"C","Humidity:",H,"%") blinkLED(2, 200) return H
def get_temperature(): data = {} d = dht.DHT11(machine.Pin(DH11_PIN)) d.measure() data["temperature"] = d.temperature() data["humidity"] = d.humidity() return data
def read_dht11(self, *args, **kwargs): import dht d = dht.DHT11(machine.Pin(self.pin_id)) d.measure() print("{0}: {1}C, {2}%".format(self.name, d.temperature(), d.humidity())) return ({'temperature': d.temperature(), 'humidity': d.humidity()})
def __init__(self, pin, name='dht11'): self._pin = pin Producer.__init__(self, name, 60000, 1000) self._dht = dht.DHT11(Pin(self._pin)) self.add_sensor("temperature", self.get_temperature) self.add_sensor("humidity", self.get_humidity) self.set_prepare_handler(self.measure)
def f(t): d = dht.DHT11(machine.Pin(4)) d.measure() a = d.temperature() b = d.humidity() print('温度:', a, '°C') print('湿度:', b, '%')
def showTempDHT(tm): dht11 = dht.DHT11(machine.Pin(Wemos.D4)) dht11.measure() tempDHT = dht11.temperature() tm.write_int(0x1000000000000000) number_helper.show2FiguresNumberX3(tm, tempDHT) return tempDHT
def read_dht11(self, pin): sensor = dht.DHT11(machine.Pin(pin)) while True: sensor.measure() t = sensor.temperature() h = sensor.humidity() return t, h
def upload_temperature_humidity(temp): # 温湿度测量 data = dht.DHT11(p5) data.measure() temperature = data.temperature() humidity = data.humidity() # 一氧化碳测量 Carbon_monoxide = adc.read() message = { 'datastreams': [{ 'id': 'humidity', 'datapoints': [{ 'value': humidity }] }, { 'id': 'temperature', 'datapoints': [{ 'value': temperature }] }, { 'id': 'Carbon_monoxide', 'datapoints': [{ 'value': Carbon_monoxide }] }] } c.publish('$dp', pubdata(message)) print('publish message:', message)
def init_robot(): print("Imported Libraries") print("Initializing...") # Turn on Light led = Pin(25, Pin.OUT) led.high() # DRIVER INITIALIZATION btn = button.Button(BUTTON_PIN) bzz = buzzer.Buzzer(BUZZER_PIN) motors = motor.TwoWheel(MOTOR_PINS, AXIL_LENGTH) threshold = max(UNIT_SIZE) - MIN_SENSOR_WIDTH ping_sensors = list( map(lambda pins: ping.PingProximitySensor(pins, threshold), PING_PINS)) ping_collection = ping.PingProxCollection(ping_sensors) dht_sensor = dht.DHT11(Pin(20)) # MAZE INITIALIZATION maze = Maze(MAZE_SIZE) # ROBOT INITIALIZATION robot = Robot(btn, bzz, motors, ping_collection, dht_sensor, maze, UNIT_SIZE, SOLUTIONS, threshold) utime.sleep_ms(100) led.low() print("Pico Initialized") robot.Start()
def temp_humid(): sensor = dht.DHT11(Pin(0)) while True: sensor.measure() print('temperature {:>2}c humidity {:>2}%'.format( sensor.temperature(), sensor.humidity())) sleep_ms(1000)
def getvalues(boardType): import temperature import machine import dht import time import mainAppConstants if boardType == 'esp32': TSPIN = mainAppConstants.ESP32_TS_PIN DHTPIN = mainAppConstants.ESP32_DHT_PIN else: TSPIN = mainAppConstants.ESP8266_TS_PIN DHTPIN = mainAppConstants.ESP8266_DHT_PIN try: ts = temperature.TemperatureSensor(TSPIN) d = dht.DHT11(machine.Pin(DHTPIN)) d.measure() dh11_hum = d.humidity() dh11_tmp = d.temperature() dsTemp = ts.read_temp(False) time.sleep(1) return dsTemp, dh11_tmp, dh11_hum except: time.sleep(1) return 0, 0, 0
def __init__(self, pin=2, sensor='dht11'): if sensor == 'dht11': self._d = dht.DHT11(machine.Pin(pin)) elif sensor == 'dht22': self._d = dht.DHT22(machine.Pin(pin)) else: raise NotImplementedError
def _dht(): import dht import machine d = dht.DHT11(machine.Pin(2)) d.measure() d.temperature() # eg. 23 (°C) d.humidity() # eg. 41 (% RH)
def do_temp(): try: d = dht.DHT11(machine.Pin(DHT_PIN)) d.measure() t = d.temperature() h = d.humidity() except OSError as err: t = 0 h = 0 print('temperature = %.2f' % t) print('humidity = %.2f' % h) global THINGSPEAK_WRITE_KEY if not THINGSPEAK_WRITE_KEY: print('not ThingSpeak key specified, skip sending data') return print('send data to ThingSpeak') data = '{"field1":"%.2f", "field2": "%.2f"}' % (t, h) headers = { 'X-THINGSPEAKAPIKEY': THINGSPEAK_WRITE_KEY, 'Content-type': 'application/json' } r = requests.post(API_THINGSPEAK_HOST, data=data, headers=headers) results = r.json() print(results)
def send(lora): sensor = dht.DHT11(Pin(17)) counter = 0 print("LoRa Sender") display = Display() while True: ident = "LoRa Sender" sleep(2) sensor.measure() temp = sensor.temperature() temp_conv = str('{:d} C'.format(temp)) hum = sensor.humidity() hum_conv = str('{:d} %'.format(hum)) payload = '{} {} ({})'.format(temp_conv, hum_conv, counter) #payload = 'Hello ({0})'.format(counter) # print("Sending packet: \n{}\n".format(payload)) display.show_text_wrap( "{0} {1} RSSI: {2}".format( ident, payload, lora.packetRssi()), 2) # Mensagem a enviar pelo sx127x.py: lora.println(payload) counter += 1 sleep(5)
def gravar(): sensor = dht.DHT11(Pin(23)) while True: try: sleep(1) print("Data: ", utime.localtime()) min = utime.localtime()[4] print("min: ", min) min = 60 - min sensor.measure() temp = sensor.temperature() umid = sensor.humidity() print("Temperatura ", temp) print("Umidade ", umid) url = "https://www.alessandro.inf.br/temperatura/inserir.php?temp=" + str( temp) + "&umid=" + str(umid) print(url) response = urequests.get(url) print(response.text) response.close() sleep(min * 60) except OSError as err: print(err) #gravar() #from ntptime import settime #settime() #import utime # t = utime.localtime()[4] # min[4]
def connect_devices(): import machine # Lib used to controll devices relay = machine.Pin(2, machine.Pin.OUT) import dht # Lib used to controll the DHT11 dht11 = dht.DHT11(machine.Pin(4)) return relay, dht11
def weather(): d = dht.DHT11(machine.Pin(4)) d.measure() d.temperature() d.humidity() print('listening on', addr) print('temperature', d.temperature()) print('humidity', d.humidity())
def measure(): d = dht.DHT11(machine.Pin(DHT11Pin)) d.measure() temp = d.temperature() hum = d.humidity() print('Temp: ', temp) # eg. 23.6 (°C) print('Humidity: ', hum) # eg. 41.3 (% RH) return temp, hum
def GetLocalTH(): ClearDisplay() d = dht.DHT11(machine.Pin(4)) DisplayMsg('{:16}'.format("Local Temp:"), 16) DisplayMsg('{:^16}'.format(str(d.temperature())), 24) DisplayMsg('{:16}'.format("Local Humidity:"), 40) DisplayMsg('{:^16}'.format(str(d.humidity())), 48) display.show()
def __init__(self, name, pin, on_change=None): import dht _HTDHT.__init__(self, name, pin, dht.DHT11(pin), 1000, on_change=on_change)
def get_dht_temperature(sensetype, pin): if (sensetype == 'dht11'): d = dht.DHT11(machine.Pin(pin)) else: d = dht.DHT22(machine.Pin(pin)) d.measure() time.sleep_ms(1) return d.temperature()
def get_dht_relative_humidity(sensetype, pin): if (sensetype == 'dht11'): d = dht.DHT11(machine.Pin(pin)) else: d = dht.DHT22(machine.Pin(pin)) d.measure() time.sleep_ms(1) return d.humidity()
def DHT11(pin_num): """ :param pin_num: :return: """ THI = dht.DHT11(Pin(pin_num)) THI.measure() THI_List = [THI.temperature(), THI.humidity()] return THI_List
def get_dht_sensor(): import dht dht_sensor = dht.DHT11(machine.Pin(5)) try: dht_sensor.measure() # is it even connected? except OSError: dht_sensor = None return dht_sensor
def getValues(self, dhtSensorSettings): #Load config d = dht.DHT11(machine.Pin(pin)) d.measure() time.sleep(0.1) vals = (d.temperature(), d.humidity()) print(vals) return vals
def __init__(self, name, pin, on_change=None, filter=None): import dht _HTDHT.__init__(self, name, pin, dht.DHT11(pin), 2000, on_change=on_change, filter=filter)