Eric Hsieh
Eric Hsieh

Reputation: 17

How to execute BLE command in script?

I want to set my bluetooth device on my embedded Linux. I can manually execute below command to enable my BT device, and can scan it from BLE scanner.

#bluetoothctl
#menu advertise
#manufacturer 0xffff 0x12 0x34
#name myAX564
#discoverable on
#back
#advertise on
#menu gatt
#register-service e2d36f99-8909-4136-9a49-d825508b297b
#register-characteristic 0x1234 read
#register-characteristic 0x4567 read,write
#register-application
#back
#power on

However, when I tried to run this within a script, I always met "org.bluex.Error.Failed" after run "register-application".

Below is my script, is there anyone can help this?

#!/usr/bin/expect -f
spawn bluetoothctl
expect "Agent registered"
sleep 1
send -- "menu advertise\r"
expect "Menu advertise:"
sleep 2
send -- "manufacturer 0xffff 0x12 0x34\r"
send -- "name myAX564\r"
send -- "discoverable on\r"
send -- "back\r"
expect "Menu main:"
sleep 2
send -- "advertise on\r"
expect "Advertising object registered "
sleep 4
send -- "menu gatt\r"
expect "Menu gatt:"
sleep 4
send -- "register-service e2d36f99-8909-4136-9a49-d825508b297b\r"
expect "Primary (yes/no):"
sleep 2
send -- "yes\r"
sleep 4
send -- "register-characteristic 0x1234 read\r"
expect "Enter value:"
sleep 2
send -- "0xFA\r"
sleep 4
send -- "register-characteristic 0x4567 read, write\r"
expect "Enter value:"
sleep 2
send -- "0xFE\r"
sleep 4
send -- "register-application\r"
sleep 5
expect "Application registered"
send -- "back\r"
expect "Menu main:"
send -- "power on\r"
expect "Changeing power on succeed"
send -- "exit\r"

Upvotes: -2

Views: 173

Answers (1)

Eric Hsieh
Eric Hsieh

Reputation: 17

It should be:

"register-characteristic 0x4567 read,write"

No space before "write".

Upvotes: 0

Related Questions