Exemple #1
0
    def execute(self):
        bugnet_name = 'kerellou'
        device = "/dev/ttyUSB0"

        bugnet = BugNet.objects.get(name=bugnet_name)
        print "Logging data of %s bugnet" % bugnet_name

        sniffer = rfm12.SnifferSerial(device)

        while True:
            msg = sniffer.waitForMessage()
            if msg:
                print "#"
                msgType = bugOne.getPacketType(msg)
                srcNodeId = bugOne.getPacketSrc(msg)

                if msgType == bugOne.PACKET_VALUES:
                    print "@"
                    values = bugOne.readValues(bugOne.getPacketData(msg))
                    print values

                    for (srcDevice,dstDevice,value) in values:
                        d = DeviceData()
                        d.timestamp = datetime.datetime.today()
                        d.bugnet = bugnet
                        d.node_id = srcNodeId
                        d.device_id = srcDevice
                        d.data = value
                        d.save()

                        print d

            else:
                print "."
Exemple #2
0
    def execute(self):
        bugnet_name = 'kerellou'
        device = "/dev/ttyUSB0"

        bugnet = BugNet.objects.get(name=bugnet_name)
        print "Logging data of %s bugnet" % bugnet_name

        sock = socket()
        try:
            sock.connect((CARBON_SERVER,CARBON_PORT))
        except:
            print "Couldn't connect to %(server)s on port %(port)d, is carbon-agent.py running?" % { 'server':CARBON_SERVER, 'port':CARBON_PORT }
            sys.exit(1)

        sniffer = rfm12.SnifferSerial(device)

        while True:
            msg = sniffer.waitForMessage()
            if msg:
                print "#"
                msgType = bugOne.getPacketType(msg)
                srcNodeId = bugOne.getPacketSrc(msg)
		try:
                	srcNode = BugNetNode.objects.get(node_id=srcNodeId)
                	srcNodeName = srcNode.location
		except BugNetNode.DoesNotExist:
			print "%d device not defined" % srcNodeId
		except Exception as e:
			print e
			

                if msgType == bugOne.PACKET_VALUES:
                    print "@"
                    values = bugOne.readValues(bugOne.getPacketData(msg))
                    print values

                    now = int(time.time())
                    lines = []
                    #lines.append("%s.%s.%s %s %d" % (bugnet_name,srcNodeId,srcDevice,values,now))

                    for (srcDevice,dstDevice,value) in values:
                        srcDevice = BugNetDevice.objects.get(device_id=srcDevice,node=srcNode)
                        srcDeviceName = srcDevice.device_description
                        lines.append("%s.%s.%s %s %d" %
                                (bugnet_name,srcNodeName,srcDevice,value,now))

                    message = '\n'.join(lines) + '\n'
                    print message
                    sock.sendall(message)
Exemple #3
0
sniffer = rfm12.SnifferSerial(device)

bugOne.ping(0x1, sniffer)

while True:
	message = sniffer.waitForMessage()
	if message:
		messageType = bugOne.getPacketType(message)
		srcNodeId = bugOne.getPacketSrc(message)
		destNodeId = bugOne.getPacketDest(message)
		counter = bugOne.getPacketCounter(message)
		print "Message [%s] from %s to %s" % (counter, hex(srcNodeId), hex(destNodeId))
		if messageType == bugOne.PACKET_HELLO:
			print "Hello"
		elif messageType == bugOne.PACKET_PING:
			print "Ping"
		elif messageType == bugOne.PACKET_PONG:
			print "Pong"
		elif messageType == bugOne.PACKET_VALUES:
			values = bugOne.readValues(bugOne.getPacketData(message))
			for (srcDevice, destDevice, value) in values:
				print "- (%s.%s) -> (%s.%s) = %s" % \
					(srcNodeId, srcDevice, destNodeId, destDevice, value)
		else:
			print [hex(ord(i)) for i in bugOne.getPacketData(message)]
	else:
		sys.stdout.write(".")
		sys.stdout.flush()