0

I am working on a project where i have a motion sensor connected to a arduino connected to a raspberry pi and when the motion sensor detects movement i turn of my Windows pc. I want to connect the raspberry pi to my pc with bluetooth, i have a 'raspberry pi zero w 1.1' so it does have bluetooth. But i dont know how to connect it to my pc. And i also need to send data to my pc (over this bluetooth connection). It only needs to be just one byte only to tell the computer movement was detected (then ill turn the pc off using python)

Does anyone know how to set up this connection and send data?

Btw: if this is easyer with wifi thats fine as wel

2
  • What OS is your PC running? – FelixJN Dec 26 '20 at 21:14
  • My pc is running windows, my raspberry pi can be running any os – a-bad-js-developer Dec 26 '20 at 22:19
0
  • Assuming your PC's bluetooth device is AB:12:34:45:67:78.

  • On Windows reveiver: Create a COMM port on Windows - listen mode.

  • On the Pi sender: Elevate yourself to root or use sudo.

  • Establish a connection with bluetoothclt -> scan on, pair AB:12:34:45:67:78

  • Bind your connection with rfcomm

    rfcomm bind 0 AB:12:34:45:67:78
    
  • You now have a new entry in /dev/rfcomm0

  • Send whatever output there.

    echo "die nasty PC!" > /dev/rfcomm0 
    
  • Do your python magic on the Windows receiver side.

1
  • 1
    hciattach, hciconfig, hcitool, hcidump, rfcomm, sdptool, ciptool, and gatttool were deprecated by the BlueZ project in 2017 so I would be cautious of starting a new project with those tools. – ukBaz Dec 26 '20 at 23:51
0

If you have Python 3.9 on your Windows PC then you can create a Serial Port Profile (SPP) client with the Socket library.

There is more information about Bluetooth with Python sockets at: https://blog.kevindoran.co/bluetooth-programming-with-python-3/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.