Skip to content

Android app to connect, disconnect, receive and send messages to BLE devices using external intents/Tasker - Fork of Android terminal app for Bluetooth LE devices using custom serial profiles

License

Notifications You must be signed in to change notification settings

SteinOv/SimpleBluetoothLeTerminal

 
 

Repository files navigation

Codacy Badge

SimpleBluetoothLeTerminal - fork for use with Tasker

This is a fork of SimpleBluetoothLeTerminal with the main goal to be able to communicate with BLE devices using Tasker. You can connect, send and disconnect to BLE devices by sending intents. When a message by the BLE device is received, a broadcast intent is sent. When losing the connection or failing to connect, the service will try to reconnect for a configurable amount of time.
Keep in mind that the external intents can be sent by any app, which may be a security risk. I made this mainly with a personal Arduino project in mind and this is my first time coding in Android, so there may be some bugs/imperfections. If you spot any, feel free to create a PR.

Known bugs

  • Service crashes when sending another connect command while it is trying to establish a connection or trying to reconnect.
  • When trying to send a message while no BLE device is connected, it will try to connect to MAC address null.
  • When trying to send a message while the service is reconnecting, it will stop trying to reconnect.
  • Connecting using the GUI after service is connected through intent results in two connections at the same time (and two intents are received for each message)

Since these don't give me problems in my personal project I have no plans for fixing them. If you want to fix them, feel free to create a PR.

How To Use

First install the apk which can be found under app -> release

Sending data

Create a new intent with component name package de.kai_morich.simple_bluetooth_le_terminal and class de.kai_morich.simple_bluetooth_le_terminal.SerialService. Add parameters as extra's (key, value pairs), keys are case-insensitive. Send the intent using context.StartForegroundService(intent)
You can use the following parameters:

  • command (required)
    Main command, has the following possible values
    • connect - Connect to BLE device and start background service
    • disconnect - Disconnect from BLE device and stop background service
    • send - Send string to connected BLE device

  • macAddress (required when using connect command)
    MAC address of device to connect to (for example AA:11:BB:C3:D5:B6:66). If you do not know this, you can find it by opening the app and scanning for devices. The MAC address will be below the device name.
  • reconnectTimeout (optional, only relevant with connect command)
    Maximum amount of time the service should try to reconnect after losing connection (in milliseconds) default is 30000 (5 minutes), set to 0 to infinitely retry (until either reconnected or service is stopped).

  • text (required when using send)
    String to send to connected device.

Receiving data

The service will send an intent with action TASKER_BLE and scheme tasker with data in the form: tasker:<string sent by BLE device>
To be able to react to error, connect and disconnect events, these events are sent in an intent with action TASKER_BLE_EVENT and scheme tasker. The possible data values are tasker: connected (after connecting to device), tasker: disconnected (after disconnecting from device) and tasker: error (after a connection/send error has occurred). Additionally, for debugging purposes, some logging is sent via an intent with action TASKER_BLE_DEBUG, and scheme tasker.

Tasker specific instructions

You can send intents in tasker by using the Java Function task. You can receive intents using the Intent Received event, then the data will be available in the local variable %intent_data. You can import taskerBleExample.xml into Tasker for working examples (all you have to do is change the macAddress in the connectToMacAddress task).

More information

Tasker User Guide - Intents
Tasker User Guide - Java Support
Android docs - Intents


Original Readme

This Android app provides a line-oriented terminal / console for Bluetooth LE (4.x) devices implementing a custom serial profile

For an overview on Android BLE communication see Android Bluetooth LE Overview.

In contrast to classic Bluetooth, there is no predefined serial profile for Bluetooth LE, so each vendor uses GATT services with different service and characteristic UUIDs.

This app includes UUIDs for widely used serial profiles:

  • Nordic Semiconductor nRF51822
  • Texas Instruments CC254x
  • Microchip RN4870/1
  • Telit Bluemod

Motivation

I got various requests asking for help with Android development or source code for my Serial Bluetooth Terminal app. Here you find a simplified version of my app.

About

Android app to connect, disconnect, receive and send messages to BLE devices using external intents/Tasker - Fork of Android terminal app for Bluetooth LE devices using custom serial profiles

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%