Beispiel #1
0
def detect(pi, baud_rate):
    rx = vw.rx(pi, PIGPIO_PIN, baud_rate)
    found = False
    start = time.time()
    while time.time() - start < 30:
        while rx.ready():
            found = True
    rx.cancel()
    return found
	def getLevel(self):
    
		pi = pigpio.pi()
		self.rx = vw.rx(pi, self.pin, self.bps)
		while True:
		    if not self.rx.ready():
		        time.sleep(0.1)
		    else:
		        msg = "".join(chr (c) for c in self.rx.get())
		        #self.logger.debug("Received msg: " + msg  #Complete Message
		        self.logger.debug("Received distance: " + msg[10:len(msg)-1])  #only level
		        if msg[len(msg)-1] == '$':
		        	break
		data = {}
		data['level'] = msg[10:len(msg)-1]
			
		level = msg[10:len(msg)-1]
		self.rx.cancel()
		pi.stop()
		
		return level
Beispiel #3
0
if __name__ == "__main__":

   import time

   import pigpio

   import vw

   RX=22

   BPS=2000

   pi = pigpio.pi() # Connect to local Pi.

   rx = vw.rx(pi, RX, BPS) # Specify Pi, rx gpio, and baud.

   msg = 0

   start = time.time()

   while (1):

      msg += 1

      if rx.ready():
         print("".join(chr (c) for c in rx.get()))

   rx.cancel()

   pi.stop()
Beispiel #4
0
    #get eth0 ip address
    def get_ip_address(ifname):
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        return socket.inet_ntoa(
            fcntl.ioctl(
                s.fileno(),
                0x8915,  # SIOCGIFADDR
                struct.pack('256s', ifname[:15]))[20:24])

    ip = get_ip_address('eth0')
    RX = 17
    BPS = 2000

    pi = pigpio.pi()  # Connect to local Pi.

    rx = vw.rx(pi, RX, BPS)  # Specify Pi, rx gpio, and baud.

    msg = 0
    start = time.time()
    #while (time.time()-start) < 300:
    while (1):
        while rx.ready():
            count += 1
            raz = "".join(chr(c) for c in rx.get())
            l = list(raz)
            #print raz
            #print raz[0:2]
            #print(count,"-".join(chr (c) for c in rx.get()))
            #for c in rx.get():
            #c=chr(c)
            #print c
Beispiel #5
0
    parser = argparse.ArgumentParser()
    parser.add_argument("-p", "--pubnub", help="listen for 'radio' updates on pubnub channel (for testing)", action="store_true", default=False)
    parser.add_argument("--noradio",  help="do NOT listen for updates on radio (e.g. not present)", action="store_true", default=False)
    parser.add_argument("-c", "--conf", help="path to config file (default %s)" % config_file, default=config_file)
    args = parser.parse_args()

    config = TurdConf(os.path.expanduser(args.conf))

    pubnub = Pubnub(publish_key=config.pubnub['publish_key'], subscribe_key=config.pubnub['subscribe_key'], ssl_on=False)

    radio_rx = None
    if not args.noradio:       # yes, this is tortured
        import vw
        logger.info("instantiating radio")
        pi = pigpio.pi() # Connect to local Pi.
        radio_rx = vw.rx(pi, radio_rx, radio_bps) # Specify Pi, rx gpio, and baud.
   
    pubnub_radio = None
    if args.pubnub:
        pubnub_radio = PubNubRadio(pubnub, config.pubnub['radio_channel'])

    while (1):
        parsed_message = None

        if pubnub_radio and pubnub_radio.ready():
           received_string = pubnub_radio.pop()
           logger.info("received pubnub radio message: %s" % received_string)
           parsed_message = parse_message(received_string)
        elif radio_rx and radio_rx.ready():
           received = radio_rx.get()
           received_string = "".join(chr(c) for c in received[4:])
Beispiel #6
0
#!/usr/bin/env python

if __name__ == "__main__":

   import time
   import pigpio
   import vw

   RX=20
   TX=25

   BPS=2000

   pi = pigpio.pi() # Connect to local Pi.

   rx = vw.rx(pi, RX, BPS) # Specify Pi, rx GPIO, and baud.
   tx = vw.tx(pi, TX, BPS) # Specify Pi, tx GPIO, and baud.

   msg = 0

   start = time.time()

   while (time.time()-start) < 300:

      msg += 1

      #while not tx.ready():
      #   time.sleep(0.02)

      #time.sleep(0.1)
Beispiel #7
0
Nécessite la présence du fichier vw.py dans le 
même répertoire.
http://www.raspberrypi.org/forums/viewtopic.php?t=84596&p=598087

'''
import time
import pigpio

import vw

RX=11

BPS=2000

pi = pigpio.pi() 

rx = vw.rx(pi, RX, BPS) 

start = time.time()

print("En attente de la reception des donnees")

while (time.time()-start) < 10000:

    while rx.ready():
        print("".join(chr (c) for c in rx.get()))

rx.cancel()

pi.stop()
Beispiel #8
0
 def __init__(self):
     self.pi = pigpio.pi()
     self.rx = vw.rx(self.pi, LED_COM_RX, LED_COM_BPS)
import time
import pigpio
import vw
import sys

RX = 27
BPS = 128

pi = pigpio.pi()

if not pi.connected:
    exit(0)

rx = vw.rx(pi, RX, BPS)

while True:
    while rx.ready():
        print('{ "data": [' + ', '.join(str(e) for e in rx.get()) +
              '], "time": ' + str(round(time.time() * 1000)) + ' }')
    time.sleep(1)
    sys.stdout.flush()

rx.cancel()
pi.stop()
      self.cb = None

if __name__ == "__main__":

   import time
   import pigpio
   import vw

   RX=27
#   TX=21

   BPS=2000

   pi = pigpio.pi() # Connect to local Pi.

   rx = vw.rx(pi, RX, BPS) # Specify Pi, rx GPIO, and baud.
#   tx = vw.tx(pi, TX, BPS) # Specify Pi, tx GPIO, and baud.

   msg = 0

   start = time.time()

   while (time.time()-start) < 300:

      msg += 1

      while not tx.ready():
         time.sleep(0.02)

      time.sleep(0.1)
Beispiel #11
0
import pigpio
import vw
import time
import sqlite3

#GPIO pin for receiver
RXPin = 27

#Radio rate in bps
rate = 2000

#This server address
address = 1

pi = pigpio.pi()
receiver = vw.rx(pi, RXPin, rate)

print("Starting receiver")

#Set redundant check variables
lastprobe = 0
lastid = 0
lastflag = 0

#Runs forever listening to messages
while True:
    time.sleep(0.5)
    message = []

    #Receive message, a list of Ints
    while receiver.ready():
Beispiel #12
0
def handle_pdb(sig, frame):
  print('debug')
  pdb.Pdb().set_trace(frame)
signal.signal(signal.SIGUSR1, handle_pdb)


mraa.init()
mraa.setLogLevel(syslog.LOG_DEBUG)
mraa.setPriority(99)

for i in vw.TARGET_MSG:
  print("%10s " % bin(i)),
print("")
rate = 3000
print('starting RX, rate: ', rate)
rx = vw.rx(36, rate)

print('sampling ...')
time.sleep(3)
rx.cancel()
print('done')

# while rx.messages:
#   row = rx.get()
#   print("good: "),
#   for i in vw.TARGET_MSG:
#     print("%10s " % bin(i)),
#   print("")
#   print(" bad: "),
#   for i in row:
#     print("%10s " % bin(i)),
Beispiel #13
0
LOG_FILE = 'rdd'
LOGGER1 = ml.init_logging(NAME, LOG_FILE)

NAME = 'MotionDetect'
LOG_FILE = 'motion'
LOGGER2 = ml.init_logging(NAME, LOG_FILE)

try:

    RX = int(CONFIG.get("vw", "RX"))
    TX = int(CONFIG.get("vw", "TX_RF"))
    BPS = int(CONFIG.get("vw", "BPS"))

    PI = pigpio.pi()  # Connect to local Pi.

    RX = vw.rx(PI, RX, BPS)  # Specify Pi, rx GPIO, and baud.
    TX = vw.tx(PI, TX, BPS)  # Specify Pi, tx GPIO, and baud.

    NUM = 3
    MSG = 0

    START = time.time()

    CONFIG = ' TX:' + str(TX) + ' RX:' + str(RX) + ' BPS:' + str(BPS)
    LOGGER.warning('RFSniffer has started with CONFIG. >> ' + CONFIG)

    LOGGER1.warning('RFSniffer has started >> ')
    ################Update entry for RFSniffer################
    LOGGER.info('Update entry for RFSniffer in db')

    UPDATE_ENTRY = "UPDATE status SET isrunning=1 WHERE name='RFSniffer'"