BleuIO

BleuIO

  • Get Started
  • Buy Now
  • Manual
  • AT Commands
  • Help

›Beaglebone

Manual

  • How it works
  • How to use
  • Verbose Mode
  • Known Issues
  • Troubleshooting

Firmware Updates

    BleuIO Pro (SSD025)

    • Firmware Updates
    • Release History

    BleuIO (SSD005)

    • Firmware Updates
    • Release History of BleuIO (SSD005)

AT-Commands

  • List of AT Commands

BleuIO Libraries

  • JavaScript Library
  • Python Library

Scripts & Tutorials

  • Python: iBeacon
  • Python: Eddystone Beacon
  • Python: Scan
  • Python: Scan and Store
  • Python: SPS Script
  • Python: File transfer Script
  • Python: Repeater Script
  • Javascript: Google chrome.serial Beacon
  • C# Console App Example
  • C# WFA Example

Script using libraries

    Python library > v1.2.0

    • Custom Services example using Python library
    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library

    Python library < v1.2.0

    • Eddystone example using Python library
    • IBeacon example using Python library
    • Scan example using Python library
    • Scan and store example using Python library
    • SPS example using Python library
    • Security Example using Python library

    JS library

    • Eddystone example using Javascript library
    • IBeacon example using Javascript library
    • Scan example using Javascript library
    • Security Example using Javascript library
    • Get Device Distance

Projects

    Arduino

    • Arduino Example

    Beaglebone

    • Beaglebone Example

    Raspberry Pi

    • Raspberry PI into Beacon
    • Raspberry PI home automation

    Raspberry PI Pico

    • BleuIO integration (Part1)
    • BleuIO integration (Part2)
    • BleuIO integration (Part3)

    Renesas RA4M2

    • Signal Strength Monitoring
    • Real-Time CO2 monitor
    • Monitoring Air Quality

    STM32 Nucleo-144

    • Nucleo-144 board example
    • Smart Bulb Example

    M5Stack's CoreMP135

    • M5Stack's CoreMP135 board example

Build Your Own Firmware

  • Build Your Own Firmware
  • Advertising Example

More

  • Links
Order Now

BleuIO

$19.99

Buy Now

Beaglebone Example

alt text

1. Introduction

This is a simple example showcasing how to control a BleuIO dongle connected to Beaglebone Black using a python script.

When running the script, it will first ask for the com port where the dongle is connected (usually '/dev/ttyACM0'). After that, the BleuIO will start advertising. Every 8th second it will turn on one of the onboard Beaglebone Black LEDs whilst changing the BLE advertising name to indicate which LED is on.

We are using the Linux debian image: 'OMAP3/DM3730 Debian 9.5 2018-10-07 4GB SD LXQT' (https://beagleboard.org/latest-images). alt text

2. About the Code

You can get access to the project HERE
https://github.com/smart-sensor-devices-ab/beaglebone_bleuio_example


We are using the Adafruit_BBIO python library that comes with the Beaglebone to control the onboard LEDs. First we define the LEDs names and then set them as GPIO Outputs. Then we define the advertising messages that the BleuIO will switch between. Lets break one down:

"10:09:42:6C:65:75:49:4F:20:4C:45:44:20:30:20:4F:4E:"

"10" is the size of the advertising packet in HEX.
"09" is the flag for device name (Complete Local Name).
"42:6C:65:75:49:4F:20:4C:45:44:20:30:20:4F:4E" is the packet itself, translated from HEX to ASCII it says: "BleuIO LED 0 ON"

Afterwards the user is presented with a message to input the com port the BleuIO is connected to. If you are not using a USB Hub the port should be '/dev/ttyACM0'.

You can change the comport name in the Python script and fill in your COM port.

com_input = "/dev/ttyACM0"

The script continues into the main loop, where it will first make sure all LEDs are off and then start BLE advertising.

The loop iterates through all four LEDs. In every iteration it turns one LED on and advertise the LED name then continue to the next LED. This will continue until the script is aborted.


import serial
import time
import Adafruit_BBIO.GPIO as GPIO


LED_USR0 = "USR0"
LED_USR1 = "USR1"
LED_USR2 = "USR2"
LED_USR3 = "USR3"

GPIO.setup(LED_USR0, GPIO.OUT)
GPIO.setup(LED_USR1, GPIO.OUT)
GPIO.setup(LED_USR2, GPIO.OUT)
GPIO.setup(LED_USR3, GPIO.OUT)

LED0_ON_ADV_MSG = "10:09:42:6C:65:75:49:4F:20:4C:45:44:20:30:20:4F:4E:"
LED1_ON_ADV_MSG = "10:09:42:6C:65:75:49:4F:20:4C:45:44:20:31:20:4F:4E:"
LED2_ON_ADV_MSG = "10:09:42:6C:65:75:49:4F:20:4C:45:44:20:32:20:4F:4E:"
LED3_ON_ADV_MSG = "10:09:42:6C:65:75:49:4F:20:4C:45:44:20:33:20:4F:4E:"

# Turn off all LEDs
GPIO.output(LED_USR0, GPIO.LOW)
time.sleep(0.1)
GPIO.output(LED_USR1, GPIO.LOW)
time.sleep(0.1)
GPIO.output(LED_USR2, GPIO.LOW)
time.sleep(0.1)
GPIO.output(LED_USR3, GPIO.LOW)
time.sleep(0.1)

print("\nBlueIO BeagleBone Example!\n\n")
connecting_to_dongle = 0
com_input = ""

start_input = 0
valid_input = 0
while start_input == 0:
    com_input = input(
        "Enter Com port of Dongle (default for BeagleBone: '/dev/ttyACM0'):\n>>"
    )
    print("\nComport to use: " + com_input)
    input_continue = input(
        "If your happy with your choice just press Enter to continue the script. Else type E to exit or R to redo your choice. \n>>"
    )
    if input_continue.upper() == "E":
        start_input = 1
    elif input_continue.upper() == "":
        start_input = 1
    elif input_continue.upper() == "R":
        valid_input = 0
        start_input = 0
if input_continue.upper() == "E":
    print("Exiting script...")
    exit()

console = None

while 1:
    try:
        print("Please wait...")
        time.sleep(0.5)
        console.write(str.encode("AT+DUAL"))
        console.write("\r".encode())
        time.sleep(0.5)
        print("Starting Advertising...")
        console.write(str.encode("AT+ADVSTART"))
        console.write("\r".encode())
        time.sleep(0.5)
        led_turn = 0
        # Turn off all LEDs
        GPIO.output(LED_USR0, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR1, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR2, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR3, GPIO.LOW)
        time.sleep(0.1)
        while True:
            if led_turn == 0:
                print("\nTurning LED USR0 ON")
                console.write(str.encode("AT+ADVRESP="))
                console.write(LED0_ON_ADV_MSG.encode())
                console.write("\r".encode())
                GPIO.output(LED_USR0, GPIO.HIGH)
                GPIO.output(LED_USR1, GPIO.LOW)
                GPIO.output(LED_USR2, GPIO.LOW)
                GPIO.output(LED_USR3, GPIO.LOW)
                led_turn = led_turn + 1
            elif led_turn == 1:
                print("\nTurning LED USR1 ON")
                console.write(str.encode("AT+ADVRESP="))
                console.write(LED1_ON_ADV_MSG.encode())
                console.write("\r".encode())
                GPIO.output(LED_USR0, GPIO.LOW)
                GPIO.output(LED_USR1, GPIO.HIGH)
                GPIO.output(LED_USR2, GPIO.LOW)
                GPIO.output(LED_USR3, GPIO.LOW)
                led_turn = led_turn + 1
            elif led_turn == 2:
                print("\nTurning LED USR2 ON")
                console.write(str.encode("AT+ADVRESP="))
                console.write(LED2_ON_ADV_MSG.encode())
                console.write("\r".encode())
                GPIO.output(LED_USR0, GPIO.LOW)
                GPIO.output(LED_USR1, GPIO.LOW)
                GPIO.output(LED_USR2, GPIO.HIGH)
                GPIO.output(LED_USR3, GPIO.LOW)
                led_turn = led_turn + 1
            elif led_turn == 3:
                print("\nTurning LED USR3 ON")
                console.write(str.encode("AT+ADVRESP="))
                console.write(LED3_ON_ADV_MSG.encode())
                console.write("\r".encode())
                GPIO.output(LED_USR0, GPIO.LOW)
                GPIO.output(LED_USR1, GPIO.LOW)
                GPIO.output(LED_USR2, GPIO.LOW)
                GPIO.output(LED_USR3, GPIO.HIGH)
                led_turn = 0

            time.sleep(8)

    except KeyboardInterrupt:
        GPIO.output(LED_USR0, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR1, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR2, GPIO.LOW)
        time.sleep(0.1)
        GPIO.output(LED_USR3, GPIO.LOW)
        time.sleep(0.1)
        print("Exiting script...")
        exit()
    except:
        print("\n\nDongle not connected.\n")
        connecting_to_dongle = 0
        while connecting_to_dongle == 0:
            try:
                print("Trying to connect to dongle...")
                console = serial.Serial(
                    port=com_input,
                    baudrate=57600,
                    parity="N",
                    stopbits=1,
                    bytesize=8,
                    timeout=0,
                )
                if console.is_open.__bool__():
                    connecting_to_dongle = 1
                    print("\n\nConnected to Dongle in port: " + com_input + ".\n")
            except:
                print(
                    "Dongle not found. Retrying connection to port: "
                    + com_input
                    + "..."
                )
                time.sleep(5)


3. Using the example project

3.1 What you will need

  • A Computer
  • A BleuIO dongle (https://www.bleuio.com/)
  • A BeagleBone Black (https://beagleboard.org/black) with Beaglebone Firmware installed (https://beagleboard.org/latest-images)

4. How to setup project

4.1 Downloading the project from GitHub

Get access to the project HERE
https://github.com/smart-sensor-devices-ab/beaglebone_bleuio_example

Either clone the project, or download it as a zip file and unzip it, into a folder on your BeagleBone.

You can also create a new python file using the Cloud9 IDE from the BeagleBone (run by going to http://192.168.7.2:3000/).
alt text

Copy the code and pasting it into the newly created file.


alt text


4.2 Installing pyserial

To run the script you will need to install the python library pyserial.

The easiest way of doing this is just connecting to the BeagleBone via shh (the default password is temppwd):
alt text

or using the bash tab in the Cloud9 IDE and type:

 sudo pip3 install pyserial


alt text

5. Running the example

Go to the folder where you have the python script file and run:
(Pyserial needs sudo-privileges to function.)


sudo python3 name_of_script.py

6. Links

  • Go to BleuIO Manual

  • Go to BleuIO Blog

← Arduino ExampleRaspberry PI into Beacon →
  • 1. Introduction
  • 2. About the Code
  • 3. Using the example project
    • 3.1 What you will need
  • 4. How to setup project
    • 4.1 Downloading the project from GitHub
    • 4.2 Installing pyserial
  • 5. Running the example
  • 6. Links

Support Request

If you have any queries or technical questions, please don't hesitate to send us a message. We will reply within 24 hours.

Message Sent!

Docs
ManualAT CommandsHelp
Community
YouTubeLinkedInFacebook
More
BleuIOSmart Sensor DevicesGitHub
Sales & Support
support@bleuio.comsales@bleuio.com
Copyright © 2025 BleuIO. A product of Smart Sensor Devices