From b4e763613a732121e41e9489018f81aeb53cde0c Mon Sep 17 00:00:00 2001 From: microDev <70126934+microDev1@users.noreply.github.com> Date: Wed, 7 Jul 2021 15:13:26 +0530 Subject: [PATCH] delete ports/nrf/examples directory --- ports/nrf/examples/ubluepy_eddystone.py | 68 ------------------ ports/nrf/examples/ubluepy_scan.py | 42 ----------- ports/nrf/examples/ubluepy_temp.py | 94 ------------------------- 3 files changed, 204 deletions(-) delete mode 100644 ports/nrf/examples/ubluepy_eddystone.py delete mode 100644 ports/nrf/examples/ubluepy_scan.py delete mode 100644 ports/nrf/examples/ubluepy_temp.py diff --git a/ports/nrf/examples/ubluepy_eddystone.py b/ports/nrf/examples/ubluepy_eddystone.py deleted file mode 100644 index 96818d01c2..0000000000 --- a/ports/nrf/examples/ubluepy_eddystone.py +++ /dev/null @@ -1,68 +0,0 @@ -from ubluepy import Peripheral, constants - -BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE = const(0x02) -BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED = const(0x04) - -BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE = const( - BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE | BLE_GAP_ADV_FLAG_BR_EDR_NOT_SUPPORTED -) - -EDDYSTONE_FRAME_TYPE_URL = const(0x10) -EDDYSTONE_URL_PREFIX_HTTP_WWW = const(0x00) # "http://www". -EDDYSTONE_URL_SUFFIX_DOT_COM = const(0x01) # ".com" - - -def string_to_binarray(text): - b = bytearray([]) - for c in text: - b.append(ord(c)) - return b - - -def gen_ad_type_content(ad_type, data): - b = bytearray(1) - b.append(ad_type) - b.extend(data) - b[0] = len(b) - 1 - return b - - -def generate_eddystone_adv_packet(url): - # flags - disc_mode = bytearray([BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE]) - packet_flags = gen_ad_type_content(constants.ad_types.AD_TYPE_FLAGS, disc_mode) - - # 16-bit uuid - uuid = bytearray([0xAA, 0xFE]) - packet_uuid16 = gen_ad_type_content( - constants.ad_types.AD_TYPE_16BIT_SERVICE_UUID_COMPLETE, uuid - ) - - # eddystone data - rssi = 0xEE # -18 dB, approx signal strength at 0m. - eddystone_data = bytearray([]) - eddystone_data.append(EDDYSTONE_FRAME_TYPE_URL) - eddystone_data.append(rssi) - eddystone_data.append(EDDYSTONE_URL_PREFIX_HTTP_WWW) - eddystone_data.extend(string_to_binarray(url)) - eddystone_data.append(EDDYSTONE_URL_SUFFIX_DOT_COM) - - # service data - service_data = uuid + eddystone_data - packet_service_data = gen_ad_type_content( - constants.ad_types.AD_TYPE_SERVICE_DATA, service_data - ) - - # generate advertisement packet - packet = bytearray([]) - packet.extend(packet_flags) - packet.extend(packet_uuid16) - packet.extend(packet_service_data) - - return packet - - -def start(): - adv_packet = generate_eddystone_adv_packet("micropython") - p = Peripheral() - p.advertise(data=adv_packet, connectable=False) diff --git a/ports/nrf/examples/ubluepy_scan.py b/ports/nrf/examples/ubluepy_scan.py deleted file mode 100644 index 37daa6c69b..0000000000 --- a/ports/nrf/examples/ubluepy_scan.py +++ /dev/null @@ -1,42 +0,0 @@ -from ubluepy import Scanner, constants - - -def bytes_to_str(bytes): - string = "" - for b in bytes: - string += chr(b) - return string - - -def get_device_names(scan_entries): - dev_names = [] - for e in scan_entries: - scan = e.getScanData() - if scan: - for s in scan: - if s[0] == constants.ad_types.AD_TYPE_COMPLETE_LOCAL_NAME: - dev_names.append((e, bytes_to_str(s[2]))) - return dev_names - - -def find_device_by_name(name): - s = Scanner() - scan_res = s.scan(100) - - device_names = get_device_names(scan_res) - for dev in device_names: - if name == dev[1]: - return dev[0] - - -# >>> res = find_device_by_name("micr") -# >>> if res: -# ... print("address:", res.addr()) -# ... print("address type:", res.addr_type()) -# ... print("rssi:", res.rssi()) -# ... -# ... -# ... -# address: c2:73:61:89:24:45 -# address type: 1 -# rssi: -26 diff --git a/ports/nrf/examples/ubluepy_temp.py b/ports/nrf/examples/ubluepy_temp.py deleted file mode 100644 index c70235c4a3..0000000000 --- a/ports/nrf/examples/ubluepy_temp.py +++ /dev/null @@ -1,94 +0,0 @@ -# This file is part of the MicroPython project, http://micropython.org/ -# -# The MIT License (MIT) -# -# SPDX-FileCopyrightText: Copyright (c) 2017 Glenn Ruben Bakke -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE - -from pyb import LED -from machine import RTC, Temp -from ubluepy import Service, Characteristic, UUID, Peripheral, constants - - -def event_handler(id, handle, data): - global rtc - global periph - global serv_env_sense - global notif_enabled - - if id == constants.EVT_GAP_CONNECTED: - # indicated 'connected' - LED(1).on() - - elif id == constants.EVT_GAP_DISCONNECTED: - # stop low power timer - rtc.stop() - # indicate 'disconnected' - LED(1).off() - # restart advertisement - periph.advertise(device_name="micr_temp", services=[serv_env_sense]) - - elif id == constants.EVT_GATTS_WRITE: - # write to this Characteristic is to CCCD - if int(data[0]) == 1: - notif_enabled = True - # start low power timer - rtc.start() - else: - notif_enabled = False - # stop low power timer - rtc.stop() - - -def send_temp(timer_id): - global notif_enabled - global char_temp - - if notif_enabled: - # measure chip temperature - temp = Temp.read() - temp = temp * 100 - char_temp.write(bytearray([temp & 0xFF, temp >> 8])) - - -# start off with LED(1) off -LED(1).off() - -# use RTC1 as RTC0 is used by bluetooth stack -# set up RTC callback every 5 second -rtc = RTC(1, period=5, mode=RTC.PERIODIC, callback=send_temp) - -notif_enabled = False - -uuid_env_sense = UUID("0x181A") # Environmental Sensing service -uuid_temp = UUID("0x2A6E") # Temperature characteristic - -serv_env_sense = Service(uuid_env_sense) - -temp_props = Characteristic.PROP_NOTIFY | Characteristic.PROP_READ -temp_attrs = Characteristic.ATTR_CCCD -char_temp = Characteristic(uuid_temp, props=temp_props, attrs=temp_attrs) - -serv_env_sense.addCharacteristic(char_temp) - -periph = Peripheral() -periph.addService(serv_env_sense) -periph.setConnectionHandler(event_handler) -periph.advertise(device_name="micr_temp", services=[serv_env_sense])