Android Question Connect to BLE DSD Relay board

mauro vicamini

Active Member
Licensed User
Longtime User
Hi Evreyone,
I'm traying to comunicate with with a BLE DSD Relay Board to send commands to activate/deactivate relay.
Using the instructions in the post https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/ I've done the connection with the board, but I don't know how to write data to it, or better I don't understand what service/Characteristic use with the WriteData method.
How to identify which service and which Characteristic from the service list of the Connected event and/or by the AdvertisingData in the DeviceFound event.
The services that I've found are :

00001800-0000-1000-8000-00805f9b34fb
00001801-0000-1000-8000-00805f9b34fb
0000180a-0000-1000-8000-00805f9b34fb
0000ffe0-0000-1000-8000-00805f9b34fb

The advertisingdata are:
(MyMap) {1=[B@a9d29c6, 2=[B@cc94d87, 9=[B@4bf54b4, 18=[B@87e18dd, 10=[B@1321c52, 0=[B@633b23}

What are the steps to indetify the service and Characteristic to use with the writedata method to send commands to the board.

I wonder how does the App Serial Bluetooth Terminal to connect to the board easily (identifying it as BLE device) and permit to send the hexidecimal command without specify what service and Characteristic use.

Please help!

Thanks for the attention.
 

emexes

Expert
Licensed User
edit: read the next post first (but I'll leave this post here just in case there's something useful in it)

Knowing nothing of this relay board, but looking at:

Amazon: DSD TECH 4 Channels Bluetooth Relay Module

the BLE module looks like (eg chip and component layout):

Ebay: DSD Tech Shhc08 Bluetooth 4.0 Ble Slave Module to UART Transceiver

and the "Shhc08" suggests that it is a HC-08 module which is a clone/knockoff of the original HM-10 module for which information is available from the manufacturer:

Jinan Huamao: Download Center

downloading the "BLE 4.0 modules(HM-10;HM-11)" link, which returns a 3MB Zip of documents etc called "bluetooth40_en.zip"

OR (AND?)

have a look at this seriously-good blog post about the BLE UART module:

HM-10 Bluetooth 4 BLE Modules - Martyn Currey

In summary, you send bytes to the BLE module by writing to characteristic FFE1 (max. 20 bytes per write) and you receive bytes from the BLE module by notifications of the same characteristic. NOTE THAT YOU NEED TO ENABLE NOTIFICATIONS, ie you can't just read the characteristic like you would expect.

Once you're able to communicate with the relay board (same as you already can with the BLE terminal program, going by your post), then you should be able to likewise send commands from your program. I don't know what the commands look like, but presumably there is documentation with the relay board that tells you what they are. If they are human-readable (and typeable) plain ASCII commands, then you should be able to send the commands from the terminal program too, to confirm that you're sending the right commands, and also that the Android BLE and HM10/HC08 BLE module can talk to each other.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Hey Mauro, I thought: how hard can it be to find out how to control those relays?

Turns out: quite hard :-(

DSD Tech seem to have no documentation about controlling their relay boards. They do tell you how to connect to the boards using generic BLE apps, but they then seem to expect that you'll be using their Android/iOS app to control the relays.

I started thinking that maybe they are using the general I/O pins (16 to 19) of the BLE module, but then I found this:

Ali Expresss: DSD TECH 2 Channels Bluetooth Relay module

which quietly mentions (perhaps accidentally ;-)

Control instruction(Hexadecimal format):
Channel 1 ON: A00101A2
Channel 1 OFF: A00100A1
Channel 2 ON: A00201A3
Channel 2 OFF: A00200A2

and so what I infer from that is:

To switch a relay on or off, send a 4-byte command packet in the format:

Byte 1 = Sync/Header = A0 (hexadecimal) = 160 (decimal)
Byte 2 = Relay Number : 01 = first relay, 02 = second relay (and etc for > 2 relays, presumably)
Byte 3 = Relay State : 00 = off, 01 = on
Byte 4 = Checksum = sum of preceding bytes (eg, Channel 2 OFF = A0 + 02 + 00 = A2)

Note that it is NOT ASCII, so don't ye be adding end-of-line characters (although it'll probably still work even if you do, thanks to the Sync/Header byte)

Given that it's a one-way protocol (or at least, that's all we currently need) then you can ignore the part in the previous post about enabling notifications.

All you have to do is send your 4-byte commands to characteristic FFE1 which is under the FFE0 service that you've already discovered, if I understand your opening post correctly.

What could possibly go wrong?!?!

 
Upvote 0

mauro vicamini

Active Member
Licensed User
Longtime User

Thanks so much emexes!!!
The board is right the Ali Expresss: DSD TECH 2 Channels Bluetooth Relay module.
I already know the hexadecimal command A00100A2 to send because was wrote on the Amazon page.
What it was obscure to me is the service and the charateristic to use: tomorrow I surely try your advice to use characteristic FFE1 which is under the FFE0 service. And for this I'm really thankfull with you.
But what I'd like to know is how does a genereic app like Serial Bluetooth Terminal that is not a DSD app, but a generic app to connect bluetooth devices, once identified and connected the DSD device to understand, without any hint, the right service and characteristic to use. I've try it sending the hexidecimal commands to DSD device and it works like a charm.
I know that at the base of the question ther is my huge lack in BLE philosophy, but I think that there is some kind of indication in some byte of service UUID or the advertisingdata (by the way: what rapresent the advertise data?) to find out which characteristic is writeble and , most important, how to find the characteristics.

Thanks so much again emexes, I will let you know if it's all ok with your advice.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
the right service and characteristic to use
try this example https://www.b4x.com/android/forum/threads/ble-2-bluetooth-low-energy.59937/
Does it list all characteristics?
tomorrow I surely try your advice to use characteristic FFE1 which is under the FFE0 service. And for this I'm really thankfull with you.

check this document: https://drive.google.com/file/d/1aUKZaKQnj6v4Jz-hOtDGEAVyBKMAJmQk/view
i found it using a small google search.
 
Upvote 0

emexes

Expert
Licensed User
My understanding is that using the EE01 characteristic for BLE UART emulation is a defacto standard set by the HM-10. If you hunt around in the Serial Bluetooth Terminal app's settings, you'll probably find an option to set which characteristic to use, and they've defaulted it to EE01 because 99% of the time, that's what works.

Imagine their support load if every person who wanted to use it had to spend a half-hour trawling through the HM-10/HC-08 documentation. Perhaps that's even what happened originally ;-)
 
Upvote 0

mauro vicamini

Active Member
Licensed User
Longtime User
You are so right Emexes! Looking around in the Serial Terminal Bluetooth app I've found in the info that is developed for some specific devices (that are the leading ones on the market) and between them there is the HM-10 chip.
Well I've got my answers and now go to develop my app.
Thanks once again to Emexes and DonManfred, but also the whole community that is always so reactive!
 
Upvote 0

emexes

Expert
Licensed User
Mauro was reading and writing to the relay board, and we got tripped up by the fact that reads could only be done via notifications.

But if the relay board is output only, it might be that you only need to do Bluetooth Low Energy writes, not reads.

That could be simpler.

If you could post some information about the board you have, that would be good.

;-)
 
Last edited:
Upvote 0

GeorgManfred

New Member
Licensed User
Hello, everyone,
I want to program an app to control a DSD relay module. For days I tried everything without success. The discussion on this page helped me a lot and now my B4A app works great. Thank you all.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…