Coder Social home page Coder Social logo

bleconsole's Introduction

BLEConsole

Windows command-line tool for interacting with Bluetooth LE devices

alt text

Requirements:

Windows 10, BT 4.0 adapter

Console commands:

  • help, ? : show help information

  • quit, q : quit from application

  • list, ls [w] : show available BLE devices

  • open or <#> : connect to BLE device

  • timeout : show/change connection timeout, default value is 3 sec

  • delay : pause execution for a certain number of milliseconds

  • close : disconnect from currently connected device

  • stat, st : shows current BLE device status

  • print, p <text&vars>* : prints text and variables to stdout, where are variables are:

    • %id : BlueTooth device ID
    • %addr : device BT address
    • %mac : device MAC address
    • %name : device BlueTooth name
    • %stat : device connection status
    • %NOW, %now, %HH, %hh, %mm, %ss, %D, %d, %T, %t, %z : date/time variables
  • format [data_format], fmt : show/change display format, can be ASCII/UTF8/Dec/Hex/Bin

  • set <service_name> or <#> : set current service (for read/write operations)

  • read, r ** : read value from specific characteristic

  • write, w ** : write value to specific characteristic

  • subs ** : subscribe to value change for specific characteristic

  • unsubs ** [all] : unsubscribe from value change for specific characteristic or unsubs all for all

  • wait : wait seconds for notification event on value change (you must be subscribed, see above)

  • foreach [device_mask] : starts devices enumerating loop

  • endfor : end foreach loop

  • if : start conditional block dependent on function returning w/o error

    • elif : another conditionals block
    • else : if condition == false block
  • endif : end conditional block

    * you can also use standard C language string formating characters like \t, \n etc.

    ** could be "service/characteristic", or just a char name or # (for selected service)

Example of usage:

Lookup, connect and print all BLE devices names

BLEConsole.exe < cmd.txt, where is cmd.txt is a simple text file with content:

// Loop for each device
foreach 

	// Connect and if successfull
	if open $
		
		//Read first characteristic of first service
		read #0/#0
		
		// Close connection to device
		close
	endif
	
endfor
  • Blank/empty lines are ignored.
  • Comments can be added by preceding them with //

Below is an example of interactive use of the BLEConsole:

You can use BT name or # or address provided by list command. For example, run BLEConsole, type ls and it should list available BT devices, like

BLE: ls
#    Address           Name
#00: 85:41:35:3f:d6:8a TOZO-S2
#01: 65:b3:6e:8d:ba:f4 F2
#02: e4:98:bb:5f:80:53 LEDnetWF02004100000

Note: The list consists of devices that Windows has seen in the past time. Not all devices may be available at this moment.

Than use command open #1 or open TOZO-S2 or open 85:41:35:3f:d6:8a to connect to the device. (you can also use partial name, like TOZ if no more BLE devices with that name exist)

BLE: open #1
Connecting to TOZO-S2.
Found 3 services:
#00: GenericAccess
#01: GenericAttribute
#02: 2800

The open command will automatically list the available services on the device. Now you can set active service and list it's characteristics, by issuing command set #0

BLE: set #0
Selected service GenericAccess.
#00: DeviceName RW
#01: Appearance R
#02: PeripheralPreferredConnectionParameters    R
#03: 10918      R

Now you can read or write characteristics of the active service.

Read a characteristic by # or name, like read #0

BLE: read #0
TOZO-S2

Write a characteristic by # or name, like write #0 value

BLE: write #0 123

If you already knew your service name/#, you can avoid previous step and read characteristic after successful connection to BLE device, like read #1/#0

Data will be interpreted in the selected format Here we select hexadecimal as the format for both sending and receiving.

BLE: format hex
Current send data format: Hex
Current received data format: Hex

You can also directly write a value to a known service/characteristic. For example here we write an (hexadecimal) array of data to service (0xFFFF) / characteristic (0xFF01)

BLE: write 0xFFFF/0xFF01 00 04 80 00 00 0d 0e 0b 3b 23 00 00 00 00

bleconsole's People

Contributors

eried avatar fabje avatar jpstotz avatar marcovansteen avatar sensboston avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bleconsole's Issues

Finding specific devices

It's only finding specific devices. It can't find my Xbox controller or Nintendo Switch Joy-cons. It can find it just find in the settings app for Windows 10, but it can't find it in this app.

"Error accessing service" which is viewable in "Bluetooth LE Explorer"

Thank you for an amazing application!

I am interacting with a GoPro. I encountered 2 problems:

First problem

In "Bluetooth LE Explorer" I can see the service 61590 and it's characteristics:
image

When I try to access the same service (65190) through BLEConsole, it returns "Error accessing service."
image

Second problem

I would like to write directly to characteristic b5f90072-aa8d-11e3-9046-0002a5d5c51b (which is inside the service 6190). I tried following your naming rules, but it didn't work:

image

It would be easier if I could write to b5f90072-aa8d-11e3-9046-0002a5d5c51b directly (without the "Custom characteristic" or service part).

How to send a file to BLE device?

Hello everyone,
I could able to send some string data to BLE device, which is already paired.
Now I want to send a text file which is already saved in my local drive. But i could not load file from my Local drive. Can anyone suggest me how to send local file data to ble device?

direct use BLEConsole in cmd

how to direct use BLEConsole.exe in cmd,do not in BLEConsole.exe . like C:\BLEConsole.exe list,then output ble device list

Why would ls get a device that no longer exists?

  1. I see in the README that there is a possibility that the device that ls fetches may not currently exist, but I don't understand why ls would fetch a device that is not present in the current period, is it because ls isn't really scanning for surrounding devices? If so, is it possible for BLEConsole to actively scan for surrounding devices?

  2. Also, I noticed that BLEConsole supports using the arrow keys to fetch the input history, but why is it that a BLEConsole that is closed and then restarted can also fetch the previous input history?

By the way, I've never written C#, so I don't know much about any of this, and would appreciate a explanation, thanks!

BLE Console crashes while performing the subs command

Dear Community,

I came across this application and found it quite good. So i started testing this to see if it would be suitable for me to use in my project. I found one issue that i am not sure of and need some help.

After disconnecting from a device, reconnecting to the device again will invariable report a device unreachable error or a crash just after subscribing to the notify service. Log file attached.

Any help or pointers would be greatly appreciated. Since i can just reopen the app and connect i dont believe its an issue on the peripheral side. Also i have used outer android based ble apps to connect and disconnect multiple time siwthout any issues.

Thanks.
BLEConsoleLog.txt
Abel.

Support Request: Is there any way to detect errors or retry?

Thanks for this tool! It's very helpful for automating control of my RGB strips.

Sometimes my devices respond with:
Device <Device> is unreachable.

Is there a good way to detect that this happened, and retry? Maybe with exit codes or just using if/else and repeating the code a few times?

Perhaps increasing the timeout that might help?

Sending Char(acters)

I connected to a ble device(#3), it has a service (#2) i want to use a characteristic (#00 or #1) to send a char ("?"), if i send this char the bluetooth device will send me a string.
BLE: stat
Device Control_Unit is connected.
Available services:
#00: GenericAccess
#1: GenericAttribute
#2: Custom Service: 39df7777-b1b4-b90b-57f1-7144ae4e4a6a
Selected service: Custom Service: 39df7777-b1b4-b90b-57f1-7144ae4e4a6a
Available characteristics:
#00: Custom Characteristic: 39df9999-b1b4-b90b-57f1-7144ae4e4a6a N
#1: Custom Characteristic: 39df8888-b1b4-b90b-57f1-7144ae4e4a6a W
BLE:
i have already set format to ASCII
how can i get this work? Here is what i send:
Current display format: ASCII
BLE: read #2/#1 ?
Invalid device number 01 ?
Invalid characteristic #1 ?
BLE:

Unsubscribe does not work correctly

Using the "unsub all" command does not actually work!
In the file "Program.cs", it appears that line 1322 never returns to complete the unsubscribe operation.

I found the following changes allow the unsubscribe to work:
Line 1303:
was: static async void Unsubscribe(string param)
change to: static async Task Unsubscribe(string param)

Line 793:
was: if (_subscribers.Count > 0) Unsubscribe("all");
change to: if (_subscribers.Count > 0) await Unsubscribe("all");

Line 790:
was: static void CloseDevice()
change to: static async Task CloseDevice()

Line 742:
was: CloseDevice();
change to: await CloseDevice();

Line 380:
was: Unsubscribe(parameters);
change to: await Unsubscribe(parameters);

Line 334:
was: CloseDevice();
change to: await CloseDevice();

Line 286:
insert: if (_selectedDevice != null) { await CloseDevice(); }

[Feature-Idea] Device info dump

Note: This is a new feature idea, I don't know if I will find the time to implement this, anyone is welcome to do so

Rationale
When getting a new/unknown BLE device it always a discovery which services/characteristics are implemented/supported.
Especially in reverse-engineering of a undocumented product.

Description
Currently it is technically possible to do this by hand, but I think it would be a good feature to have a "device info dump" command.
Listing all the available services and their characteristics with their values/options in one big list.

Implementation
There is a bit of a challenge implementing this in the current codebase.
Only the BluetoothLEAttributeDisplay is stored in the global _services and _characteristics lists. Also the _characteristics is switches based on the selected service.

We could either:

  • Store all services as a "nested list" like structure. with each of them having a list of their characteristics as a "child" property/list and let other commands use that "tree". _selectedService and _selectedCharacteristic would point to objects within that list.
  • Implement the command with kind of a duplicate code of the current service selection/switching. which would duplicate a lot of code.

[Feature-Idea] Advertisement collecting

Note: This is a new feature idea, I don't know if I will find the time to implement this, anyone is welcome to do so

Rationale
More and more (low-power) devices publish their information in a advertisement message instead or in addition to the GATT.
Connecting to such a (battery powered) device will get you the info but will drain the battery of the device.

Description
It would be a good feature to be able to receive/collect these advertisement messages and provide them as output.

Implementation
.NET has the BluetoothLEAdvertisementWatcher class for this purpose.
Basically creating start trigger and displaying the output from the receive event would implement this feature.

Send value to go Pro Hero8

Hi,

I wanted to use BLEConsole in order to activate the wifi on a GoPro Hero 8.
In order to do this I need to send a value to a characteristic. The value is 03170101. This value should be converted in byte array and send to the device.
When I do it i do not get any error message but nothing happens on the camera.
For confirmation I tried another similar solution on Debian and it works...
I just wanted to be sure of how the write command should be written. As of know I use : Write #06/#00 03170101
Thnaks,

Issues in working with services when Device name is used to open

I am attempting to leverage BLEConsole in a scripted method. Issue I am having is that when leveraging the open command against the name of the devices the application presents the services as it should but any time I attempt to write to those characteristics or set the service I get an error. When specifying the device by number I am able to connect without issue. This is an issue as if the system device order changes the script will break.

A successful write...

BLE: ls
#00: bhyve_20B160
#01: Living Room TV
#02: MX Master 2S
#03: NEEWER-RGB660 PRO
BLE: open #3
Connecting to NEEWER-RGB660 PRO.
Found 4 services:
#00: GenericAccess
#01: GenericAttribute
#02: Custom Service: 69400001-b5a3-f393-e0a9-e50e24dcca99
#03: Custom Service: 7f510004-b5a3-f393-e0a9-e50e24dcca9e
BLE: set #2
Selected service Custom Service: 69400001-b5a3-f393-e0a9-e50e24dcca99.
#00: Custom Characteristic: 69400003-b5a3-f393-e0a9-e50e24dcca99          N
#01: Custom Characteristic: 69400002-b5a3-f393-e0a9-e50e24dcca99         W
BLE: format HEX
Current display format: Hex
BLE: w #02/#01 78 86 04 58 01 18 64 D7

An example of write failure... showing the error "Error accessing service." & "Please specify characteristic name or # for writing."

BLE: ls
#00: bhyve_20B160
#01: Living Room TV
#02: MX Master 2S
#03: NEEWER-RGB660 PRO
BLE: open NEEWER-RGB660
Device NEEWER-RGB660 PRO is disconnected.
Connecting to NEEWER-RGB660 PRO.
Found 4 services:
#00: GenericAccess
#01: GenericAttribute
#02: Custom Service: 69400001-b5a3-f393-e0a9-e50e24dcca99
#03: Custom Service: 7f510004-b5a3-f393-e0a9-e50e24dcca9e
BLE: set #2
Error accessing service.
BLE: format HEX
Current display format: Hex
BLE: w #02/#01 78 86 04 58 01 18 64 D7
Please specify characteristic name or # for writing.

Mi Band 4

I am trying to read the hart rate or (if possible) the raw pulse from a Mi Band 4.

BLE: st
Device Mi Smart Band 4 is connected.
Available services:
#00: GenericAccess
#1: GenericAttribute
#2: DeviceInformation
#3: Custom Service: 00001530-0000-3512-2118-0009af100700
#4: AlertNotification
#5: ImmediateAlert
#6: HeartRate
#7: 65248
#8: 65249
#9: 14338
Selected service: HeartRate
Available characteristics:
#00: HeartRateMeasurement N
#1: HeartRateControlPoint RW

if I do r #1 I get protocol error.
device information works.
any idea?

I want to get the battery information

As shown in the figure, how can I get the information of battery quantity and how to send instructions
image

image

Why isn't it the power information? It's just a "P"?

escape char on write?

hi! thanks for this console it is brilliant! I just have a question, how can I append a \r ? like "hello\r"

I know I can switch at the end to hex, but then I see the notifications in hex too :/

BLE Console

I am new to this app and am trying to figure out all commands but still getting errors I don't understand.
Can you give me some examples of how to write to my device?
Example: how would I write a Bluetooth name?
Write %name ?

little bug in prompt?

I have not been able to understand why there is this little error in the prompt printing (1 "BLE:" moves to the next line):
image

I think is when data is received too fast

With friendly name can we get device info which is already connected BT.

With friendly name can we get device info which is already connected BT.
Like I assume i have mouse logitech mouse mx master, keyboard EGRO860 and Mi phone connected to that.

With this tool last connected is active we are fetching that device info.
is it possible to fetch the device info with friendly name MX master.

Latest build?

I was planning on using the BLE Console for some simple device interaction.
But I'm not sure where I can find the latest build.

The releases page (and click once) all refer to 1.5.6. But according to the releases page, this is from Mar 17, 2018.
The source-code seems to have advanced a lot beyond this point.

Can someone be so kind to create a release/build?

I've tried compiling the sources, but as the compile_hints.txt states I got down the rabbit hole of Windows SDK Kit versions and I'm afraid I'm going to introduce more issues rather than fix them.

Feature Request: Connect to device via bluetooth address

Hi,

I have a lot of ble devices with the same advertising name.
It would be cool if there was a way of connecting to them using the 6-byte bluetooth address. At the moment I don't really have a way of differentiating between the devices using just the name.

Other than that its a really helpful application for testing various communication protocls during development.
Thanks for your effort!

Read characteristic from BLE tinyshield

Hello,

I've been experimenting with a BLE TinyShield paired with a TinyZero from TinyCircuits. Successfully, I managed to establish a connection and issue commands to the Arduino by writing them into the characteristic "Custom Characteristic: 6e400002-b5a3-f393-e0a9-e50e24dcca9e W" (details below). Despite thorough testing of all available characteristics and services, I can't seem to read the data written by the Arduino into the UART characteristic.

Any insights on this? I must admit, I'm quite new to coding.

Thank You!


What I tried using the BLEConsole:
BLE: ls
#Address Name
#00: 49:d7:0d:da:c2:22 no_advertising_name
#1: e1:81:69:a0:a8:53 BlueNRG
#2: c4:07:1f:9f:b2:0b Forerunner 935
BLE: open #1
Device BlueNRG is disconnected.
Connecting to BlueNRG.
Found 3 services:
#00: GenericAttribute
#1: GenericAccess
#2: Custom Service: 6e400001-b5a3-f393-e0a9-e50e24dcca9e
BLE: set #0
Selected service GenericAttribute.
#00: ServiceChanged I
BLE: set #0
Selected service GenericAttribute.
#00: ServiceChanged I
BLE: read #0
Read failed: ProtocolError 0x02: Read Not Permitted
BLE: set #1
Selected service GenericAccess.
#00: DeviceName RW
#1: Appearance RW
#2: PeripheralPreferredConnectionParameters R
BLE: read #0
Read 7 bytes.
utf8: BlueNRG
hex: 42 6C 75 65 4E 52 47
BLE: read #1
Read 2 bytes.
utf8:
hex: 00 00
BLE: read #2
Read 8 bytes.
utf8: ???? ??
hex: FF FF FF FF 00 00 FF FF
BLE: set #2
Selected service Custom Service: 6e400001-b5a3-f393-e0a9-e50e24dcca9e.
#00: Custom Characteristic: 6e400002-b5a3-f393-e0a9-e50e24dcca9e W ---> characteristic I use to write
#1: Custom Characteristic: 6e400003-b5a3-f393-e0a9-e50e24dcca9e N
BLE: read #0
Read failed: ProtocolError 0x02: Read Not Permitted
BLE: read #1
Read failed: ProtocolError 0x02: Read Not Permitted


How the BLE shield writes data inside the characteristic:

uint8_t lib_aci_send_data(uint8_t ignore, uint8_t* sendBuffer, uint8_t sendLength) {
return !Write_UART_TX((char*)sendBuffer, sendLength);
}

uint8_t Write_UART_TX(char* TXdata, uint8_t datasize)
{
tBleStatus ret;

ret = aci_gatt_update_char_value(UARTServHandle, UARTRXCharHandle, 0, datasize, (uint8_t *)TXdata);

if (ret != BLE_STATUS_SUCCESS) {
PRINTF("Error while updating UART characteristic.\n") ;
return BLE_STATUS_ERROR ;
}
return BLE_STATUS_SUCCESS;
}

AND

if (!lib_aci_send_data(PIPE_UART_OVER_BTLE_UART_TX_TX, (uint8_t*)sendBuffer, sendLength))
{
SerialMonitorInterface.println(F("TX dropped!"));
}

Unsubscribe of notifications does not work

In my tests on Windows 10 the command to unsubscribe from e.g. a notification does not work (also affects indications):

await sub.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.None);
https://github.com/sensboston/BLEConsole/blob/master/BLEConsole/Program.cs#L1200

Once you execute the command above the control flow stops and exit Unsubscribe, so it seems to trigger some internal Exception but I wasn't able to catch an Exception.

The command itself seems to be correct just Windows acts totally unexpected. For this reason the unsubs all command does not work at least on the computers I had tested it on.

My guess is that this is some sort of Windows/.net bug.

subs in script

Hello and thank you for this tool!
I am able to pull data from the console from a Nordic Thingy52 without problem e.g.

open Thingy
fmt dec
subs #4/#5

how can I run this from a script and let another application use the output?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.