Exemplo n.º 1
0
    def data_available(self):
        if not self.netatmoDevList:

            if self.natatmoAuthorization == None:
                config = ConfigParser.ConfigParser()
                config.read("netatmo-auth.cfg")

                if config.get("Netatmo_Auth", "clientsecret") == "":
                    raise RuntimeError('Netatmo authentication information are missing in netatmo-auth.cfg')

                self.natatmoAuthorization = lnetatmo.ClientAuth( clientId = config.get("Netatmo_Auth", "clientid"),
                                                                 clientSecret = config.get("Netatmo_Auth", "clientsecret"),
                                                                 username = config.get("Netatmo_Auth", "username"),
                                                                 password = config.get("Netatmo_Auth", "password") )

                if self.natatmoAuthorization == None:
                    print('Netatmo authentication failed')
                    return False
            
            self.netatmoDevList = lnetatmo.DeviceList(self.natatmoAuthorization)

            if self.netatmoDevList == None:
                print('Could not get Netatmo device list')
                return False

        self.humidity = self.netatmoDevList.lastData()[self.netatmoName]['Humidity']
        self.temperature = self.netatmoDevList.lastData()[self.netatmoName]['Temperature']

        return True
Exemplo n.º 2
0
    def update(self):
        """Call the Netatmo API to update the data."""
        import lnetatmo
        dev_list = lnetatmo.DeviceList(self.auth)

        if self.station is not None:
            self.data = dev_list.lastData(station=self.station, exclude=3600)
        else:
            self.data = dev_list.lastData(exclude=3600)
Exemplo n.º 3
0
def get_weather(device_id,
                client_id,
                client_secret,
                username,
                password,
                station_id=None):
    weather = {}
    weather['wind_direction'] = '...'
    weather['wind_speed'] = '...'
    weather['gust'] = '...'
    weather['temperature'] = '...'
    weather['rain_1hr'] = '...'
    weather['rain_24hr'] = '...'
    weather['rain_midnight'] = '...'
    weather['humidity'] = '..'
    weather['pressure'] = '.....'

    authorization = lnetatmo.ClientAuth(client_id, client_secret, username,
                                        password)

    device_list = lnetatmo.DeviceList(authorization)
    if not device_id in device_list.stations:
        return

    device_data = device_list.stations[device_id]
    place_data = device_data['place']

    # Select between Station ('Indoor' v 'Outdoor') and Dashboard Data.
    if station_id is not None:
        readings = device_list.lastData()[station_id]
        last_reading = readings['When']
    else:
        readings = device_data['dashboard_data']
        last_reading = readings['time_utc']

    # Humidity is an acceptable format for APRS:
    weather['humidity'] = readings['Humidity']

    # Convert C to F for APRS:
    weather['temperature'] = netatmoaprs.c2f(readings['Temperature'])

    # Convert float to APRS format:
    if 'Pressure' in readings:
        weather['pressure'] = str(readings['Pressure']).replace('.', '')

    # Convert UTC Epoch to DHM Zulu:
    weather['timestamp'] = time.strftime('%d%H%M', time.gmtime(last_reading))

    # Get location data and convert to APRS format:
    weather['latitude'] = aprs.geo_util.dec2dm_lat(place_data['location'][1])
    weather['longitude'] = aprs.geo_util.dec2dm_lng(place_data['location'][0])

    frame = "@%sz%s/%s_%s/%sg%st%03dr%sp%sP%sh%02db%sNttm" % (
        weather['timestamp'],
        weather['latitude'],
        weather['longitude'],
        weather['wind_direction'][:3],
        weather['wind_speed'][:3],
        weather['gust'][:3],
        weather['temperature'],
        weather['rain_1hr'][:3],
        weather['rain_24hr'][:3],
        weather['rain_midnight'][:3],
        weather['humidity'],
        weather['pressure'],
    )
    return frame
#!/bin/python
# -*- coding: utf-8 -*-

import time
import json
import lnetatmo

authorization = lnetatmo.ClientAuth()
devList = lnetatmo.DeviceList(authorization)

module_dict = {}

for module, moduleData in devList.lastData(exclude=3600).items():
    sensor_dict = {}
    for sensor, value in moduleData.items():
        if sensor == "When":
            value = time.strftime("%H:%M:%S", time.localtime(value))
        sensor_dict.update({sensor: value})
    module_dict.update({module: sensor_dict})

print(json.dumps(module_dict))
Exemplo n.º 5
0
 def update(self):
     """ Call the NetAtmo API to update the data. """
     import lnetatmo
     # Gets the latest data from NetAtmo. """
     dev_list = lnetatmo.DeviceList(self.auth)
     self.data = dev_list.lastData(exclude=3600)
Exemplo n.º 6
0
def main():
    # Main program block
    # Initialise display
    lcd_init()

    napis = "Opakovani n="

    while True:
        #           12345678901234567890
        lcd_string("Getting tempture1...", LCD_LINE_1)
        lcd_string("From NetAtmo and ", LCD_LINE_2)
        lcd_string("From DS18B20 sensor", LCD_LINE_3)
        lcd_string("Dvorek,puda,pudicka", LCD_LINE_4)
        #req = "Teplota 00 :-("
        datumcas = datetime.datetime.now().strftime("Cas: %Y-%m-%d %H:%M:%S")
        dvorek = "000"
        puda = "000"

        try:
            reqt = requests.get('http://www.t1.cz/puda.temp', timeout=10)
            esp8266 = reqt.text.rstrip()
            tlak = esp8266.split(' ')
            akt = float(tlak[0][:-2])
            atm = float(tlak[1][:-3])
            # Math Expression to count pressure to the sea level:
            # ( pressure * 9.80665 * meters_above_sea ) / (273 + actual_temperature + (meters_above_sea/400)) + pressure
            vypocet = (atm * 9.80665 * mnm) / (287 * (273 + akt +
                                                      (mnm / 400))) + atm
            tlak_hladina = int(round(vypocet))
            esp_line = "ESP: " + str(akt) + "C, " + str(tlak_hladina) + "hPa"
        except requests.exceptions.RequestException as reqt:
            print datumcas
            print reqt
            esp8266 = "ESP nejede"

        try:
            # 1 : Authenticate NetAtmo
            authorization = lnetatmo.ClientAuth()
            # 2 : Get devices list
            devList = lnetatmo.DeviceList(authorization)
        except IOError:
            print "IOError"

        dvorek = devList.lastData("Plzenska")['dvorek']['Temperature']
        puda = devList.lastData("Plzenska")['puda']['Temperature']
        netatmo = str(dvorek) + ", " + str(puda)
        datum = datetime.datetime.now().strftime("Date: %Y-%m-%d")
        fo = open(TEMPERFILE, "w")
        fo.write(netatmo)
        fo.close()
        for i in range(REVOL):
            if (GPIO.input(19)):
                LCD_BACKLIGHT = 0x08  # On
            else:
                LCD_BACKLIGHT = 0x00  # Off

            #print("LCD Backlight")
            #print(LCD_BACKLIGHT)
            #lcd_byte(0x0C, LCD_CMD)

            cas = datetime.datetime.now().strftime("%H:%M:%S %d.%m.%Y")
            lcd_string("Venku: " + str(dvorek) + "C..W" + str(i), LCD_LINE_1)
            lcd_string(" Puda: " + str(puda) + "C", LCD_LINE_2)
            lcd_string(esp_line, LCD_LINE_3)
            lcd_string(cas, LCD_LINE_4)

            time.sleep(SLEEPTIME)