示例#1
0
# AWS endpoint parameters
host = b'FILL_ME_IN'  # ex: b'a1p3gcs127hy79'
region = b'FILL_ME_IN'  # ex: b'us-east-2'
if host == "FILL_ME_IN":
    print("Connection parameters not set. You must fill them in.")
    exit(-1)

aws_endpoint = b'%s.iot.%s.amazonaws.com' % (host, region)
ssl_params = {
    'keyfile': "cert/aws.key",
    'certfile': "cert/aws.crt",
    'ca_certs': "cert/aws.ca"
}  # ssl certs

ble.active(True)
cell_conn = Cellular()
print("Waiting for network...")
while not cell_conn.isconnected():
    sleep(1)
print("connected")
imei = cell_conn.config('imei')
print("imei: ", imei)

UPDATE_NONE, UPDATE_CLOUD = 0, 1
bulbs = None


class BLESmartSwitch:
    @staticmethod
    def _find_thunderboard():
示例#2
0
# 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.

import iBeacon
import time
import binascii
from digi import ble


def form_mac_address(addr: bytes) -> str:
    return ":".join('{:02x}'.format(b) for b in addr)


# Make sure the BLE radio is on
active = ble.active(True)
# Print out the BLE Mac
print("Started Bluetooth with address of: {}".format(form_mac_address(ble.config("mac"))))

# iBeacon frame parameters
uuid = binascii.unhexlify('b7a8bf1d-f5bd-4b57-9b35-12c7be74eb7a'.replace('-', ''))  # Randomly generated UUID
major = 44
minor = 47
calib_power = 189  # Calibrated power 1 meter away (-67 dBm)

# Create the iBeacon frame
frame = iBeacon.make_proximity_beacon(uuid, calib_power, major, minor)

# Advertise the iBeacon frame every 200ms
interval_us = 200_000
ble.gap_advertise(interval_us, frame)