GithubHelp home page GithubHelp logo

reformationpro / bluez-rfcomm-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from 5cript/bluez-rfcomm-example

0.0 0.0 0.0 42 KB

An example to register an RFCOMM server using dbus-mock

License: The Unlicense

C++ 95.09% CMake 4.91%

bluez-rfcomm-example's Introduction

bluez-rfcomm-example

An example to register an RFCOMM server using my dbus-glue library. But this is useful for everyone trying to implement a bluez serial service. You can use the sdbus++ library, or any dbus lib. The code should be understandable enough for that.

This provides a simplified example project from which a more powerful and useful server can be build upon.

Since getting to this point in C++ was an absolute nightmare, I decided to share my efforts here.

Could contain bugs.

What have I learned.

  1. The bluez documentation is a HUGE pain.

  2. The sdbus documentation is a HUGE pain.

  3. The name of all interfaces registered with "sd_bus_add_object_vtable" are gathered under the given sd_bus* instance. This instance can be named with "sd_bus_request_name" (which has no documentation). The naming is possible without any further work on the session (user) bus, but requires special permissions on the system bus. https://stackoverflow.com/questions/32828468/sd-bus-api-sd-bus-request-name-returns-permission-denied

  4. Despite all the horribly outdated sources, creating and binding your own socket is not needed. Bluez does that for you. Scrap all that legacy code and just use the dbus methods.

  5. In order to create a rfcomm server, you have to first register a new interface on the bus with a given object path and the type "org.bluez.Profile1". The "NewConnection" function is called whenever a new connection is made. You then take control of the file descriptor and handle read/writes from there.

  6. To tell bluez that you just registered/exposed this new Profile1 interface, you have to call "RegisterProfile". this method takes an object_path (to the "Profile1" interface of yours that you created), A uuid and options. this uuid cannot be chosen willy nilly - it identifies the bluetooth service and is unique to this service. The client connects to a specific id. Use the SerialPortServiceClass uuid if you want to be THE serial bluetooth service of your device. The function also takes a dictionary with options, for which the documentation is somewhat sufficient for once: https://github.com/pauloborges/bluez/blob/master/doc/profile-api.txt

  7. I dont know if the passed channel matters at all. In my testing with common android apps, it doesn't. I dont know how the handle their connect.

Building

Everything will be contained within "bluetoot_project".

Troubleshooting

Unit dbus-org.bluez.service not found

Start the bluetooth service that exposes the dbus interfaces: sudo systemctl start bluetooth.

could not give myself a name: Permission denied

See point 3) above

bluez-rfcomm-example's People

Contributors

5cript avatar soicew avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.