コード例 #1
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
コード例 #2
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)
コード例 #3
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")
コード例 #4
0
class DHT11:
    temp_sensor = DTH(Pin('P4', mode=Pin.OPEN_DRAIN), 0)

    def get_temperature(self):
        return self.temp_sensor.read().temperature

    def get_humidity(self):
        return self.temp_sensor.read().humidity

    def get_sim_temperature(self, temp_threshold):
        random_num = uos.urandom(1)[0]
        if (random_num > 100):
            return temp_threshold - 1
        else:
            return temp_threshold + 1
コード例 #5
0
import pycom
import time
from machine import Pin
from dth import DTH

pycom.heartbeat(False)
pycom.rgbled(0x000008)  # blue
th = DTH('P3', 0)
time.sleep(2)
result = th.read()
if result.is_valid():
    pycom.rgbled(0x001000)  # green
    print("Temperature: %d C" % result.temperature)
    print("Humidity: %d %%" % result.humidity)
コード例 #6
0
from network import LoRa
import time
import binascii
import socket
import time
import pycom
import time
from machine import Pin
from dth import DTH
from machine import UART
import json

uart = UART(1, 115200)
th = DTH('P11', 0)

lora = LoRa(mode=LoRa.LORAWAN, tx_power=14, region=LoRa.EU868)

app_eui = binascii.unhexlify('70B3D57ED000C391')
app_key = binascii.unhexlify('E3B600CCE5FF1C6155838376FD7E0330')

lora.join(activation=LoRa.OTAA, auth=(app_eui, app_key), timeout=0)

# wait until the module has joined the network
while not lora.has_joined():
    time.sleep(5)
    print('Not joined yet...')

print('Network joined!')

s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
コード例 #7
0
import pycom
import time
from machine import Pin
from dth import DTH

pycom.heartbeat(False)  # turn off heartbeat LED
th = DTH('P3', 0)  # Assign 'P3' as input pin or sensor read

print("\n*** FiPy-1 successfully booted! ***\n")
コード例 #8
0
# stop the blue light from flickering
pycom.heartbeat(False)
led = LEDColors.pyLED()

print('Starting up...')

#setup LoRa connection
connection = TTN.LoRaConnection()
print("LoRa device EUI:")
connection.getDeviceEUI()
connection.start()

# setup sensor
pin = Pin('G7', mode=Pin.OPEN_DRAIN)
while True:
    th = DTH(pin, 0)
    result = th.read()
    if result.is_valid():
        led.setLED('green')
    else:
        led.setLED('red')
    co2 = "00000"  # no CO2 sensor in DHT11
    hum = "{0:0>2}0".format(result.humidity)
    temp = "{0:0>2}0".format(result.temperature)

    dataline = co2 + hum + temp
    led.setLED('off')
    print(dataline)
    data = bytearray()
    for i in bytes(dataline, 'utf-8'):
        try:
コード例 #9
0
from dth import DTH
from machine import Pin

# Setup for temperature and humidity sensor
th1 = DTH(Pin('P13', mode=Pin.OPEN_DRAIN), 1)
th2 = DTH(Pin('P23', mode=Pin.OPEN_DRAIN), 1)
コード例 #10
0
ファイル: main.py プロジェクト: PopBogdan97/puez
# SENSOR ----- PIN --- ATTENUATION
# DHT11        P3      ADC.ATTN_0DB
# Flame        P17     ADC.ATTN_0DB
# LM35         P14     ADC.ATTN_0DB
# Light        P17     ADC.ATTN_11DB

flame = machine.ADC()
temp = machine.ADC()
light = machine.ADC()

# Might need to set it to 11DB for real flames
flamePin = flame.channel(pin='P17', attn=flame.ATTN_0DB)  # G6
tempPin = temp.channel(pin='P14', attn=temp.ATTN_0DB)  # G4
# Calibration: 3.1 volts, maximum is 6000 lux, min is 1 lux
lightPin = light.channel(pin='P20', attn=light.ATTN_11DB)  # G7
th = DTH(Pin('P3', mode=Pin.OPEN_DRAIN), 0)

# Initialise LoRa in LORAWAN mode
lora = LoRa(mode=LoRa.LORAWAN, device_class=LoRa.CLASS_C)

# Create an ABP authentication
dev_addr = struct.unpack(
    ">l", ubinascii.unhexlify('007f6c48'))[0]  # your device address here
nwk_swkey = ubinascii.unhexlify(
    'e8b5606374b7688c4585a3c25c0a79de')  # your network session key here
app_swkey = ubinascii.unhexlify(
    '4596c2f319690ff914cdca0212f622a4')  # your application session key here

# Join the network using ABP (Activation By Personalisation)
lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
コード例 #11
0
ファイル: main.py プロジェクト: frahlg/UBC-NAME
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# configure data rate. 3 = US (not sure why)

s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
# make the socket blocking
# (waits for the data to be sent and for the 2 receive windows to expire)
s.setblocking(True)

lpp = CayenneLPP.CayenneLPP(size = 100, sock = s)


# Type 0 = dht11
# Type 1 = dht22

th = DTH(Pin('P23', mode=Pin.OPEN_DRAIN), 0)
time.sleep(2)

def send_env_data():
    while True:
        result = th.read()
        while not result.is_valid():
            time.sleep(1)
            result = th.read()
        print('Temp:', result.temperature)
        print('RH:', result.humidity)
        lpp.add_temperature(result.temperature)
        lpp.add_relative_humidity(result.humidity)
        lpp.send(reset_payload = True)
        time.sleep(30)
コード例 #12
0
import pycom
import time
from machine import Pin
from dth import DTH

# Disable LED heartbeat (so we can control the LED)
pycom.heartbeat(False)
# Assign 'P3' as input pin or sensor read
th = DTH('P3', 0)

print("\n*** Sensor Node successfully booted! ***\n")
コード例 #13
0
# If we fail to successfully POST results within a 32 minute window (allowing for retries) we will reset the device
wdt = WDT(timeout=1920000)

adc = ADC(bits=12)

time.timezone(3600)  # CET

INTEGRATIONTIME_100MS = 0x00
INTEGRATIONTIME_200MS = 0x01
GAIN_LOW = 0x00
GAIN_MED = 0x10

light_sensor = Tsl2591(1, INTEGRATIONTIME_100MS, GAIN_LOW)
soil_moisture_sensor = adc.channel(pin='P20', attn=ADC.ATTN_11DB)
temp_and_humidity_sensor = DTH(Pin('P22', mode=Pin.OPEN_DRAIN), 0)

while True:
    resultValid = False

    while not resultValid:
        pycom.rgbled(0x101000)  # yellow

        # increase the gain and exposure of light sensor at night
        currentHour = time.localtime()[3]
        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)
コード例 #14
0
ファイル: main.py プロジェクト: aparcar/lora-evaluation
from network import LoRa
import socket
import ujson
import time
import machine
import pycom
from machine import ADC

from dth import DTH

print("starting")

pycom.heartbeat(False)

th = DTH("P23", 1)
time.sleep(2)

adc = ADC()
adc.vref_to_pin("P22")
adc.vref(1100)
adc_c = adc.channel(pin="P16", attn=ADC.ATTN_11DB)


lora = LoRa(mode=LoRa.LORA, region=LoRa.US915)
lora.init(
    tx_power=14,
    sf=7,
    frequency=915000000,
    coding_rate=LoRa.CODING_4_5,
    bandwidth=LoRa.BW_125KHZ,
    power_mode=LoRa.TX_ONLY,
コード例 #15
0
ファイル: solver.py プロジェクト: JulkerKhan/PathFinding
def solve(input,
          output,
          list_of_locations,
          list_of_homes,
          starting_car_location,
          adjacency_matrix,
          params=[]):
    """
    Write your algorithm here.
    Input:
        list_of_locations: A list of locations such that node i of the graph corresponds to name at index i of the list
        list_of_homes: A list of homes
        starting_car_location: The name of the starting location for the car
        adjacency_matrix: The adjacency matrix from the input file
    Output:
        A list of locations representing the car path
        A dictionary mapping drop-off location to a list of homes of TAs that got off at that particular location
        NOTE: both outputs should be in terms of indices not the names of the locations themselves
    """
    dth = DTH(input_filename=input,
              output_filename=utils.input_to_output(input, output))
    e = dth.energy()
    if len(list_of_locations) <= 50:
        dth.Tmax = (e / 10)  # Max (starting) temperature
        dth.Tmin = (e / 1000)  # Min (ending) temperature
        dth.steps = 10000  # Number of iterations
        dth.updates = 1000
        # Number of updates (by default an update prints to stdout)
        dth.prob = 0.8
        # dth.set_schedule(dth.auto(minutes=.2, steps=250))
        # dth.steps = 500
        # dth.updates = 500
    elif len(list_of_locations) <= 100:
        dth.Tmax = e / 10  # Max (starting) temperature
        dth.Tmin = e / 1000  # Min (ending) temperature
        dth.steps = 1000  # Number of iterations
        dth.updates = 100  # Number of updates (by default an update prints to stdout)
        # dth.set_schedule(dth.auto(minutes=.2, steps=250))
        # dth.steps = 500
        # dth.updates = 500
        dth.prob = 0.8
    else:
        dth.Tmax = (e / 10)  # Max (starting) temperature
        dth.Tmin = (e / 1000)  # Min (ending) temperature
        dth.steps = 100  # Number of iterations
        dth.updates = 100  # Number of updates (by default an update prints to stdout)
        # dth.set_schedule(dth.auto(minutes=.2, steps=250))
        # dth.steps = 500
        # dth.updates = 500
        dth.prob = 0.8
    dth.copy_strategy = "slice"

    car_cycle, cost = dth.anneal()
    dth.gen_best_state_dropoff()

    return car_cycle, dth.dropoff_mapping
コード例 #16
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)
コード例 #17
0
            while not wlan.isconnected():
                machine.idle()
            print("Connected with Fablab", end=" ")
            global mychannel;
            mychannel = net.channel
            print("SSID {} RSSI {} Channel {}".format(net.ssid, net.rssi, net.channel))
            break;

# connect the grove temperature/humidity (DHT11) sensor to digital connector J7 or J8
#  J7 connector: to I/O Pin 'P12'
#  J8 connector: to I/O Pin 'P11'

# Instantiate the DHT class with these parameters:
# 1) the pin number
# 2) type of sensor: 0 for DTH11, 1 for DTH22
th = DTH('P11',0)

# loop to read temperature / humidity from DHT11
#
i2c = I2C(0, I2C.MASTER, baudrate=100000)
sensor = SI1145(objI2C=i2c)
# use grove oled display
grove_oled_display = SSD1308_I2C(objI2C=i2c)
display = Writer(grove_oled_display, myfont)
gc.collect()            # free ram
Writer.set_clip(True, True)
time.sleep(2)
adc = machine.ADC()             # create an ADC object
apin = adc.channel(pin='P16')   # create an analog pin on P15 (J5 connector)
dpin = adc.channel(pin='P15')
data = []
コード例 #18
0
import config
from dth import DTH
import machine
import pycom
import rgb
import time
import ubidots

pycom.heartbeat(False)

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()
コード例 #19
0
 f.close()
 if config.powersaving==False: #and result.is_valid()
     print("Measure # ", newcounter)
     pycom.rgbled(config.RED)
     utime.sleep(0.5)
     pycom.rgbled(config.OFF)
     utime.sleep(0.2)
     pycom.rgbled(config.RED)
     utime.sleep(0.5)
     pycom.rgbled(config.OFF)
 us1med,us1mean,us1dev = measureUSblack.advanced_measuretime(config.trig,config.echo)
 if config.powersaving==False:
     print("Ultrasonic time = "+ str(us1med)+ " us")
     print("Ultrasonic distance = "+ str(us1med*0.34)+ " mm")
 if config.isDHT11==True:
     th = DTH(config.DHT,0) #for DHT11 sensor (blue)
     nameDTH="11"
 else:
     th = DTH(config.DHT,1) #for DHT22 sensor (white)
     nameDTH="22"
 # time.sleep(2)
 result = th.read()
 if config.powersaving==False: #and result.is_valid()
     print("Temperature DHT"+nameDTH+" = %d C" % result.temperature)
     print("Humidity DHT"+nameDTH+"  = %d %%" % result.humidity)
 meanbatt=0
 j=0
 if config.powersaving==False:
     pycom.rgbled(config.BLUE)
 while j < 5:
     utime.sleep(0.2)
コード例 #20
0
import binascii
from machine import Pin
from dth import DTH
import ustruct
import utime

# Colors
off = 0x000000
red = 0xff0000
green = 0x00ff00
blue = 0x0000ff
FIVE_MINUTES = 5 * 60

# Turn off hearbeat LED
pycom.heartbeat(False)
th = DTH(Pin('P3', mode=Pin.OPEN_DRAIN), 1)
# Initialize LoRaWAN radio
# lora = LoRa(mode=LoRa.LORAWAN)
lora = LoRa(mode=LoRa.LORAWAN)

# Set network keys
app_eui = binascii.unhexlify(appkeys.APP_EUI)
app_key = binascii.unhexlify(appkeys.APP_KEY)

# Switch OFF WLAN
#print("Disable WLAN");
#wlan = WLAN()
#wlan.deinit()
counter = 0

コード例 #21
0
from machine import deepsleep
from machine import RTC
from dth import DTH
#from hx711 import HX711
import machine
import time
import pycom
#import sys

### CONSTANTS ###
MAXTEMP = 20  # Desired inside temperature of chickencoup
DOOROPENTIME = 30  # Ammount of time it takes to open the door
DOORCLOSETIME = 30  # Ammount of time it takes to let the door close (might be different to open time)

p_in = Pin('P19', mode=Pin.IN, pull=Pin.PULL_UP)  # Input for door switch
th = DTH(Pin('P23', mode=Pin.OPEN_DRAIN),
         1)  # Creating DHT object to get temperature and humidity
firstLed = Pin(
    'P22', mode=Pin.OUT
)  # Leds to show ammount of eggs in binary (firstLed is the left most led (MSB))
secondLed = Pin(
    'P21', mode=Pin.OUT)  # secondLed and thridLed are to the right of firstLed
thirdLed = Pin('P20', mode=Pin.OUT)

rtc = RTC()  # init with default time and date
lasttime = rtc.now(
)  # Variable to store the last time an action was performed to calculate the time difference

#machine.pin_sleep_wakeup(pins=p_in, mode=machine.WAKEUP_ANY_HIGH, enable_pull=True) # Enabeling the swith to wake up the lopy from deepsleep


### FUNCTIONS ###