Exemplo n.º 1
0
def read_temp_and_humidity(sensor, scale="f"):
    """
    Reads the current temperature and humidity.
    :param sensor:
    :param scale: default is f (fahrenheit)
    :return:
    """
    (temperature, humidity) = sensor.get_data(scale)
    while temperature is None or temperature <= 32:
        (temperature, humidity) = sensor.get_data()
        time.sleep(.5)
    return temperature, humidity
Exemplo n.º 2
0
def get_data(type):
    try:
        t = sensor.get_data(type)
    except Exception as e:
        t = {}
        t[type] = '-1'
    return jsonify({'ts': int(time.time() * 1000), type: t})
Exemplo n.º 3
0
def get_data(type):
    t = None
    try:
        t = sensor.get_data(type)
    except Exception as e:
        return jsonify({'ts': int(time.time() * 1000), type: -1}) # handle sensor data error
    return jsonify({'ts': int(time.time() * 1000), type: t})
Exemplo n.º 4
0
def get_data(type):
    t = None
    try:
        t = sensor.get_data(type)
    except Exception as e:
        return jsonify({
            'ts': int(time.time() * 1000),
            type: -1
        })  # handle sensor data error
    return jsonify({'ts': int(time.time() * 1000), type: t})
Exemplo n.º 5
0
def pull_temperature():
    global myWrapper
    temperature = sensor.get_data('temperature')
    myWrapper.addValue(temperature)
    average = myWrapper.averageValues()
    if myWrapper.monitorSize():
        if myWrapper.monitorAverage():
            if average >= myWrapper.getHigh():
                myWrapper.sendSparkMessage(
                    "\n\nHOT DAMN HOT DAMN HOT DAMN HOT DAMN")
                myWrapper.sendSparkMessage("It's steamy in here.")
            else:
                myWrapper.sendSparkMessage(
                    "\n\nBRRRRRRR BRRRRRRR BRRRRRRR BRRRRRRR")
                myWrapper.sendSparkMessage("It's freezing in here")
            myWrapper.sendSparkMessage(
                "There is an extreme average temperature of " + str(average) +
                " degrees Fahrenheit over the past " +
                str(myWrapper.getMaxSize() * 3) + " seconds!!!")
        else:
            myWrapper.sendSparkMessage("\n\nIt's all good in the hood")
Exemplo n.º 6
0
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import sh1106
from PIL import ImageDraw, Image
import time
import sensor

# Display einrichten
serial = i2c(port=1, address=0x3C)
device = sh1106(serial)

# Display Ausgabe von aktuellen Sensordaten mit Einheiten und verschiebung der y Position des Textes
while 1:
    for i, j, k, l in zip(sensor.get_data(r=True, acc=2), sensor.labels(),
                          sensor.units(), [0, 1, 2, 3]):
        with canvas(device) as draw:
            draw.rectangle(device.bounding_box, outline="white", fill="black")
            draw.text((10, l * 10 + 5),
                      j + "\n" + str(i) + " " + k,
                      fill="white")
        time.sleep(3)
Exemplo n.º 7
0
import time
import sensor
import datenbank as db

# speichert die Messwerte alle 60s in der sqlite Datenbank Wetter.db
i = 0
while 1:
    # Messwerte einlesen
    data = sensor.get_data()
    # Messwerte in datenbank speichern
    try:
        db.write_data("Wetter.db", data)
        i = i + 1
        # Ausgeben das Messwerte gespeichert wurden
        print("Es wurden", str(i), "Messreihen durchgeführt.")
    except:
        print("Error")
    time.sleep(60)
Exemplo n.º 8
0
# lopy4_bme680_ttnuplink/bme680_ttnuplink/main.py

from machine import Pin
import radio
import sensor
import time

# Configure IO Pins:
configPin = Pin('P21', Pin.IN, Pin.PULL_UP)  # Pull low to exit to REPL
LoRaPin = Pin('P22', Pin.IN, Pin.PULL_UP)  # Pull low to enable LoRa

# initial read from IO pins (Reverse the logic for better readability later):
config = not configPin()
lora_on = not LoRaPin()

if config:
    radio.config()

if lora_on:
    radio.connect()
    radio.make_socket()

if not config and lora_on:
    while True:
        btemp, bpres, bhumi, bgas = sensor.get_data()

        radio.send_packet(btemp, bpres, bhumi, bgas)

        time.sleep(30)
Exemplo n.º 9
0
def draw_image():
    weather = weather_api.get_current_weather()
    forecasts = weather_api.get_forecast()
    data = sensor.get_data('98:D3:71:F9:66:2B')
    print(data)

    image = Image.new('1', (EPD_WIDTH, EPD_HEIGHT), 1)
    draw = ImageDraw.Draw(image)
    font_big = ImageFont.truetype('MonospaceTypewriter.ttf', 40)
    font = ImageFont.truetype('MonospaceTypewriter.ttf', 25)
    font_small = ImageFont.truetype('MonospaceTypewriter.ttf', 15)

    draw.rectangle((0, 0, EPD_WIDTH, ROW_BORDER_WIDTH), fill=0)
    draw.rectangle((0, EPD_HEIGHT - ROW_BORDER_WIDTH, EPD_WIDTH, EPD_HEIGHT),
                   fill=0)

    for x in range(1, ROW_COUNT + 1):

        y_pos = ROW_WIDTH * (x - 1) - ROW_BORDER_WIDTH / 2

        if x == 0:
            y_pos += ROW_BORDER_WIDTH / 2

        draw.rectangle((y_pos, 0, y_pos + ROW_BORDER_WIDTH, EPD_HEIGHT),
                       fill=0)

        y_pos = ROW_WIDTH * x - ROW_BORDER_WIDTH / 2

        if x == ROW_COUNT:
            y_pos -= ROW_BORDER_WIDTH / 2

        draw.rectangle((y_pos, 0, y_pos + ROW_BORDER_WIDTH, EPD_HEIGHT),
                       fill=0)

    draw.text((25, 5), "outdoor", font=font_big, fill=0)

    draw.text((20, 160), "online", font=font_small, fill=0)
    draw.text((20, 180),
              "tempature: " + str(weather['main']['temp']) + "°C",
              font=font_small,
              fill=0)
    draw.text((20, 200),
              "humidity: " + str(weather['main']['humidity']) + "%",
              font=font_small,
              fill=0)
    draw.text((20, 220),
              "pressure: " + str(weather['main']['pressure']) + " hPa",
              font=font_small,
              fill=0)

    draw.text((20, 60), "sensor", font=font_small, fill=0)
    draw.text((20, 80),
              "tempature: " + str(data['temp']) + "°C",
              font=font_small,
              fill=0)
    draw.text((20, 100),
              "humidity: " + str(data['humidity']) + "%",
              font=font_small,
              fill=0)
    draw.text((20, 120),
              "pressure: " + str(data['pressure'] / 100) + " hPa",
              font=font_small,
              fill=0)

    draw.text((225, 5), "forecast", font=font_big, fill=0)

    offset = 60
    for cast in forecasts:
        dt = datetime.strptime(cast['dt_txt'], '%Y-%m-%d %H:%M:%S')
        date_str = dt.strftime('%H:%M')
        dt = dt + timedelta(hours=3)
        date_str = date_str + ' - ' + dt.strftime('%H:%M')
        draw.text((230, offset), date_str, font=font_small, fill=0)
        offset = offset + 20
        draw.text((230, offset),
                  'temperature: ' + str(cast['main']['temp']) + '°C',
                  font=font_small,
                  fill=0)

        if len(cast['weather']) > 0:
            offset += 20
            draw.text((230, offset),
                      str(cast['weather'][0]['description']),
                      font=font_small,
                      fill=0)

        offset += 40

    date = time.strftime("%d.%m.%Y")
    date = date + "\n" + time.strftime("%A")

    draw.multiline_text((460, 20), date, font=font, fill=0, align="center")

    draw.text((460, 100),
              'sunrise ' +
              utc_to_local(datetime.utcfromtimestamp(
                  weather['sys']['sunrise'])).strftime('%H:%M'),
              font=font_small,
              fill=0)
    draw.text((460, 130),
              'sunset ' +
              utc_to_local(datetime.utcfromtimestamp(
                  weather['sys']['sunset'])).strftime('%H:%M'),
              font=font_small,
              fill=0)
    return image
Exemplo n.º 10
0
if drop == "y":
    import sensor
    from pytz import timezone
    from datetime import datetime

    conn = sqlite3.connect('flaskr/database.db')
    db = conn.cursor()

    db.execute("DROP TABLE IF EXISTS readings")
    db.execute("""CREATE TABLE readings (
            temperature REAL NOT NULL,
            humidity REAL NOT NULL,
            datetime TEXT NOT NULL
        )""")

    dat = sensor.get_data(False)
    _temp = dat['temp']
    _humid = dat['humid']
    tz = timezone('EST')
    db.execute(
        "INSERT INTO readings (temperature, humidity, datetime) VALUES (?, ?, ?);",
        (_temp, _humid, datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")))

    conn.commit()
    conn.close()

elif drop == "q":
    sys.exit()

else:
    print("Continuing without reset db")