示例#1
0
def handle_payload(ev):
    msg = ev.msg
    parser = SafeConfigParser()
    parser.read('data.ini')
#    section = parser.sections()
    
    if msg.payload is not None:
        data = msg.payload
        data = str(data)
        try:
            data2 = json.loads(data)
        except ValueError:
            return
    
#    for section_name in parser.sections():
#          if section_name == ''
    for name in parser.items('Open.sen'):
        print name[0]
        if name[0] == data2['id']:
            sen_id = name[1]
            value = data2['value']
            print sen_id
            datastream = data2['id']
            if sen_id not in OpenSense.feed_ids:
                length = len(OpenSense.feed_ids)
                OpenSense.feed_ids[length] = sen_id
                
#        transmit data to sense
                api = parser.get('API', 'Open.sen')
                packet = OpenSensePacket(api, [(sen_id,value)])
                print "Sen.se status = ", packet.push()
                print datastream
                print value
示例#2
0
def handle_payload(ev):
    msg = ev.msg
    parser = SafeConfigParser()
    parser.read('data.ini')
    #    section = parser.sections()

    if msg.payload is not None:
        data = msg.payload
        data = str(data)
        try:
            data2 = json.loads(data)
        except ValueError:
            return


#    for section_name in parser.sections():
#          if section_name == ''
    for name in parser.items('Open.sen'):
        print name[0]
        if name[0] == data2['id']:
            sen_id = name[1]
            value = data2['value']
            print sen_id
            datastream = data2['id']
            if sen_id not in OpenSense.feed_ids:
                length = len(OpenSense.feed_ids)
                OpenSense.feed_ids[length] = sen_id

                #        transmit data to sense
                api = parser.get('API', 'Open.sen')
                packet = OpenSensePacket(api, [(sen_id, value)])
                print "Sen.se status = ", packet.push()
                print datastream
                print value
示例#3
0
文件: api.py 项目: Pepe74/panstamp
    def push_opensense(endp, sense_key, feed_id):
        """
        Push data to open.sen.se

        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id        
        @param sense_key: open.sen.se API key
        @param feed_id: open.sen.se feed ID
        
        @return HTTP response from open.sen.se
        """
        try:
            endpoint = NetworkAPI.get_endpoint(endp)
            if endpoint is not None:
                endpstr = endpoint.procname + "." + endpoint.location + "." + endpoint.name
                if endpstr not in OpenSense.feed_ids:
                    OpenSense.feed_ids[endpstr] = feed_id
                packet = OpenSensePacket(sense_key, [(feed_id, endpoint.value)])
                return packet.push()
            return None
        except LagartoException as ex:
            ex.log()
示例#4
0
    def push_opensense(endp, sense_key, feed_id):
        """
        Push data to open.sen.se

        @param endp: endpoint identification string
        format 1: process.location.name
        format 2: process.id        
        @param sense_key: open.sen.se API key
        @param feed_id: open.sen.se feed ID
        
        @return HTTP response from open.sen.se
        """
        try:
            endpoint = NetworkAPI.get_endpoint(endp)
            if endpoint is not None:
                endpstr = endpoint.procname + "." + endpoint.location + "." + endpoint.name
                if endpstr not in OpenSense.feed_ids:
                    OpenSense.feed_ids[endpstr] = feed_id
                packet = OpenSensePacket(sense_key,
                                         [(feed_id, endpoint.value)])
                return packet.push()
            return None
        except LagartoException as ex:
            ex.log()