Seite 1 von 1

Linux/Raspi - Bluetooth-Serial-Terminal

Verfasst: 15.01.2022 22:59
von ccode_new
Hi!

Kennt jemand eine bessere/elegantere Lösung eine Bluetooth-Serial-Terminal-Verbindung zu ermöglichen.

Bisher:
  • Edit:
    sudo nano /etc/systemd/system/dbus-org.bluez.service

    Diese Zeile erweitern:
    ExecStart=/usr/lib/bluetooth/bluetoothd -C --noplugin=sap
    Diese Zeile danach einfügen:
    ExecStartPost=/usr/bin/sdptool add SP

    Speichern

    Erstellen eines neuen "rfcomm" - Ports:
    Edit:
    sudo nano /etc/systemd/system/rfcomm.service

    [Unit]
    Description=RFCOMM service
    After=bluetooth.service
    Requires=bluetooth.service

    [Service]
    ExecStart=/usr/bin/rfcomm watch hci0
    Restart=on-failure
    RestartSec=5s
    RemainAfterExit=yes

    Speichern

    sudo systemctl enable rfcomm

    sudo reboot
Danach:
Ein Serial-Port mit PureBasic öffnen.
Beispiel:

Code: Alles auswählen

IncludeFile "Serial.pbi" 

Global Text.s

UseModule Serial

MeinPort.Serial = new()

MeinPort\open("/dev/rfcomm0", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake)

If MeinPort\isOpen()
  Debug "Das Port ist geoeffnet."

  MeinPort\sendData(Ascii(~"Hallo vom Raspi!!!\n"), 19)
  MeinPort\sendData(Ascii("Huhu!!!"), 7)

  Repeat
    Text = MeinPort\receiveString()
    Debug Text
  Until Text = "exit"
Else
  Debug "Geht nicht!"
EndIf

MeinPort\close()

MeinPort\free()

UnuseModule Serial
End