The Bluefruit LE Connect application allows you to access the location data from your phone. This demo will show you how to access that data and print it to the serial console.
Save the following as code.py on your CIRCUITPY
drive and then connect to the board using the Bluefruit LE Connect app. Then, connect to the serial console.
# SPDX-FileCopyrightText: 2019 Kattni Rembor for Adafruit Industries # # SPDX-License-Identifier: MIT from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.nordic import UARTService from adafruit_bluefruit_connect.packet import Packet from adafruit_bluefruit_connect.location_packet import LocationPacket ble = BLERadio() uart = UARTService() advertisement = ProvideServicesAdvertisement(uart) while True: ble.start_advertising(advertisement) while not ble.connected: pass # Now we're connected while ble.connected: if uart.in_waiting: packet = Packet.from_stream(uart) if isinstance(packet, LocationPacket): print("Latitude:", packet.latitude) print("Longitude", packet.longitude) print("Altitude:", packet.altitude) # If we got here, we lost the connection. Go up to the top and start # advertising again and waiting for a connection..
Connect to your board using the Bluefruit LE Connect application and navigate to the Controller page. Enable the Location data stream.
Let's take a look at the code.
First we import the necessary libraries and instantiate the UART server.
Inside the loop, we first begin advertising.
Once connected, the board begins listening for packets. In the event that a location packet is received, it prints a message to the serial console.
That's all there is to accessing location data from your mobile using the Bluefruit LE Connect app and CircuitPython!