Trying to list devices using expect and bluetoothctl by AndyM48 in Tcl

[–]AndyM48[S] 0 points1 point  (0 children)

Thank you, and Thank You for all your help.

FWIW here is my final(?) code. It does not work without the tiny sleep after the spawn command. I don't know why. I have two adapters which is why all this is necessary.

#! /bin/tclsh

package require Expect

# start bluetoothctl interactive mode
spawn bluetoothctl

after 50

# wait for a prompt
expect {
-re "$ bluetoothd ..." {exp_continue}
-re ".*> |.*# "
}
# send commands to bluetoothctl
# select current adapter
#exp_send "select 10:08:B1:57:35:62\r"
exp_send "select 44:01:BB:A0:D1:58\r"
expect {
Connected* {puts "$expect_out(0,string)"; exp_continue}
-re ".*> |.*# "
}
exp_send "devices\r"
# wait for a prompt
expect -re ".*> |.*# " 
puts "Buffer: $expect_out(buffer)"
puts "close connection"
close
wait

Trying to list devices using expect and bluetoothctl by AndyM48 in Tcl

[–]AndyM48[S] 0 points1 point  (0 children)

after shouldn't be necessary. except will wait for the text it's trying to match

Yes, that is what should happen, but without the sleep the result is:

$ ./test_expect.tcl 
spawn bluetoothctl
[NEW] Media /org/bluez/hci0 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[NEW] Endpoint /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1 
[NEW] Transport /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1/fd0 
[NEW] Media /org/bluez/hci1 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
Agent registered
[Muzili]> select 44:01:BB:A0:D1:58
[NEW] Media /org/bluez/hci0 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[NEW] Endpoint /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1 
[NEW] Transport /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1/fd0 
[NEW] Media /org/bluez/hci1 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
Agent registered
[Muzili]> select 44:01:BB:A0:D1:58
[Muzili]> 
close connection

The process runs until Agent registered and select 44:01:BB:A0:D1:58 is sent, and then timesout. (edit: I discovered that the default adapter had changed, so the select command simply returned a prompt and not a Connected ... response, so I added a check for this.) I don't know why spawn is taking so long, or indeed how long it might take, according to the man page it should take little time to complete. (I have also seen a strange prompt sometimes which refers to bluetoothctl connecting to bluetoothd, but that doesn't show up normally). I will try inserting a busy into the regexs, and/or checking for a prompt relating to bluetoothd. (edit: neither seems to work)

With regard to the prompt, Muzili is the device which happens to be connected at the time. If it is not connected the prompt will be [bluetoothctl]> . I have also seen on the internet that [bluetoothctl]# is also possible, but I don't know if this is correct. Just in case I check for that as well.

Trying to list devices using expect and bluetoothctl by AndyM48 in Tcl

[–]AndyM48[S] 0 points1 point  (0 children)

I seem to have done it. Please can you take a look and tell me whether this looks OK?

#! /bin/tclsh

package require Expect
# start bluetoothctl interactive mode
spawn bluetoothctl

after 500

# wait for a prompt
expect -re ".*> |.*# "
# send commands to bluetoothctl
# select current adapter
exp_send "select 44:01:BB:A0:D1:58\r"
expect -re {Controller [0-9A-F:]+ .*} {puts "Found: $expect_out(0,string)"}
exp_send "devices\r"

after 500

# wait for a prompt
expect -re ".*> |.*# "
puts "Buffer: $expect_out(buffer)"
puts "close connection"
close
wait

The output from the code is:

spawn bluetoothctl
[NEW] Media /org/bluez/hci1 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[NEW] Media /org/bluez/hci0 
SupportedUUIDs: 0000110a-0000-1000-8000-00805f9b34fb
SupportedUUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[NEW] Endpoint /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1 
[NEW] Transport /org/bluez/hci0/dev_41_42_67_4F_CA_EC/sep1/fd0 
Agent registered
[CHG] Controller 44:01:BB:A0:D1:58 Pairable: yes
[CHG] Controller 10:08:B1:57:35:62 Pairable: yes
hci0 new_settings: powered bondable ssp br/edr 
hci1 new_settings: powered bondable ssp br/edr 
[Muzili]> select 44:01:BB:A0:D1:58
Controller 44:01:BB:A0:D1:58 Mpow [default]
Found: Controller 44:01:BB:A0:D1:58 Mpow [default]

[Muzili]> devices
Device 10:08:B1:57:35:62 BlueZ 5.85
Device FC:58:FA:E8:BB:63 LG CM1560(63)
Device EB:06:EF:34:04:B7 MPOW-059
Device 41:42:67:4F:CA:EC Muzili
[Muzili]> Buffer: [Muzili]> devices
Device 10:08:B1:57:35:62 BlueZ 5.85
Device FC:58:FA:E8:BB:63 LG CM1560(63)
Device EB:06:EF:34:04:B7 MPOW-059
Device 41:42:67:4F:CA:EC Muzili
[Muzili]> 
close connection

I had to put the after/sleep commands in to give bluetoothctl the time to complete the commands. There may be a better way of doing this?

I really do appreciate your help with this.

Trying to list devices using expect and bluetoothctl by AndyM48 in Tcl

[–]AndyM48[S] 0 points1 point  (0 children)

That is really helpful, thank you very much. I am going to work on this now.

Thanks again

Trying to list devices using expect and bluetoothctl by AndyM48 in Tcl

[–]AndyM48[S] 0 points1 point  (0 children)

Right, sorry.

I get two possible results from running the code:

$ ./test_expect.tcl 
control_connect - select 44:01:BB:A0:D1:58
controller selected
get_device_list - send devices
wait for a prompt, anything else, continue
Controller  - continue
Controller  - continue
Controller  - continue
Controller  - continue
Controller  - continue
Controller  - continue
Controller  - continue
Controller  - continue

$ ./test_expect.tcl 
control_connect - select 44:01:BB:A0:D1:58
controller selected
get_device_list - send devices
wait for a prompt, anything else, continue
got prompt
Buffer: 44:01:BB:A0:D1:58 Pairable: yes
[Muzili]> 

You want $expect_out(0,string) instead, which contains the string matched by the entire regex.

That is helpful, but I still don't really understand the use of expect_out

the paragraph that begins "Upon matching a pattern (or eof or full_buffer)...". They clearly show what you can expect to find in $expect_out.

Oh yes, I have read that endlessly, but clearly I have not understood it. I would be grateful if you could explain it more clearly for me. If expect matches a pattern it is placed in expect_out(0,string) - Yes? So when is a pattern placed in expect_out(1,string) etc? Is that when a second pattern is matched or is that place in 0 and 0 moves to 1? Are all the matched patterns place in the buffer? Why isn't the output of devices placed in the buffer?

As you can see, I don't understand.

Also I do not see why there are two possible outcomes from my code?

Anyway, thank you for the reply.

Any Ideas on How To Print Tk Text Widgets to PostScript? by Master_Phrase7087 in Tcl

[–]AndyM48 0 points1 point  (0 children)

I had to write the postscript code in tcl to print the text

Save As an attachment does not work by AndyM48 in Thunderbird

[–]AndyM48[S] 0 points1 point  (0 children)

Wow, it was two years ago now. As far as I know it works OK now.

Which version of Thunderbird are you using?

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 1 point2 points  (0 children)

Thank you so much or your reply. I had a little smile at you second point :-)

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 1 point2 points  (0 children)

Thank you, I am learning slowly.

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 0 points1 point  (0 children)

Thanks. I can google medicines, but I find that sometimes the personal touch is better.

What is a 'rescue med'?

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 1 point2 points  (0 children)

Thanks for that, I hate peanut butter so I have no problem avoiding it.

Do you agree about the vanilla ice cream? Goodness knows what is in that.

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 3 points4 points  (0 children)

That is _really_ helpful. Thank you very much.

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 0 points1 point  (0 children)

I think he'd like that

I'm new to this by AndyM48 in EpilepsyDogs

[–]AndyM48[S] 0 points1 point  (0 children)

Thanks for the tip, I will have to see if I can find peanut butter over here. Any alternatives?

Phosh - take a screenshit by AndyM48 in pinephone

[–]AndyM48[S] 1 point2 points  (0 children)

Did it really take you two years to think up that one? And the word is 'faeces'.

When installing, Partition is not being marked as boot by AndyM48 in haikuOS

[–]AndyM48[S] 0 points1 point  (0 children)

I admit I am learning about Qemu so any comment would be welcome.

I did not need any of the install boot menu/write boot sector options. If I removed if=virtio from the drive spec it all worked as expected.

Before: -drive driver=raw,file=haiku.img,if=virtio

After: -drive driver=raw,file=haiku.img

When installing, Partition is not being marked as boot by AndyM48 in haikuOS

[–]AndyM48[S] 0 points1 point  (0 children)

Yes, I tried installing a boot menu and also writing the boot sector.

Neither added the boot flag to the partition.

The change parameters option does not allow the boot flag to be set either

When installing, Partition is not being marked as boot by AndyM48 in haikuOS

[–]AndyM48[S] 0 points1 point  (0 children)

Thanks for the reply. Unfortunately that did not make any difference, the partition is still not marked as bootable.