Beispiel #1
0
from friskby_gw import FriskByGW


<<<<<<< Updated upstream
gw = FriskByGW( )
key = "00001111-2222-3333-4444-555566667777"
sensor_id = "RANDOM"
sensor = gw.getSensor( sensor_id , key = key )
=======
gw = FriskByGW( url = "http://127.0.0.1:8000/" )
sensor_id = "RANDOM"
sensor_id = "TEST1"
sensor = gw.getSensor(sensor_id)
>>>>>>> Stashed changes
if sensor is None:
    msg = "Sorry - the friskby server at:%s does not have a %s sensor - add that manually first." % (gw.getRootURL() , sensor_id)
    sys.exit( msg )

num = 1
min_value = sensor.getMinValue( )
max_value = sensor.getMaxValue( )
sleep_time = 1
corr = 0.90

if len(sys.argv) > 1:
    num = int(sys.argv[1])

try:
    last_value = sensor.getLastValue( )[1]
except Exception:
    last_value = 0.50 * (min_value + max_value)
Beispiel #2
0
import requests
import random
import datetime
from friskby_gw import FriskByGW

sensor_map = {
    "MET:TEMP:FLORIDA":
    "http://www.yr.no/place/Norway/Hordaland/Bergen/Bergen_(Florida)_observation_site/varsel.xml",
    "MET:TEMP:BLINDERN":
    "http://www.yr.no/place/Norway/Oslo/Oslo/Blindern/varsel.xml"
}

key = "00001111-2222-3333-4444-555566667777"
gw = FriskByGW()
for sensor_id, url in sensor_map.items():
    sensor = gw.getSensor(sensor_id, key=key)
    if sensor is None:
        msg = "Sorry - the friskby server at:%s does not have a %s sensor - add that manually first." % (
            gw.getRootURL(), sensor_id)

    response = requests.get(url)
    if response.status_code == 200:
        source = response.text
        tree = ET.fromstring(source.encode("utf-8"))
        temp_node = tree.find("observations").find("weatherstation").find(
            "temperature")

        temp = float(temp_node.get("value"))
        ts = temp_node.get("time")
        sensor.postValue(temp, timestamp=ts)