import json import sys __author__ = 'talbarda' import random import uuid from src.sensor.http_client import http_client from src.utilities.utils import get_conf, get_current_time import time import mraa import pyupm_grove as grove import math INTERVAL = get_conf().get_conf_value( full_name="sensor.update_seconds_interval", val_type=float, def_val=1) temperature_sensor = grove.GroveTemp(0) pressure_sensor = mraa.Aio(2) light = mraa.Gpio(2) light.dir(mraa.DIR_OUT) light_value = 0 light.write(light_value) def change_light(val): global light_value if light_value != val: light_value = val light.write(val) def collect_data():
import json import sys __author__ = 'talbarda' import random import uuid from src.sensor.http_client import http_client from src.utilities.utils import get_conf, get_current_time import time import mraa import pyupm_grove as grove import math INTERVAL = get_conf().get_conf_value(full_name="sensor.update_seconds_interval", val_type=float, def_val=1) temperature_sensor = grove.GroveTemp(0) pressure_sensor = mraa.Aio(2) light = mraa.Gpio(2) light.dir(mraa.DIR_OUT) light_value = 0 light.write(light_value) def change_light(val): global light_value if light_value!=val: light_value=val light.write(val) def collect_data(): return dict(ts=str(get_current_time()), uid=str(uuid.uuid1()), temperature=get_temp(),
from src.utilities.utils import get_conf __author__ = 'talbarda' import httplib import json CONF_SECTION = "http_server" conf = get_conf() DEF_HOST = conf.get_conf_value(full_name="%s.host" % CONF_SECTION, val_type=str, def_val="localhost") DEF_METHOD = conf.get_conf_value(full_name="%s.method" % CONF_SECTION, val_type=str, def_val="GET") DEF_PORT = conf.get_conf_value(full_name="%s.port" % CONF_SECTION, val_type=int, def_val=8080) DEF_TIMEOUT = get_conf().get_conf_value(full_name="%s.timeout" % CONF_SECTION, val_type=int, def_val=10) class http_client(object): def __init__(self, host=DEF_HOST, method=DEF_METHOD, port=DEF_PORT, timeout=DEF_METHOD): self.http_conn = httplib.HTTPConnection(host, port, timeout) self.is_opened = True self.request_method = method self.headers = {"content-type": 'application/json'} def __enter__(self): return self def __exit__(self, type, value, traceback): try: if self.is_opened: self.http_conn.close() self.is_opened = False print "closed"
from src.utilities.utils import get_conf __author__ = 'talbarda' import httplib import json CONF_SECTION = "http_server" conf = get_conf() DEF_HOST = conf.get_conf_value(full_name="%s.host" % CONF_SECTION, val_type=str, def_val="localhost") DEF_METHOD = conf.get_conf_value(full_name="%s.method" % CONF_SECTION, val_type=str, def_val="GET") DEF_PORT = conf.get_conf_value(full_name="%s.port" % CONF_SECTION, val_type=int, def_val=8080) DEF_TIMEOUT = get_conf().get_conf_value(full_name="%s.timeout" % CONF_SECTION, val_type=int, def_val=10) class http_client(object): def __init__(self, host=DEF_HOST, method=DEF_METHOD, port=DEF_PORT, timeout=DEF_METHOD): self.http_conn = httplib.HTTPConnection(host, port, timeout) self.is_opened = True