Пример #1
0
def main():
    an = Anemometer(17)
    dr = ADS1015()
    mq = Mqtt('192.168.1.104')
    wind_avg = []
    winddir_avg = []

    an.start()

    loop_count = 0
    last_day = 0
    max_daily_gust = 0.0

    wait_time = 15.0
    max_count = 600 / wait_time

    while True:
        data = []
        loop_count += 1
        wind = get_wind(an, dr)
        wind_avg.append(wind['fields']['windspeedmph'])
        winddir_avg.append(wind['fields']['winddir'])
        wind['fields']['windspdmph_avg10m'] = float(
            round(get_average(wind_avg, max=max_count), 2))
        wind['fields']['winddir_avg10m'] = float(
            round(get_average(winddir_avg, max=max_count), 2))

        today = datetime.date.today().day
        if today != last_day:
            print("Resetting gust data for a new day")
            max_daily_gust = 0.0
            an.reset_gust()
            wind['fields']['maxdailygust'] = max_daily_gust
            wind['fields']['windgustmph'] = max_daily_gust
            last_day = today

        if wind['fields']['windgustmph'] > max_daily_gust:
            max_daily_gust = wind['fields']['windgustmph']

        wind['fields']['maxdailygust'] = max_daily_gust

        data.append(wind)
        print(data)
        db_client.write_points(data,
                               database='weather_data',
                               retention_policy='one_year')
        for d in data:
            topic = MQTT_TOPIC + '/' + d['measurement'] + '/' + d['tags'][
                'sensorName']
            mq.send(topic, json.dumps(d))

        if loop_count >= 600 / wait_time:
            an.reset_gust()
            # wind_avg = []
            # winddir_avg = []
            loop_count = 0

        time.sleep(wait_time)

    pass
Пример #2
0
#!/usr/bin/env python3
"""Can be added to weathermon main or run stand-alone"""
import time
import lib.conversions as conv
import json
from lib.mqtt import Mqtt
from lib.influxdb import Influxdb
from lib.ownet import Ownet

HOSTS = ['localhost']

db = Influxdb(host='knode.ourhouse', port='8086')
db_client = db.client()

mq = Mqtt('192.168.1.104')
mq_topic = 'sun-chaser/weather'


def scan_1w_devices(hosts, sensors):

    for host in hosts:
        client = Ownet(host)

        for dev in client.devices:
            device = {
                'host': host,
                'device': dev,
                'type': client.read(dev, 'type')
            }
            sensors.append(device)
Пример #3
0
INDOOR = 0x12
OUTDOOR = 0x0E

GPIO.setmode(GPIO.BCM)
GPIO.setup(INTERRUPT_PIN, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

event_counter = {1: 0, 4: 0, 8: 0}
event = {'distance': 100, 'energy': 0}

l_count, d_count, n_count = 0, 0, 0

db = Influxdb(host='knode', port='8086')
db_client = db.client()
mq_topic = 'sun-chaser/lightning'
mq = Mqtt('192.168.1.10')

kaboom = []


def setup_db(client):
    client.create_database('sensors_test')
    client.create_retention_policy('oneday',
                                   '1d',
                                   '1',
                                   database='sensors_test')
    client.create_retention_policy('onemonth',
                                   '30d',
                                   '1',
                                   database='sensors_test')
Пример #4
0
def main():
    delay = 10
    retain = 600
    th = SHTC3()
    pr = LPS22HB()
    an = Anemometer(17)
    dr = ADS1015()
    mq = Mqtt('192.168.1.10')

    setup_db(client)
    an.start()
    loop_count = 0
    wind_avg = []
    owdevs = scan_1w_devices(ow_hosts)

    while True:
        loop_count += 1
        data = []
        w1_temp = False

        for dev in owdevs:
            # if len(owdevs) > 0:
            w1_temp = get_1w_temperature(dev)
            if w1_temp['fields']['tempc'] < 80:
                data.append(w1_temp)

        pressure = get_pressure(pr)
        data.append(pressure)

        temp_hum = get_temperature_and_humidity(th, 'SHTC3')
        data.append(temp_hum)

        wind = get_wind(an, dr)
        data.append(wind)
        wind_avg.append(wind['fields']['windspeed'])

        client.write_points(data,
                            database='sensors_test',
                            retention_policy='oneday')
        mq.send(mq_topic, json.dumps(data))

        if loop_count >= retain / delay:
            data[-1]['fields']['windspeed'] = get_average(wind_avg)
            client.write_points(data,
                                database='sensors_test',
                                retention_policy='onemonth')
            an.reset_gust()
            wind_avg = []
            loop_count = 0

        print("---[{}]---".format(time.asctime()))
        print("Pressure     : {:.2f}".format(pressure['fields']['pressure']))
        print("Temperature  : {:.2f}".format(temp_hum['fields']['tempf']))
        print("Humidity     : {:.2f} %".format(temp_hum['fields']['humidity']))
        print("Avg WindSpeed: {:.2f} Mph".format(get_average(wind_avg)))
        print("Wind Speed   : {:.2f} Mph".format(wind['fields']['windspeed']))
        print("Max Gust     : {:.2f} Mph".format(wind['fields']['gust']))
        print("Wind Dir     : {} | {}".format(wind['fields']['dir_text'],
                                              wind['fields']['dir_value']))
        if w1_temp:
            print("{: <12} : {:.2f}".format(w1_temp['tags']['sensorName'],
                                            w1_temp['fields']['tempf']))
        print("Next Update  : {} seconds".format(retain -
                                                 (loop_count * delay)))
        print("-----------------------------\n")
        time.sleep(delay)
Пример #5
0
#!/usr/bin/env python3

import time
import json
import lib.conversions as conv
from lib.mqtt import Mqtt
from lib.influxdb import Influxdb
from lib.waveplus import WavePlus

SERIAL_NUMBER = 2930108535  # set to match my device

MQTT_TOPIC = 'sun-chaser/weather'
mq = Mqtt('rpi4b-1.ourhouse')

db = Influxdb(host='knode.ourhouse', port='8086')
db_client = db.client()


def get_readings(device):
    data = []

    try:
        device.connect()
        sensor_data = device.read()
        device.disconnect()
    except:
        return False

    # Get the humidity reading from AirThings
    reading = {}
    reading['measurement'] = 'humidity'
Пример #6
0
#!/usr/bin/env python3
import secrets
import json
import time
from lib.mqtt import Mqtt
from lib.influxdb import Influxdb
from lib.ambientweather import AmbientWeather

MQTT_TOPIC = 'sun-chaser/weather/ambientweather'

aw = AmbientWeather(secrets.AMBIENT_API_KEY, secrets.AMBIENT_APPLICATION_KEY)
mq = Mqtt('192.168.1.10')
db = Influxdb(host='knode', port='8086')
db_client = db.client()


def type_adjustments(raw):
    for key in raw.keys():
        if isinstance(raw[key], int):
            raw[key] = float(raw[key])

    # Currently there are no celsius fields, let's add them
    if 'tempc' not in raw:
        raw['tempc'] = round((raw['tempf'] - 32) * (5 / 9), 1)
        raw['tempinc'] = round((raw['tempinf'] - 32) * (5 / 9), 1)
    return raw


def create_influx_data(raw):
    # type adjustments
    raw = type_adjustments(raw)