Пример #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 "."
Пример #2
0
 def execute(self):
     print "Fill device data table with sample data"
     t = datetime.datetime.today()
     td = datetime.timedelta(minutes=1)
     for i in range(100):
         d = DeviceData(node_id=1,device_id=1)
         t = t + td
         print t
         d.timestamp = t
         d.data = random.randint(0,100)
         d.bugnet = BugNet.objects.get(name='kerellou')
         d.save()