Exemplo n.º 1
0
def creat_data():
    u=driver.read_u()
    if u:
        pack = ts.A.collect('volalite', str('%.1f'%u))
        DataCache.append(pack)
    i=driver.read_i()
    if i:
        pack = ts.A.collect('current', str('%.1f'%i))
        DataCache.append(pack)
    p=driver.read_p()
    if p:
        pack = ts.A.collect('power', str('%.1f'%p))
        DataCache.append(pack)

    dht.measure()
    t=dht.temperature()
    h=dht.humidity()
    if h:
        pack = ts.A.collect('humi', str('%.1f'%h))
        DataCache.append(pack)
    if t:
        pack = ts.A.collect('temp', str('%.1f'%t))
        DataCache.append(pack)
    if Relay.value():
        pack = ts.A.collect('switch', str(1))
    else:
        pack = ts.A.collect('switch', str(0))
    DataCache.append(pack)
Exemplo n.º 2
0
def read_dht():
    try:
        dht.measure()
    except Exception as e:
        common.log('Failed to get DHT measurements: %s' % e)
        return
    common.publish(TEMPTOPIC, "%.2f" % dht.temperature())
    common.publish(HUMTOPIC, "%.2f" % dht.humidity())
Exemplo n.º 3
0
def make_response(sta_if, request_content):
    try:
        dht.measure()
        dht_ready = True
    except OSError:
        dht_ready = False

    values = {
        'wifi': format_network_status(sta_if.ifconfig()),
        't': '{:.2f}'.format(dht.temperature()) if dht_ready else 'error',
        'h': '{:.2f}'.format(dht.humidity()) if dht_ready else 'error',
    }
    return PAGE_TEMPLATE.format(**values)
Exemplo n.º 4
0
def measure(mqtt, dht):
    #	try:
    dht.measure()

    temp = dht.temperature()
    humi = dht.humidity()
    print("Temperature: %3.1f °C" % temp)
    print("   Humidity: %3.2f %% RH" % humi)

    json_data = {"location": "lala", "temperature": temp, "humidity": humi}
    json_str = json.dumps(json_data)
    mqtt.publish(MQTT_TOPIC_TEMP, str(temp))
    mqtt.publish(MQTT_TOPIC_HUMI, str(humi))
Exemplo n.º 5
0
def polldht(dht, ledpin=None):
    """Collect measurements from DHT and return in a dictionary.
       If ledpin is specified, turn it on before measurement, and off after.
    """
    if ledpin:
        ledon(ledpin)
    dht.measure()
    results = {}
    results['temp'] = dht.temperature()
    results['humi'] = dht.humidity()
    if ledpin:
        ledoff(ledpin)
    return results
Exemplo n.º 6
0
import dht, time, machine
dht = dht.DHT11(machine.Pin(13))
while Thread[0]:
    dht.measure()
    print("temperature:", dht.temperature())
    print("humidity:", dht.humidity())  #DHT22 can be read twice every second
    time.sleep(1)  #DHT11 can only be read once every second
# connecting to WiFi
wifi = network.WLAN(network.STA_IF)
wifi.active(True)

wifi.connect(wifi_ssid, wifi_pw)
while not wifi.isconnected():
    pass

# get readings from DHT11 (connected to D5)
dht = dht.DHT11(machine.Pin(14))
dht.measure()

# Upload data via IFTTT
query_url = '{}?value1={}&value2={}&value3={}'.format(webhook_url,
                                                      'Temp(*C)/Humid(%)',
                                                      dht.temperature(),
                                                      dht.humidity())

response = None

try:
    print('Upload data...')
    response = urequests.get(query_url)
except:
    pass

if not response == None and response.status_code == 200:
    print('Upload successful')
    # led flashing quickly
    for _ in range(10):
        led.value(1)
Exemplo n.º 8
0
framebuf.text("Hello,", 0, 0, 1)
framebuf.text("World!", 0, 9, 1)
lcd.data(buffer)
sleep(5)


def elTime(sec):
    m, s = divmod(seconds, 60)
    h, m = divmod(m, 60)
    return "%02d:%02d:%02d" % (h, m, s)


import dht
DHTPIN = Pin(2)
dht = dht.DHT22(DHTPIN)

# Update display
while (True):
    dht.measure()
    seconds = ticks_ms() / 1000
    framebuf.fill(0)
    framebuf.text(elTime(seconds), 0, 0, 1)
    framebuf.text("%7d" % (ticks_ms() // 1000), 0, 11, 1)
    #framebuf.text("Temp", 0, 11, 1)
    framebuf.text("%.1f C" % dht.temperature(), 0, 20, 1)
    framebuf.text("Humidity", 0, 31, 1)
    framebuf.text("%.1f %%" % dht.humidity(), 0, 40, 1)
    lcd.data(buffer)
    sleep(1)
Exemplo n.º 9
0
import utime, dht, ssd1306

# DHT11 sensor (Pin D5)
dht = dht.DHT11(Pin(14))

# SSD1306 OLED display (SCL: D1, SDA: D2)
display = ssd1306.SSD1306_I2C(128, 64, I2C(scl=Pin(5), sda=Pin(4)))

# template string for formatting
template_str = '\nTemperature:\n {} *C  \n\nHumidity:\n {} % '

while True:

    # get readings from DHT11
    dht.measure()

    # generate formatted string
    output_str = template_str.format(dht.temperature(), dht.humidity())

    # print output without \n (new line) character
    print(output_str.replace('\n', ''))

    # print output on oled
    display.fill(0)
    for index, line in enumerate(output_str.split('\n')):
        display.text(line, 8, index * 8)
    display.show()

    # wait for 2 seconds
    utime.sleep(2)
Exemplo n.º 10
0
def read():
    dht.measure()
    value_hum = dht.humidity()
    value_temp = dht.temperature()
    read_output(value_hum)
    return value_hum, value_temp