示例#1
0
    def setup(self, opts):
        # source of streaming data
        self.archiver_url = opts.pop('archiver_url', 'http://localhost:8079')
        # streaming data uuid
        self.oatuuid = opts.get('oatuuid')
        # subscribe to datastream
        restriction = "uuid = '{0}'".format(self.oatuuid)
        self.oatclient = RepublishClient(self.archiver_url,
                                         self.oatcb,
                                         restrict=restriction)

        self.cooluuid = opts.get('cooluuid')
        restriction = "uuid = '{0}'".format(self.cooluuid)
        self.coolclient = RepublishClient(self.archiver_url,
                                          self.coolcb,
                                          restrict=restriction)

        # rate between recalculating room model
        self.rate = float(opts.get('rate', 1))
        # thermal resistance of room
        self.therm_resistance = float(opts.get('therm_resistance', .1))
        # initial temperature of room
        self.temp = float(opts.get('starttemp', 75))
        # epsilon for room (for cooling)
        self.e = float(opts.get('epsilon', .1))

        # state vars
        self.oat_val = 0
        self.cool = 0

        self.add_timeseries('/currenttemp', 'F', data_type='double')
示例#2
0
	def setup(self, opts):
		self.add_timeseries('/beep', 'unit', data_type='double')
		self.archiverurl = opts.get('archiverurl','http://shell.storm.pm:8079')
		self.subscription = opts.get('subscription','Metadata/Sourcename = "BeepCommand"')
		self.r = RepublishClient(self.archiverurl, self.cb, restrict=self.subscription)
		self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
		self.target = opts.get("target", "2001:470:832b:2:212:6d02:0:3103")
示例#3
0
 def start(self):
     """Start receiving real-time data when used in daemon mode"""
     # set up clients to provide the data
     source = ['http://ar1.openbms.org:8079', 'http://ar2.openbms.org:8079']
     self.clients = []
     for url in source:
         self.clients.append(
             RepublishClient(url, self._data, restrict=self.restrict))
         self.clients[-1].connect()
示例#4
0
    def setup(self, opts):
        self.archiver_url = opts.pop('archiver_url', 'http://localhost:8079')
        self.oatpath = opts.pop('OATpath', '/OAT/temperature')
        self.coolpath = opts.pop('coolpath', '/control/cool')
        self.siteid = opts.pop('siteid', '')

        # Subscription to OAT stream, registering a callback
        restriction = "Path = '{0}'".format(self.oatpath)
        if self.siteid:
            restriction = restriction + " and Metadata/Site/id = '{0}'".format(
                self.siteid)
        self.oatclient = RepublishClient(self.archiver_url,
                                         self.oatcb,
                                         restrict=restriction,
                                         connect_error=self.badclient)

        # subscribe to the cool control stream
        restriction = "Path = '{0}'".format(self.coolpath)
        if self.siteid:
            restriction = restriction + " and Metadata/Site/id = '{0}'".format(
                self.siteid)

        self.coolclient = RepublishClient(self.archiver_url,
                                          self.coolcb,
                                          restrict=restriction,
                                          connect_error=self.badclient)

        # initalize parameters for the room model
        self.rate = float(opts.get('rate', 1))  # model update rate
        self.therm_resistance = float(opts.get(
            'therm_resistance', .1))  # thermal resistance factor
        self.e = float(opts.get('epsilon', .1))  # cooling factor

        # initial state of the room
        self.temp = float(opts.get('starttemp', 75))  # initial room
        self.oat_val = self.temp
        self.cool = 0

        # Create the timeseries for the pseudo air temp sensor
        self.add_timeseries('/airtemp', 'F', data_type='double')
示例#5
0
    def _check_alerts(self, alerts, requested_id=None):
        """Check to make sure we are sync'ed up with the database
        about which alerts we should be computing"""
        for a in alerts:
            self._clear_error(a)
            if not a.id in self.filters:
                self.filters[a.id] = {'pending': {}, 'states': {}}
            else:
                # if the query changed, reconnect with a new query
                if a.select != self.filters[a.id]['select']:
                    self.filters[a.id]['client'].close()
                    del self.filters[a.id]['client']
                    self.filgers[a.id] = {'pending': {}, 'states': {}}

            if a.id == requested_id:
                requested_id = None

            # update our comparators
            self.filters[a.id]['test'] = a.get_test()
            self.filters[a.id]['select'] = a.select
            self.filters[a.id]['current_level'] = a.current_level

            if not 'client' in self.filters[a.id]:

                def make_cbs():
                    id_ = a.id

                    def rxfn(data):
                        return self.data(id_, data)

                    def erfn(data):
                        return self._check_alert_error(id_, data)

                    return rxfn, erfn

                cb, eb = make_cbs()
                self.filters[a.id]['client'] = RepublishClient(
                    'http://ar1.openbms.org:8079/',
                    cb,
                    restrict=a.select,
                    connect_error=eb)
                self.filters[a.id]['client'].connect()

            # note that we poked this alert
            threads.deferToThread(self._save_check_time, a.id)

        if requested_id != None and requested_id in self.filters:
            # disable any ids that were requested but might have been
            # deleted or disabled.
            print "Disabling", requested_id
            self.filters[requested_id]['client'].close()
            del self.filters[requested_id]
示例#6
0
    def read_stream_data(self):
        self.points = {}
        self.repubclients = {}

        for name in self.input_variables:
            point = name.strip()
            self.points[point] = []
            self.repubclients[point] = [
                RepublishClient(self.archiver_url,
                                partial(self.cb, point),
                                restrict="Metadata/Name = '" + str(point) +
                                "'")
            ]
        for name in self.state_variables:
            point = name.strip()
            self.points[point] = []
            self.repubclients[point] = [
                RepublishClient(self.archiver_url,
                                partial(self.cb, point),
                                restrict="Metadata/Name = '" + str(point) +
                                "'")
            ]
    def setup(self, opts):
        self.rate = float(opts.get('rate', 1))
        self.add_timeseries('/temp', 'unit', data_type='double')
        self.set_metadata(
            '/temp', {
                'Metadata/Description': 'Application for rice cooker',
            })

        self.archiverurl = opts.get('archiverurl',
                                    'http://shell.storm.pm:8079')
        self.subscription = opts.get(
            'subscription', 'Metadata/SourceName = "Rice Cooker Sensor"')
        self.r = RepublishClient(self.archiverurl,
                                 self.cb,
                                 restrict=self.subscription)
示例#8
0
    def setup(self, opts):
        self.archiver_url = opts.pop('archiver_url', 'http://localhost:8079')
        self.sp = float(opts.get('setpoint', 78))
        self.db = float(opts.get('deadband', 1))
        self.rate = float(opts.get('rate', 1))

        # Initialize controller state
        self.cur_temp = self.sp
        self.state = 0  # initial cool is off

        # subscribe to zone air temperature
        self.zonepath = opts.pop('zonepath', '/room/airtemp')
        self.siteid = opts.pop('zonesiteid', '')
        restriction = "Path = '{0}'".format(self.zonepath)
        if self.siteid:
            restriction = restriction + " and Metadata/Site/id = '{0}'".format(
                self.siteid)
        self.roomclient = RepublishClient(self.archiver_url,
                                          self.controlcb,
                                          restrict=restriction)

        # create timeseries for contoller actions
        self.add_timeseries('/cool', 'On/Off', data_type='long')
示例#9
0
    def setup(self, opts):
        # source of streaming data
        self.archiver_url = opts.pop('archiver_url', 'http://localhost:8079')
        # streaming data uuid
        self.roomuuid = opts.get('roomuuid')
        # subscribe to datastream
        restriction = "uuid = '{0}'".format(self.roomuuid)
        self.roomclient = RepublishClient(self.archiver_url,
                                          self.controlcb,
                                          restrict=restriction)
        # setpoint
        self.sp = float(opts.get('setpoint', 72))
        # deadband
        self.db = float(opts.get('deadband', 1))
        # period between calling controller
        self.rate = float(opts.get('rate', 1))
        self.cool = 0  # off

        self.add_timeseries('/cool', 'On/Off', data_type='long')

        # initialize current temperature to setpoint
        self.cur_temp = self.sp

        self.cool_controller = cool_controller
    def setup(self, opts):
        self.state = {
            'temp': 70,
            'humidity': 50,
            'hvac_state': 1,
            'temp_heat': 70,
            'temp_cool': 75,
            'hold': 0,
            'override': 0,
            'hvac_mode': 1,
            'fan_mode': 1,
        }

        self.readperiod = float(opts.get('ReadPeriod', 3))
        self.add_timeseries('/temp', 'F', data_type='long')
        self.add_timeseries('/humidity', '%RH', data_type='long')
        self.add_timeseries('/hvac_state', 'Mode', data_type='long')
        temp_heat = self.add_timeseries('/temp_heat', 'F', data_type='long')
        temp_cool = self.add_timeseries('/temp_cool', 'F', data_type='long')
        hold = self.add_timeseries('/hold', 'On/Off', data_type='long')
        override = self.add_timeseries('/override', 'On/Off', data_type='long')
        hvac_mode = self.add_timeseries('/hvac_mode', 'Mode', data_type='long')
        fan_mode = self.add_timeseries('/fan_mode', 'Mode', data_type='long')

        temp_heat.add_actuator(
            SetpointActuator(tstat=self, path='temp_heat', _range=(45, 95)))
        temp_cool.add_actuator(
            SetpointActuator(tstat=self, path='temp_cool', _range=(45, 95)))
        hold.add_actuator(OnOffActuator(tstat=self, path='hold'))
        override.add_actuator(OnOffActuator(tstat=self, path='override'))
        hvac_mode.add_actuator(
            ModeActuator(tstat=self, path='hvac_mode', states=[0, 1, 2, 3]))
        fan_mode.add_actuator(OnOffActuator(tstat=self, path='fan_mode'))

        self.archiver_url = opts.pop('archiver_url', 'http://localhost:8079')
        self.heatSPpath = opts.pop('heatSPpath', '/scheduler/heatSetpoint')
        self.coolSPpath = opts.pop('coolSPpath', '/scheduler/coolSetpoint')
        # add mode
        self.siteid = opts.pop('siteid', '')
        restriction = "Path = '{0}'".format(self.heatSPpath)
        if self.siteid:
            restriction = restriction + " and Metadata/Site/id = '{0}'".format(
                self.siteid)
        self.heatSPclient = RepublishClient(self.archiver_url,
                                            self.heatSPcb,
                                            restrict=restriction)
        restriction = "Path = '{0}'".format(self.coolSPpath)
        if self.siteid:
            restriction = restriction + " and Metadata/Site/id = '{0}'".format(
                self.siteid)
        self.coolSPclient = RepublishClient(self.archiver_url,
                                            self.coolSPcb,
                                            restrict=restriction)

        metadata_type = [('/temp', 'Sensor'), ('/humidity', 'Sensor'),
                         ('/temp_heat', 'Reading'), ('/temp_heat_act', 'SP'),
                         ('/temp_cool', 'Reading'), ('/temp_cool_act', 'SP'),
                         ('/hold', 'Reading'), ('/hold_act', 'Command'),
                         ('/override', 'Reading'),
                         ('/override_act', 'Command'),
                         ('/hvac_mode', 'Reading'),
                         ('/hvac_mode_act', 'Command')]
        for ts, tstype in metadata_type:
            self.set_metadata(ts, {'Metadata/Type': tstype})