""" Connect to a sensor using its address. When using the AT command set addresses are prefixed with 01. """ import time import serial import serial.threaded import logging import log_wrapper from dongle import BL65x from json_config import JsonConfig from json_commander import jtester if __name__ == "__main__": log_wrapper.setup(__file__, console_level=logging.DEBUG) isBle = True jc = JsonConfig(isBle) ser = serial.serial_for_url(url=jc.get_port(), baudrate=jc.get_baudrate(), timeout=1, rtscts=True) with serial.threaded.ReaderThread(ser, BL65x) as bt_module: jt = jtester() jt.set_protocol(bt_module) bt_module.secondary_initialization() input("Press sensor button (advertise) and then press enter...") bt_module.connect(bt_module.current_addr, bt_module.connection_timeout) if bt_module.vspConnection: jt.Unlock() jt.GetAttribute("sensorName")
The first time a sensor is seen its attributes are dumped. Runs indefinitely. """ import logging import log_wrapper import serial import serial.threaded from dongle import BL65x from json_commander import jtester from json_config import JsonConfig from sensor_event import SensorEvent from adv_parser import AdvParser if __name__ == "__main__": log_wrapper.setup(__file__, console_level=logging.INFO) isBle = True jc = JsonConfig(isBle, "config.json") ser = serial.Serial(jc.get_port(), baudrate=jc.get_baudrate(), timeout=1, rtscts=True) with serial.threaded.ReaderThread(ser, BL65x) as bt_module: jt = jtester() jt.set_protocol(bt_module) bt_module.secondary_initialization() name_to_look_for = jc.get("system_name_to_look_for") bt_module.scan(nameMatch=name_to_look_for) event_dict = dict() while True: ad = bt_module.get_scan(timeout=None) do_query = False
import logging import log_wrapper import serial import serial.threaded from dongle import BL65x from json_commander import jtester from json_config import JsonConfig from sensor_event import SensorEvent from adv_parser import AdvParser import metrics import boto3 NAMESPACE = "Client/Application" if __name__ == "__main__": log_wrapper.setup(__file__, console_level=logging.INFO, file_mode='a') isBle = True jc = JsonConfig(isBle) ser = serial.Serial(jc.get_port(), baudrate=jc.get_baudrate(), timeout=1, rtscts=True) with serial.threaded.ReaderThread(ser, BL65x) as bt_module: cloudwatch = boto3.client('cloudwatch') jt = jtester() jt.set_protocol(bt_module) bt_module.secondary_initialization() name_to_look_for = jc.get("system_name_to_look_for") bt_module.scan(nameMatch=name_to_look_for) event_dict = dict() while True: ad = bt_module.get_scan(timeout=None) ap = None
""" A simple test of serial communication with a BT510. """ import time import serial import serial.threaded import logging import log_wrapper from json_serial_reader import JsonSerialReader from json_config import JsonConfig if __name__ == "__main__": log_wrapper.setup(__file__) isBle = False jc = JsonConfig(isBle) ser = serial.serial_for_url( url=jc.get_port(), baudrate=jc.get_baudrate(), timeout=1.0) with serial.threaded.ReaderThread(ser, JsonSerialReader) as reader_thread: rt = reader_thread rt.set_protocol(reader_thread) rt.Unlock() rt.GetAttribute("sensorName") rt.GetAttribute("location") rt.GetAttribute("firmwareVersion") rt.GetAttribute("hwVersion") rt.GetAttribute("bluetoothAddress") rt.LedTest() rt.EpochTest(int(time.time())) rt.LogResults()