コード例 #1
0
def main():

    database = firebase.FirebaseApplication(
        'https://dont-forget-lake.firebaseio.com/', None)
    client = storage.Client()
    bucket = client.get_bucket('dont-forget-lake.appspot.com')
    blob = bucket.blob('./Audio/storage/emulated/0')
    blob.download_to_filename('./download.3gpp')
    pygame.mixer_music.load('./download.3gpp')

    if BT_ADDR:
        addr = BT_ADDR
    else:
        print(
            'No Bluetooth Address Found')  # Check whether address can be found
        return
    btrssi = BluetoothRSSI(addr=addr)
    rssiList = [btrssi.request_rssi() for _ in range(BIN_SIZE)]

    while True:  # Performs continual updates at an interval of TIME_DELAY
        rssi = btrssi.request_rssi()  # Get current RSSI
        rssiList.insert(0, rssi)  # Add RSSI to list
        rssiList.pop()  # Pop last element off list
        database.put('/pi', 'data', get_average(rssiList))

        if get_average(
                rssiList
        ) < THRESHOLD:  # Check if average is below THRESHOLD - if yes, turn on output
            pygame.mixer_music.play(1)
            print('ALARM')

        time.sleep(TIME_DELAY)
コード例 #2
0
def main():
    btrssi = BluetoothRSSI(addr=BT_ADDR)
    while True:
        rssi = btrssi.request_rssi()
        if rssi:
            print(rssi[0])
        time.sleep(1)
コード例 #3
0
 def get(self, address):
     btrssi = BluetoothRSSI(addr=address)
     rssi = btrssi.request_rssi()
     if rssi is None:
         abort(404,
               message="Device {} doesn't currently exist".format(address))
     else:
         return rssi, 200
コード例 #4
0
def bluetooth_listen(addr,
                     threshold,
                     callback,
                     sleep=1,
                     daily=True,
                     debug=False):
    """Scans for RSSI value of bluetooth address in a loop. When the value is
    within the threshold, calls the callback function.

    @param: addr: Bluetooth address
    @type: addr: str

    @param: threshold: Tuple of integer values (low, high), e.g. (-10, 10)
    @type: threshold: tuple

    @param: callback: Callback function to invoke when RSSI value is within
                      the threshold
    @type: callback: function

    @param: sleep: Number of seconds to wait between measuring RSSI
    @type: sleep: int

    @param: daily: Set to True to invoke callback only once per day
    @type: daily: bool

    @param: debug: Set to True to print out debug messages and does not 
                   actually sleep until tomorrow if `daily` is True.
    @type: debug: bool
    """
    b = BluetoothRSSI(addr=addr)
    while True:
        rssi = b.request_rssi()
        if debug:
            print("---")
            print("addr: {}, rssi: {}".format(addr, rssi))
        # Sleep and then skip to next iteration if device not found
        if rssi is None:
            time.sleep(sleep)
            continue
        # Trigger if RSSI value is within threshold
        if threshold[0] < rssi < threshold[1]:
            callback()
            if daily:
                # Calculate the time remaining until next day
                now = datetime.datetime.now()
                tomorrow = datetime.datetime(
                    now.year, now.month, now.day, 0, 0, 0, 0) + \
                    datetime.timedelta(days=1)
                until_tomorrow = (tomorrow - now).seconds
                if debug:
                    print("Seconds until tomorrow: {}".format(until_tomorrow))
                else:
                    time.sleep(until_tomorrow)
        # Delay between iterations
        time.sleep(sleep)
コード例 #5
0
ファイル: test_address.py プロジェクト: Hugo759/rssi
def main():
    if len(sys.argv) > 1:
        addr = sys.argv[1]
    elif BT_ADDR:
        addr = BT_ADDR
    else:
        print_usage()
        return
    if len(sys.argv) == 3:
        num = int(sys.argv[2])
    else:
        num = NUM_LOOP
    for i in range(0, num):
        btrssi = BluetoothRSSI(addr=addr)
        print(btrssi.request_rssi())
        time.sleep(1)
コード例 #6
0
 def update_bluetooth_once():
     """Lookup Bluetooth device and update status."""
     try:
         if track_new:
             for dev in discover_devices():
                 if dev[0] not in devs_to_track and dev[
                         0] not in devs_donot_track:
                     devs_to_track.append(dev[0])
         for mac in devs_to_track:
             _LOGGER.debug("Scanning %s", mac)
             result = bluetooth.lookup_name(mac, timeout=5)
             rssi = None
             if request_rssi:
                 client = BluetoothRSSI(mac)
                 rssi = client.request_rssi()
                 client.close()
             if result is None:
                 # Could not lookup device name
                 continue
             see_device(mac, result, rssi)
     except bluetooth.BluetoothError:
         _LOGGER.exception("Error looking up Bluetooth device")
コード例 #7
0
def main():
    if len(sys.argv) > 1:
        addr = sys.argv[1]
    elif BT_ADDR:
        addr = BT_ADDR
    else:
        print_usage()
        return
    if len(sys.argv) == 3:
        num = int(sys.argv[2])
    else:
        num = NUM_LOOP
    btrssi = BluetoothRSSI(addr=addr)

    n = 1.5  # Path loss exponent(n) = 1.5
    c = 10  # Environment constant(C) = 10
    A0 = 2  # Average RSSI value at d0
    actual_dist = 37  # Static distance between transmitter and Receiver in cm
    sum_error = 0
    count = 0

    for i in range(1, num):
        rssi_bt = float(btrssi.request_rssi())
        if(rssi_bt != 0 and i > 10):  # reduces initial false values of RSSI using initial delay of 10sec
            count = count + 1
            # Log Normal Shadowing Model considering d0 =1m where
            x = float((rssi_bt - A0) / (-10 * n))
            distance = (math.pow(10, x) * 100) + c
            error = abs(actual_dist - distance)
            sum_error = sum_error + error
            avg_error = sum_error / count
            print("Average Error=  " + str(avg_error))
            print("Error=  " + str(error))
            print("Approximate Distance:" + str(distance))
            print("RSSI: " + str(rssi_bt))
            print("Count: " + str(count))
            print(" ")
        time.sleep(1)