#!/usr/bin/python # File : test_beacon.py # Author: jmleglise # Date: 25-May-2016 # Description : Test yours beacon # URL : https://github.com/jmleglise/mylittle-domoticz/edit/master/Presence%20detection%20%28beacon%29/test_beacon.py # Version : 1.0 # TAG_DATA = [ ] import logging # choose between DEBUG (log every information) or CRITICAL (only error) logLevel=logging.DEBUG #logLevel=logging.CRITICAL #logOutFilename='/var/log/test_beacon.log' # output LOG : File or console (comment this line to console output) ################ Nothing to edit under this line ##################################################################################### import os import subprocess import sys import struct import bluetooth._bluetooth as bluez import time import requests import signal import threading LE_META_EVENT = 0x3e OGF_LE_CTL=0x08 OCF_LE_SET_SCAN_ENABLE=0x000C EVT_LE_CONN_COMPLETE=0x01 EVT_LE_ADVERTISING_REPORT=0x02 def print_packet(pkt): for c in pkt: sys.stdout.write("%02x " % struct.unpack("B",c)[0]) def packed_bdaddr_to_string(bdaddr_packed): return ':'.join('%02x'%i for i in struct.unpack("tag[2] : tag[2]=elapsed_time logging.debug('Tag %s is back after %i sec. (Max %i). RSSI %s. DATA %s',tag[0],elapsed_time,tag[2],rssi, struct.unpack("b", pkt[report_pkt_offset -2])) tag[3]=time.time() # update lastseen found=1 if found==0 : TAG_DATA.append([macAdressSeen,macAdressSeen,0,time.time()]) logging.debug('New Beacon %s Detected ', macAdressSeen) sock.setsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, old_filter )