def start(self): ''' Iniatilizes the server. Any code meant to be run at init should be here. ''' if not self.sseRunning: self.sseRunning = True self.sampler = samplers.Periodic(self.ssePeriod) self._running = True
def sampling_method(self): self.sampling_method = self.variable_config[0]['sampling']['type'] if self.sampling_method == 'PeriodicSampler': #self.first_sample = float(self.general_config['PeriodicSampler']['first_sampling']) self.period = float( self.general_config['PeriodicSampler']['period']) self.s = samplers.Samplers.Signal() self.sampler = samplers.Periodic(self.period, self.s) elif self.sampling_method == 'PeriodicSoD': #self.first_sample = float(self.general_config['PeriodicSendOnDelta']['first_sampling']) self.period = float( self.general_config['PeriodicSendOnDelta']['period']) #self.s = samplers.Signal() self.s = samplers.Samplers.Signal() self.threshold = float( self.variable_config[0]['sampling']['params']['delta']) #self.sampler = samplers.SoDsampler(self.first_sample, self.period, self.s, self.threshold) self.sampler = samplers.Samplers.PeriodicSoD( self.period, self.s, self.threshold) else: print('sampling method dont found')
def nextSample(self): ''' Retrieve the next periodic update ''' # TO DO: Remove this code and start when the first client arrives if not self.sseRunning: self.sseRunning = True self.sampler = samplers.Periodic(self.ssePeriod) while self.sseRunning: self.sampler.wait() try: self.preGetValuesToNotify() toReturn = self.getValuesToNotify() self.postGetValuesToNotify() except: toReturn = 'ERROR' response = { "result": toReturn } event = 'periodiclabdata' id = round(self.sampler.time * 1000) data = ujson.dumps(response) yield 'event: %s\nid: %s\ndata: %s\n\n' % (event, id, data)