Android Question String for sending commands to a DSD TECH bluetooth card

evolutionfit

Member
Licensed User
Longtime User
Hello

I need an example of a string to send to a BLE card to open a relay.
The command to open it is: "A00101A2".
I can connect to the BLE card but I don't know what commands to use to send the string.
With another Bluetooth card I used SERIAL and TEXWRITER but with the BLE card it doesn't work.

Thank you all
 

evolutionfit

Member
Licensed User
Longtime User
Thanks for the answers.
I would like to understand if you send the command to the relay via manager.writeData () and if it is the right command what to write seeing that the supplier of the board alone as instructions CHANNEL 1 ON: A00101A2. (manager.writeData (xxxxx, xxxxx, xxxx) ???

Emexes may have had the same problem. How do you send the string to the DSD TECH card? Do you have an example please?

Thanks for your help.
 
Upvote 0

emexes

Expert
Licensed User
I don't have an example, but I've whipped one up (bit of a battle to get it going, not sure if it was my computer running out of disk space yesterday, or that copied an existing project and renamed the files) but I have to go out now, so here's what I've got so far.

Run it, and the log will list device id's, eg:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
DeviceFound Id=[A0:E6:F8:4D:1D:26] Name=[63607] RSSI=-53.0
DeviceFound Id=[23:F4:8E:78:C5:FF] Name=[] RSSI=-102.0
DeviceFound Id=[BC:F2:92:56:82:5C] Name=[] RSSI=-81.0
DeviceFound Id=[23:78:65:AA:19:70] Name=[] RSSI=-100.0
DeviceFound Id=[F8:B4:86:32:9D:0A] Name=[34506               ] RSSI=-75.0
DeviceFound Id=[FF:FF:C2:0D:58:00] Name=[iTAG            ] RSSI=-92.0
DeviceFound Id=[4A:07:61:11:D1:4F] Name=[] RSSI=-98.0
DeviceFound Id=[43:E3:E8:88:22:6A] Name=[] RSSI=-94.0
Whatever the id is of your relay board, put that in the BLEIdFilter at the top of Starter module.

Run it again, and the log will connect to the board and list the available services.

Post that run's log, and when I get back, we'll keep going.

What could possibly go wrong?!?!
 

Attachments

  • BLEDSD.zip
    9.7 KB · Views: 258
Upvote 0

emexes

Expert
Licensed User
Once we're connected to the relay board, and we know the service and characteristic UUID's, then controlling the relays should be a case of adding this to the Starter module:

B4X:
Sub SetRelay(RelayNumber As Int, RelayState As Int)

    Dim NumRelays As Int = 8

    If RelayNumber < 1 or RelayNumber > NumRelays Then
        Log("Relay " & RelayNumber & "?  Really?")    'help me help you
        Return
    End If

    'protocol per "documentation" found at: https://www.aliexpress.com/item/32892267055.html
    'Control instruction(Hexadecimal format):
    'Channel 1 ON: A00101A2
    'Channel 1 OFF: A00100A1
    'Channel 2 ON: A00201A3
    'Channel 2 OFF: A00200A2

    Dim Cmd(4) As Byte

    'Sync/Header = A0 (hexadecimal) = 160 (decimal)
    Cmd(0) = 0xA0
 
    'Relay Number : 01 = first relay, 02 = second relay (and etc for > 2 relays, presumably)
    Cmd(1) = relayNumber

    'Relay State : 00 = off, 01 = on
    Cmd(2) = Min(Abs(RelayState), 1)    '= 0 if RelayState 0, otherwise = 1

    'Checksum = sum of preceding bytes (eg, Channel 2 OFF = A0 + 02 + 00 = A2)
    Cmd(3) = Cmd(0) + Cmd(1) + Cmd(2)

    manager.WriteData(BLEService, BLECharacteristic, Cmd)

End Sub

'and perhaps these two helper functions (not necessary, just nice):

Sub SetRelayOff(RelayNumber As Int)

    SetRelay(RelayNumber, 0)

End If

Sub SetRelayOn(RelayNumber As Int)

    SetRelay(RelayNumber, 1)

End If
and then from elsewhere in the program you would eg:
B4X:
CallSub2(Starter, "SetRelayOn", 3)    'turn relay 3 on
CallSub2(Starter, "SetRelayOff", 5)    'no prize for guessing what this might do
 
Last edited:
Upvote 0
Top