Memotech-Bill / bluetooth-stdio

STDIO over Bluetooth for Pico_W C SDK
Other
5 stars 0 forks source link

Missing file: sd_spi.pio #3

Open tjko opened 5 months ago

tjko commented 5 months ago

CMakeLists.txt refers to a PIO file that is not included in the repository: sd_spi.pio Is this file needed?

Commenting out the reference seemed to allow library to compile at least:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e33c81..24691de 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,7 +8,7 @@ if (NOT TARGET bluetooth_stdio)
     ${CMAKE_CURRENT_LIST_DIR}
     )

-  pico_generate_pio_header(bluetooth_stdio ${CMAKE_CURRENT_LIST_DIR}/sd_spi.pio)
+#  pico_generate_pio_header(bluetooth_stdio ${CMAKE_CURRENT_LIST_DIR}/sd_spi.pio)

   target_sources(bluetooth_stdio INTERFACE
     ${CMAKE_CURRENT_LIST_DIR}/stdio_bt.c
Memotech-Bill commented 5 months ago

The PIO file is not required. The statement in CMakeLists.txt was a hang-over from the project from which this repository was extracted.

Now removed.

tjko commented 5 months ago

Thanks, I did some initial testing with the library (on Raspberry Pi 5) and it sees and pairs fine, but serial port does not appear... I do have WiFi stack in use as well, not sure if that is causing some conflict...

Feb 08 18:32:36 raspberrypi kernel: **Bluetooth: Unexpected continuation frame (len 0)**

Does this library require something specific in __btstack_config.h__? I used one from pico-examples to do the test...

Just a thought, it would be nice to have a test/example included that demonstrates this library. Something very simple, like echoing back typed in characters, etc...

Memotech-Bill commented 5 months ago

I have now added a simple example in the test folder.

There is a non-trivial example with both BT and WiFi here. This repository was created by extracting the BT code from that source.

tjko commented 5 months ago

Thanks!

I tested the example (_bttest.elf) with a Raspberry Pi 5, and pairing works but it doesn't find any services:

image

With MacOS, pairing works OK as well, and serial device appears (/dev/cu.PicoXXXXXXXXXX), but it only works for little while... Seems like after sending one line of text and then connection 'dies'...
Resetting Pico W doesn't seem to make difference, only re-pairing seems to get connection to establish again, but only for few seconds...

MacOS side:

% tio /dev/cu.Pico28CDC1xxxxxx
[19:58:03.424] tio v2.5
[19:58:03.425] Press ctrl-t q to quit
[19:58:03.425] Connected
Waiting for BT connection...32
Connected...
test1

Pico W side (USB connection):

Waiting for BT connection...24
Waiting for BT connection...25
Waiting for BT connection...26
Waiting for BT connection...27
Waiting for BT connection...28
Waiting for BT connection...29
Waiting for BT connection...30
Waiting for BT connection...31
Waiting for BT connection...32
Connected...
test1

I added couple printf() statements to the example to get some insight what was going on...

diff --git a/test/bt_test.c b/test/bt_test.c
index 4f15b6a..da926b7 100644
--- a/test/bt_test.c
+++ b/test/bt_test.c
@@ -14,15 +14,17 @@ int main (void)
     stdio_set_driver_enabled (&stdio_bt, true);

     // Wait for connection
-    
+    int counter = 0;
     int iLED = 0;
        while (true)
         {
+               printf("Waiting for BT connection...%d\n", counter++);
                iLED ^= 1;
                cyw43_arch_gpio_put (CYW43_WL_GPIO_LED_PIN, iLED);
                if ( stdio_bt_connected() ) break;
                sleep_ms(1000);
         }
+    printf("Connected...\n");
     cyw43_arch_gpio_put (CYW43_WL_GPIO_LED_PIN, 0);

     // Echo input lines
tjko commented 5 months ago

I was testing with SDK v1.5.1. I'll check if "spp_counter" from pico-examples works any better....

Memotech-Bill commented 5 months ago

I have been testing with an Intel laptop running Ubuntu:

Memotech-Bill commented 5 months ago

Testing from a Raspberry Pi. In a command window:

pi@raspberrypi:~ $ bluetoothctl
Agent registered
[CHG] Controller DC:A6:32:49:34:E0 Pairable: yes
[bluetooth]# discoverable on
Changing discoverable on succeeded
[CHG] Controller DC:A6:32:49:34:E0 Discoverable: yes
[bluetooth]# pairable on
Changing pairable on succeeded
[bluetooth]# agent on
Agent is already registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller DC:A6:32:49:34:E0 Discovering: yes
[NEW] Device 2C:B4:3A:08:07:D5 2C-B4-3A-08-07-D5
[NEW] Device 4C:FA:7A:18:81:1E 4C-FA-7A-18-81-1E
[NEW] Device 28:CD:C1:02:56:99 Pico 28:CD:C1:02:56:99
[bluetooth]# pair 28:CD:C1:02:56:99
Attempting to pair with 28:CD:C1:02:56:99
[CHG] Device 28:CD:C1:02:56:99 Connected: yes
[CHG] Controller DC:A6:32:49:34:E0 Discoverable: no
Request confirmation
[agent] Confirm passkey 235229 (yes/no): yes
[CHG] Device 28:CD:C1:02:56:99 UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[CHG] Device 28:CD:C1:02:56:99 ServicesResolved: yes
[CHG] Device 28:CD:C1:02:56:99 Paired: yes
Pairing successful
[CHG] Device 28:CD:C1:02:56:99 ServicesResolved: no
[CHG] Device 28:CD:C1:02:56:99 Connected: no
[CHG] Device 2C:B4:3A:08:07:D5 RSSI: -78
[bluetooth]# scan off
Discovery stopped
[CHG] Device 28:CD:C1:02:56:99 RSSI is nil
[CHG] Device 4C:FA:7A:18:81:1E TxPower is nil
[CHG] Device 4C:FA:7A:18:81:1E RSSI is nil
[CHG] Device 2C:B4:3A:08:07:D5 RSSI is nil
[CHG] Controller DC:A6:32:49:34:E0 Discovering: no
[DEL] Device 2C:B4:3A:08:07:D5 2C-B4-3A-08-07-D5
[DEL] Device 4C:FA:7A:18:81:1E 4C-FA-7A-18-81-1E
[bluetooth]# trust 28:CD:C1:02:56:99
[CHG] Device 28:CD:C1:02:56:99 Trusted: yes
Changing 28:CD:C1:02:56:99 trust succeeded
[bluetooth]# exit
pi@raspberrypi:~ $ sudo rfcomm connect hci0 28:CD:C1:02:56:99
Connected /dev/rfcomm0 to 28:CD:C1:02:56:99 on channel 1
Press CTRL-C for hangup

From a second command window:

pi@raspberrypi:~ $ picocom /dev/rfcomm0 
picocom v3.1

port is        : /dev/rfcomm0
flowcontrol    : none
baudrate is    : 9600
parity is      : none
databits are   : 8
stopbits are   : 1
escape is      : C-a
local echo is  : no
noinit is      : no
noreset is     : no
hangup is      : no
nolock is      : no
send_cmd is    : sz -vv
receive_cmd is : rz -vv -E
imap is        : 
omap is        : 
emap is        : crcrlf,delbs,
logfile is     : none
initstring     : none
exit_after is  : not set
exit is        : no

Type [C-a] [C-h] to see available commands
Terminal ready
Hello
Testing
This seems to work

The following sources were used in working out how to do this: https://bluedot.readthedocs.io/en/latest/pairpipi.html#using-the-command-line https://forums.raspberrypi.com/viewtopic.php?t=199308#p1244334

tjko commented 5 months ago

Thanks, I'll check the CLI approach on RPi, I only did quick test from the UI since I assumed 20+ year old Bluetooth Serial Profile surely should be supported by now :) If its just issue that latest Raspberry Pi OS doesn't have BT Serial support on the GUI, then that would explain what I saw. But point to there possibly being some issue with Pico W Bluetooth stack, since other Bluetooth SPP devices have worked just fine on MacOS...

I had been testing on old Pico W (from very early production runs), so I ordered a new one to rule out its nothing to do with the hardware as well.