How to use data wedge to connect to non scanner bluetooth device? - bluetooth

I have a use case for connecting with a arbitrary bluetooth device (not a scanner). I have the following questions -
Is it possible to connect data wedge to a random bluetooth device to send and receive data? I was unable to find any example online in docs or elsewhere. The idea is that the bluetooth device will dump data to its outputstream, and i am hoping data wedge can pick it up and insert in my app field.
Can data wedge also send requests to the bluetooth device? ( Or can it only be a listener and receive data? ) If yes, how to we configure the request string and frequency.
In our use case the data is a long string (eg - "a,b,c,d"). My idea is to send this string to a text field and then segregate it in application itself.
Our use case is for TC 56 devices. As i understand it, the application app listens for the intent data wedge generates post scanning. Can it work seamless on laptops as well? The service in our use case is a web app.

Related

HM-10 BLE Module - connect to other Devices

first of all: What i am trying to do is only for private interest.
I'd like to connect a AT-09/HM-10 BLE-Module with Firmware 6.01 to another device which provides also a BLE Module, which it is not based on the CC254X-Chip,
I am able to communicate with this Device using my Laptop with integrated Bluetooth, Linux and the bluepy-helper. I am also able to make a connection using the HM10 through a USB-RS232-Module and "Hterm", but after that quite Stuck in my progress.
By "reverse-engineering" the Android-Application for controlling this particular device i found a set of Commands, stored as Strings in Hex-Format. The Java-Application itself sends out the particular Command combined with a CRC16-Modbus-Value in addition with a Request (whatever it is), to a particular Service and Characteristic UUID.
I also have a Wireshark-Protocol pulled from my Android-Phone while the application was connected to the particular device, but i am unable to find the commands extracted from the .apk in this protocol.
This is where i get stuck. After making a connection and sending out the Command+CRC16-Value i get no response at all, so i am thinking that my intentions are wrong. I am also not quite sure how the HM-10-Firmware handles / maps the Service and Char-UUIDs from the destination device.
Are there probably any special AT-Commands which would fit my need?
I am absolutely not into the technical depths of Bluetooth and its communication layer at all. The only thing i know is that the HM-10 connects to a selected BLE-Device and after that it provides a Serial I/O and data flows between the endpoints.
I have no clue how and if it can handle Data flow to certain Service/Char UUIDs from the destination endpoint, althrough it seems to have built-in the GATT , l2cap-Services and so on. Surely it handles all the neccessary communication by itself, but i don´t know where i get access to the "front-end" at all.
Best regards !

Send data using over bluetooth using different protocols

I have an app that communicates with a bluetooth device, and I'm trying to replace that app with some code.
I tried using C# InTheHand nuget, Microsoft's Bluetooth LE Explorer, python's sockets and others to send data and see what happens.
But there's something I still don't understand - in each way using different libraries I saw in wireshark a different protocol: ATT, RFCOMM, L2CAP...
When I sniffed my bluetooth traffic from my phone using the app mentioned before, I saw mostly HCI_CMD protocol traffic.
How can I choose the protocol I want to send? Is there a simple package for that? something to read?
Do I need to build the packet myself? including headers and such?
Thank you!
Update:
Using Microsoft's Bluetooth LE Explorer I was able to send a packet that lit up my lamp, starting with 02010e10000c00040012(data)
Using bleak I was able to send a packet starting with 02010e10000c00040052(data)
the difference makes the lamp not ligh up and I'm not sure if I can change it via bleak as it's not part of the data I send
I think what you are showing is that bleak does a write without response while MS BLE Explorer does a write_with_response.
Looking at the Bleak documentation for write_gatt_char that seems to be consistent as response is False by default
write_gatt_char Parameters:
char_specifier (BleakGATTCharacteristic, int, str or UUID). The characteristic to write to, specified by either integer handle, UUID
or directly by the BleakGATTCharacteristic object representing it.
data (bytes or bytearray) – The data to send.
response (bool) – If write-with-response operation should be done. Defaults to False.
I would expect the following to have the desired effect:
await client.write_gatt_char(LIGHT_CHARACTERISTIC, b"\x55\xaa\x03\x08\x02\xff\x00\xff\xf5", True)

Reverse engineering Bluetooth LE - device sends weird responses back

I recently aquired a Segway Ninebot ES2 electric scooter. I can connect to the scooter via Bluetooth LE and grab information such as battery status, current mileage, temperature, and so on. This is all done through an application.
On my Android device, I've successfully extraceted the HCI log file, which I imported into Wireshark. I can see all the requests and commands send back and forth between my phone and the scooter. However, the requests and responses are all garbage and I have no idea how to interpret them.
Example of a sent command (info says Sent Write Command, Handle: 0x000e (Nordic UART Service: Nordic UART Tx))
Example of the received value I got right after (info says Rcvd Handle Value Notification, Handle: 0x000b (Nordic UART Service: Nordic UART Rx))
How am I supposed to interpret these responses? If the battery status was 59%, I would expect it to return something like 0x3b (0x3b hex is 59 decimal). But honestly, I have no idea how this works. Maybe they're returning a bunch of data in a data type only their app knows how to interpret? Like JSON for web.
Here's an example from the nRF Connect for Mobile application, where I hit the down arrow on all the characteristics: https://i.imgur.com/hREDomP.jpg (large image)
And probably more important: How do I replicate a request or command in nRF Connect? I've tried sending a byte array that looks like 0x {02410011000d.....} (from the Write Command) in the application, but I have no idea how to read the response.
If someone is still interested, I did the same research for this scooter.
That's standart BLE communacation, device offers BLE "services" and "characteristics". Service can contain one or more characteristics, by which you communicate with device. Each charateristic can allow different types of interaction with it: writing into it, reading from it, subscribing to notifications (so you dont have to to manually read, it kinda pushes data to your app), and more (read here, for example)
Take a look at your wireshark screenshot: you can see Service UUID, Handle UUID (the characteristic), and handle ID. You can communicate with device via uuid or id, depending on your programming language or library (more about uuids).
In this particular scooter there are two characteristics, one allows writing into it, another - allows subscribing to it. Together, they act like RX and TX wires in UART: you write data into one and read from another. So, to begin communication with scooter you must establish connection to it, subscribe for notifications from one ch, and write data to another.
As for protocol: look again at she screenshots, "UART Tx" is the actual payload that was sent to scooter and "UART Rx" was the response. Yes, it's binary data, that only app would understand. Luckily, protocol has been reverse engineered and is well documented. In your example app requests serial number, and it's returned in response - "N2GWX...". In order to request battery percentage you must build another payload according to protocol.
I'm not sure if it's still relevant, but at least for those, who will be interested in the topic.
You can try the following to understand how to interpret response from the device.
An option to consider is to fetch manufacturer's mobile app (apk) either by adb or from sites like apkmirror, etc.
Then apply some reverse-eng tool like JADX.
If you're lucky and the code is somewhat readable, then search for smth that has to do with response (like ResponseParser) and try to find algo that is used to interpret the response.
However, the very first attemp should always be to search on github/google if smb did it already for your device, unless it's very niche.

Manufacturer Specific Data on BLE

I'm a newbie of BLE programming on android.
In my first apps using BLE on android, I have a big problem.
I got a ScanRecord from Apple Bluetooth Headset using this function.
#Override
public void onScanResult(int callbackType, ScanResult result)
and I got a manufacturer data using Apple corp, ID(0x4C).
after that, I don't know how to decode a manufacturer data.
I want to auxiliary bluetooth headset information such as battery info, direction info etc. but I don't know how to decode the manufacturer data.
I also searched Apple development document(https://developer.apple.com/accessories/Accessory-Design-Guidelines.pdf)
But that guide document didn't help me.
Anyway, anyone who tell me how to resolve this problem?!!?!
Thank you to read my question.
Ok so from your comment it looks like you scanned the device over BLE and want to use one of the services it offers to get information like battery info.
The first thing you will need to do establish a connection to the BLE device.
The scanresult you pasted has a method getDevice you'll need to call
After you get the device you can call its connectGatt method. This will attempt to connect your phone and BLE device.
The connectGatt method from step 2 requires a callback. When the connection is successful or unsuccessful the callback will fire onConnectionStateChanged. If successful it will have the success status. This method will also give you a gatt device we will use in step 4.
If step 3 was successful we can assume your phone is connected. The next thing we want to do is discover services. You do this by using the gatt devices discoverServices method.
When the services are discovered your callback will fire onServicesDiscovered. At this point you can now use services. Depending on the API of the headphones they'll want you to read, or subscribe to a services characteristic and descriptor. Since I don't know the API I can't help you further. But you'll end up needing to use one or more of the following:
setCharacteristicNotification
readCharacteristic
readDescriptor
And the value will return to your callback on. Keep in mind you must wait for the callback for each request before write/reading/subscribing to another characteristic or descriptor.

Thingsboard; Data about same sensor, but from a different (multiple) gateway

I have just started using Thingsboard and made some good progress in understanding how some of the basic stuff works ( mainly sending sensor data using mqtt ). But I have come to a complete halt at one point. Here is an explanation of the problem. Thingsboard version is 1.3.1
My setup:
4x RPi (Raspberry Pi) used as gateways to gather data from bluetooth
beacons
A set of bluetooth beacons
Here's what the system is supposed to do:
Send periodic data from the gateways ( RPi ) to inform thingsboard that the gateway is alive
The above part is working fine. I have set up the gateways to connect to thingsboard using access token, and post the data ( both the attributes and telemetry ). For sending attributes I use "v1/devices/me/attributes" and for telemetry data I use "v1/devices/me/telemetry", as mentioned in the documentation.
A typical string from the gateway indicating that it is alive is
{"gwA.macid": "00:00:00:00:00:00", "gwA.timestamp": "2018-02-16T19:20+01:00"}
The above part is working well. This is just for an indication that the gateway is well and able to communicate with the Thingsboard server. All the gateways connect to thingsboard using it's own respective access token and posts the above data.
Now the problem part ( or where I got halted )
The gateways gather the data about the nearby bluetooth beacons and post it too.
The data format in which the gateways posts the beacon data is
{"bcn000001.mac": "00:00:00:00:00:00", "bcn000001.timeepoch": 1518939044}
The gateway ensures that each beacon data will have the correct prefix. For example
{"bcn000001.mac": "50:80:25:AA:BB:CC", "bcn000001.timeepoch": 1518939044}
{"bcn000002.mac": "50:80:25:RR:AA:DD", "bcn000002.timeepoch": 1518939039}
{"bcn000003.mac": "50:80:25:GG:33:EE", "bcn000003.timeepoch": 1518939020}
But the data about the same sensor can also come from another gateway. How do I show it on a single widget irrespective of which gateway the data comes from. If I choose "entity list" then either it does not work, or shows up all the 4 RPi gateways on the widget. This is not what I want. I have attached an image. I am not sure if I am able to explain this well but pls do let me know if there is any other information that I can furnish. I am adding an image to point to some things that I just mentioned. I have even separated the data out by using a prefix ( as mentioned in one of the earlier SO posts ). I have spent close to couple of days on this. This was not supposed to be difficult. At least that's what I thought when I got started.
Note: As I explore, I just learnt (realized) one more thing. I think this part was a little confusing so I thought I should inform others. When one adds a device in Thingsboard, there is an option to specify if the device "Is a Gateway". What it is trying to tell(ask?) is that whether thingsboard gateway service is installed on that device. In my case I made the mistake(?) of thinking that a device that gathers data from sensors and posts it to the server is a gateway device. I guess I'll try to install thingsboard gateway service on the raspberry pi, then see how it goes. I'll post an update once I am done but in the meantime any useful comments or suggestions - please keep em coming.
I have seen others ask very similar question on SO. Something fundamental like this shouldn't be so difficult. No point in have a hundred pages of documentation without a clear explanation of most basic steps towards setting up an IoT backend/dashboard. All I wanted to do is to display the same sensor data ( say Sensor A ) coming from "any one of the devices", to show on the same widget. If I choose single entity, the widget won't update if the data comes from other device. If I choose entity list, and turn on "Resolve as multiple entities", then I end up with the widget showing all the devices
you are using wrong API. The API you are looking for is gateway API which allows to push telemetry and other messages on behalf of other devices. Please use this API https://thingsboard.io/docs/reference/gateway-mqtt-api/ on the Raspberry Pi gateways. You can also use our Gateway project and modify it for your needs.

Resources