예제 #1
0
def humid_temp_sensor(read):
    th = DHT('P23', 0)
    time.sleep(2)
    while read:
        result = th.read()
        while not result.is_valid():
            time.sleep(.5)
            result = th.read()
        temperature = result.temperature
        humidity = result.humidity
        read = False
    return (temperature, humidity)
예제 #2
0
    except:
        return None


# Sends the request. Please reference the REST API reference https://ubidots.com/docs/api/
def post_var(device, value1, value2):
    try:
        url = "https://industrial.api.ubidots.com/"
        url = url + "api/v1.6/devices/" + device
        headers = {"X-Auth-Token": TOKEN, "Content-Type": "application/json"}
        data = build_json("Temp", value1, "RM", value2)
        if data is not None:
            print(data)
            req = requests.post(url=url, headers=headers, json=data)
            return req.json()
        else:
            pass
    except:
        pass


while True:
    result = th.read()
    if result.is_valid():
        temp = result.temperature  # Data values
        rm = result.humidity  # Data values
        post_var("pycomTemp", temp, rm)
        time.sleep(DELAY)
    else:
        time.sleep(1)
예제 #3
0
import pycom
import time
from machine import Pin
from dht import DHT

powerPin = Pin('G28', mode=Pin.OUT)
powerPin(0)

pycom.heartbeat(False)
pycom.rgbled(0x000008)  # blue
powerPin(1)
time.sleep(2)
th0 = DHT('G24', 1)
th1 = DHT('G11', 1)
result0 = th0.read()
result1 = th1.read()
# powerPin(0)

if result0.is_valid():
    pycom.rgbled(0x001000)  # green
    print('Temperature0: {:3.1f}'.format(result0.temperature / 1.0))
    print('Humidity0: {:3.1f}'.format(result0.humidity / 1.0))
if result1.is_valid():
    pycom.rgbled(0x001000)  # green
    print('Temperature1: {:3.1f}'.format(result1.temperature / 1.0))
    print('Humidity1: {:3.1f}'.format(result1.humidity / 1.0))