コード例 #1
0
ファイル: main.py プロジェクト: FrederickFranck/KippenKot
def read_dht():
    th = DTH(dht_pin, 1)
    result = th.read()
    if result.is_valid():
        print('Temperature: {:3.2f}'.format(result.temperature / 1.0))
        print('Humidity: {:3.2f}'.format(result.humidity / 1.0))
    else:
        print("Invalid Result")
コード例 #2
0
def read_sensor():
    pycom.heartbeat(False)
    pycom.rgbled(0x000f00)  # green = reading
    th = DTH(Pin('P3', mode=Pin.OPEN_DRAIN), 0)  # P3 = G24
    time.sleep(1)
    result = th.read()
    if result.is_valid():
        return result
コード例 #3
0
ファイル: read_dht.py プロジェクト: waheb2020/applied-iot-20
def value():
    th = DTH(Pin('P23', mode=Pin.OPEN_DRAIN), 1)
    time.sleep(3)
    result = th.read()
    # print('Temp:', result.temperature)
    # print('RH:', result.humidity)
    if result.is_valid():
        return (result.temperature, result.humidity)
コード例 #4
0
ファイル: main.py プロジェクト: PopBogdan97/puez
lora.add_channel(2, frequency=868100000, dr_min=0, dr_max=5)

# Uplink sending and downlink receiving
while (True):
    s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)  # create a LoRa socket
    s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)  # set the LoRaWAN data rate
    s.setblocking(False)  # make the socket non-blocking

    # Print and save all the values to be sent
    flameVal = flamePin()
    print("Flame = %d" % flameVal)
    tempVal1 = tempPin() / 32
    print("Temperature (LM35) = %.2f" % tempVal1)
    lightVal = 6000 * lightPin() / 4096  # Translate into lux
    print("Light = %.2f lx" % lightVal)
    dhtVal = th.read()
    tempVal2 = dhtVal.temperature
    print("Temperatura (DHT11) = %.2f C" % tempVal2)
    avgTemp = (tempVal1 + tempVal2) / 2.0
    print("AvgTemp = %.2f" % avgTemp)
    humVal = dhtVal.humidity
    print("Humidity = %d %%" % humVal)

    windSpeed = RandomRange(0, 40)
    windDir = RandomRange(0, 360)  # Polar coordinates 90 degrees shifted

    # Sending start, prepare JSON object
    pkt = {
        "id": "server",
        "F": flameVal,
        "L": lightVal,
コード例 #5
0
ubidots.setup()
print('Connected to WiFi')
rgb.blink(0x00ff00, 3)

d = DTH(machine.Pin(config.DHT_PIN, mode=machine.Pin.OPEN_DRAIN), 1)
light = machine.Pin(config.LIGHT_PIN, mode=machine.Pin.IN)
adc = machine.ADC(bits=10)
read_light_value = adc.channel(attn=machine.ADC.ATTN_11DB, pin=config.LIGHT_PIN)
soil_moisture_power = machine.Pin(config.SOIL_MOISTURE_POWER_PIN,
                                  mode=machine.Pin.OUT,
                                  pull=machine.Pin.PULL_DOWN)
read_soil_moisture_value = adc.channel(attn=machine.ADC.ATTN_11DB,
                                       pin=config.SOIL_MOISTURE_READ_PIN)

while True:
    result = d.read()

    while not result.is_valid():
        time.sleep(1)
        result = d.read()

    soil_moisture_power.value(1)
    time.sleep(0.1)
    soil_moisture_percentage = read_soil_moisture_value()*100/1024
    soil_moisture_power.value(0)
    light_percentage = read_light_value()*100/1024

    data = {
        'temperature': {'value': result.temperature},
        'humidity': {'value': result.humidity},
        'light': {'value': light_percentage},
コード例 #6
0
ファイル: main.py プロジェクト: kiwinol/sensor-city-delft
import time
from machine import Pin
from dth import DTH

# data pin connected to P11
# 1 for AM2302
th = DTH(Pin('P3', mode=Pin.OPEN_DRAIN), 1)
time.sleep(2)

while True:
    result = th.read()
    print(result, type(result))
    print(result.is_valid())
    # if result.is_valid():
    print('Temperature: {:3.2f}'.format(result.temperature / 1.0))
    print('Humidity: {:3.2f}'.format(result.humidity / 1.0))
    time.sleep(2)
コード例 #7
0
        if currentHour >= 6 and currentHour <= 18:
            light_sensor.set_timing(INTEGRATIONTIME_100MS)
            light_sensor.set_gain(GAIN_LOW)
        else:
            light_sensor.set_timing(INTEGRATIONTIME_200MS)
            light_sensor.set_gain(GAIN_MED)
        time.sleep(2)

        soil_moisture = soil_moisture_sensor()
        time.sleep(2)

        full, ir = light_sensor.get_full_luminosity()
        lux = light_sensor.calculate_lux(full, ir)
        time.sleep(2)

        result = temp_and_humidity_sensor.read()
        time.sleep(3)

        if result.is_valid():
            resultValid = True
            pycom.rgbled(0x001000)  # green

            results = {
                "timestamp": time.time(),
                "lux": lux,
                "temperature": result.temperature,
                "humidity": result.humidity,
                "soilMoisture": soil_moisture
            }

            jsonString = ujson.dumps(results)
コード例 #8
0
ファイル: main.py プロジェクト: aparcar/lora-evaluation
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

cnt = 0
node = "lopy4_1"


def get_voltage():
    sum = 0
    for i in range(100):
        sum += adc_c.voltage()
    return (sum / 100) * 2 / 1000


while True:
    dht_result = th.read()
    voltage = get_voltage()
    msg = ujson.dumps(
        {
            "node": node,
            "cnt": cnt,
            "bat": voltage,
            "temp": dht_result.temperature / 1.0,
            "hum": dht_result.humidity / 1.0,
        }
    )
    print(msg)
    s.send(msg)
    cnt += 1
    time.sleep(10)