示例#1
0
 def publish_to_smap(self, smap_identifier, value, smap_identifier2,
                 value2, time_value):
     '''
     Push diagnostic results and energy
     impact to sMAP historian.
     '''
     self._log.debug(''.join(['Push to sMAP - ', smap_identifier, str(dx_msg),
                              ' Energy Impact: ', str(energy_impact)]))
     if time_value is None:
         mytime = int(time.time())
     else:
         mytime = time.mktime(time_value.timetuple())
     if value2 is not None:
         content = {
             smap_identifier: {
                  "Readings": [[mytime, value]],
                  "Units": "TU",
                  "data_type": "double"
              },
               smap_identifier2: {
                  "Readings": [[mytime, value2]],
                  "Units": "kWh/h",
                  "data_type": "double"}
          }
     else:
         content = {
             smap_identifier: {
                  "Readings": [[mytime, value]],
                  "Units": "TU",
                  "data_type": "double"
              }
         }
     self._agent.publish(self.smap_path, self.headers, jsonapi.dumps(content))
示例#2
0
        def on_received_message(self, topic, headers, message, matched):
            _log.debug("Message received")
            _log.debug("MESSAGE: "+ jsonapi.dumps(message[0]))
            _log.debug("TOPIC: "+ topic)
            data = jsonapi.loads(message[0])

            results = app_instance.run(datetime.now(),data)
            self._process_results(results)
示例#3
0
        def on_received_message(self, topic, headers, message, matched):
            _log.debug("Message received")
            _log.debug("MESSAGE: " + jsonapi.dumps(message[0]))
            _log.debug("TOPIC: " + topic)
            data = jsonapi.loads(message[0])

            results = app_instance.run(datetime.now(), data)
            self._process_results(results)
示例#4
0
        def on_received_message(self, topic, headers, message, matched):
            '''Subscribe to device data and convert data to correct type for
            the driven application.
            '''
            _log.debug("Message received")
            _log.debug("MESSAGE: " + jsonapi.dumps(message[0]))
            _log.debug("TOPIC: " + topic)
            data = jsonapi.loads(message[0])

            #TODO: grab the time from the header if it's there or use now if not
            self.received_input_datetime = datetime.utcnow()
            results = app_instance.run(self.received_input_datetime, data)
            self._process_results(results)
示例#5
0
 def on_received_message(self, topic, headers, message, matched):
     '''Subscribe to device data and convert data to correct type for
     the driven application.
     '''
     _log.debug("Message received")
     _log.debug("MESSAGE: " + jsonapi.dumps(message[0]))
     _log.debug("TOPIC: " + topic)
     data = jsonapi.loads(message[0])
     
     #TODO: grab the time from the header if it's there or use now if not
     self.received_input_datetime = datetime.utcnow()
     results = app_instance.run(self.received_input_datetime, data)
     self._process_results(results)
示例#6
0
        def on_received_message(self, topic, headers, message, matched):
            '''Subscribe to device data and convert data to correct type for
            the driven application.
            '''
            _log.debug("Message received")
            _log.debug("MESSAGE: " + jsonapi.dumps(message[0]))
            _log.debug("TOPIC: " + topic)
            data = jsonapi.loads(message[0])
            if not converter.initialized and \
                config.get('conversion_map') is not None:
                converter.setup_conversion_map(config.get('conversion_map'),
                                               data.keys())
            data = converter.process_row(data)

            results = app_instance.run(datetime.now(), data)
            self._process_results(results)
示例#7
0
        def on_received_message(self, topic, headers, message, matched):
            '''Subscribe to device data and convert data to correct type for
            the driven application.
            '''
            _log.debug("Message received")
            _log.debug("MESSAGE: " + jsonapi.dumps(message[0]))
            _log.debug("TOPIC: " + topic)
            data = jsonapi.loads(message[0])
            if not converter.initialized and \
                config.get('conversion_map') is not None:
                converter.setup_conversion_map(config.get('conversion_map'),
                                               data.keys())
            data = converter.process_row(data)

            results = app_instance.run(datetime.now(), data)
            self._process_results(results)
示例#8
0
文件: agent.py 项目: devmull/volttron
 def publish_data_or_heartbeat(self):
     '''Publish data from file to message bus.'''
     published_data = {}
     now = datetime.datetime.now().isoformat(' ')
     if not self._src_file_handle.closed:
         line = self._src_file_handle.readline()
         line = line.strip()
         data = line.split(',')
         if line:
             # Create 'all' message
             for i in xrange(0, len(self._headers)):
                 published_data[self._headers[i]] = data[i]
             if custom_topic:
                 data_dict = jsonapi.dumps(published_data)
                 self.publish(
                     custom_topic, {
                         HEADER_NAME_CONTENT_TYPE: MIME_PLAIN_TEXT,
                         HEADER_NAME_DATE: now
                     }, data_dict)
                 return
             device_dict = {}
             ukey = ''
             kval = None
             for key, value in published_data.iteritems():
                 for item in subdev_list:
                     ukey = key
                     kval = value
                     if item in key:
                         ukey = ''
                         kval = None
                         break
                 if ukey:
                     device_dict.update({ukey: kval})
             # Pushing out the data
             if not device_dict and not subdev_list:
                 device_dict = published_data
             device_dict = jsonapi.dumps(device_dict)
             if device_dict:
                 self.publish(
                     BASETOPIC + '/' + device_path + '/all', {
                         HEADER_NAME_CONTENT_TYPE: MIME_PLAIN_TEXT,
                         HEADER_NAME_DATE: now
                     }, device_dict)
             device_dict = {}
             for item in subdev_list:
                 for key, value in published_data.iteritems():
                     if key.startswith(item):
                         pub_key = key[len(item):]
                         device_dict.update(
                             {pub_key.split('_')[1]: value})
                 device_dict = jsonapi.dumps(device_dict)
                 topic = (BASETOPIC + '/' + device_path + '/' + item +
                          '/all')
                 self.publish(
                     topic, {
                         HEADER_NAME_CONTENT_TYPE: MIME_PLAIN_TEXT,
                         HEADER_NAME_DATE: now
                     }, device_dict)
                 device_dict = {}
         else:
             self._src_file_handle.close()
     else:
         self.publish(
             'heartbeat/DataPublisher', {
                 'AgentID': self._agent_id,
                 HEADER_NAME_CONTENT_TYPE: MIME_PLAIN_TEXT,
                 HEADER_NAME_DATE: now,
             }, now)