libdo

Untitled

Sep 29th, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import sys
  2. from tinyos import tos
  3.  
  4. """
  5. Jacks Version
  6. """
  7.  
  8. CHANNEL = 6
  9.  
  10. class BroadcastPacket(tos.Packet):
  11.  
  12.     def __init__(self, packet = None):
  13.         print 'Debug: initialised bPacket'
  14.  
  15.         tos.Packet.__init__(self,
  16.             [('node_id', 'int', 2),
  17.              ('hopCount', 'int', 1),
  18.              ('temperature', 'int', 2),
  19.              ('light', 'int', 2),
  20.              ('humidity', 'int', 2),
  21.              ('TTL', 'int', 1),
  22.              ('TSN', 'int', 2)], packet)
  23.  
  24. if '-h' in sys.argv:
  25.     print "Usage:", sys.argv[0], "serial@/dev/ttyUSB0:115200"
  26.     sys.exit()
  27.  
  28. am = tos.AM()
  29.  
  30. while True:
  31.     p = am.read()
  32.     if p and p.type == CHANNEL:
  33.         msg = BroadcastPacket(p.data)
  34.         print "Payload\nFrom: {}\nHop Count: {}\nTemp: {}\nLight: {}\nHumidity: {}\nTTL: {}\nTSN: {}\n\n".format(
  35.             msg.node_id,
  36.             msg.hopCount,
  37.             msg.temperature,
  38.             msg.light,
  39.             msg.humidity,
  40.             msg.TTL,
  41.             msg.TSN)
Add Comment
Please, Sign In to add comment