Writing Gatt Server Application in Bluez - linux

We want to write a custom Gatt Server Application for Bluez where we want to give some useful features. For example:
Start Gatt Server
Register/Unregister custom Service
Add/Remove custom Characteristics/Descriptor
Set/Get Value of Characteristics/Descriptor
Disconnect Client / Close Gatt Server etc.
Bluez don't have these features in command line tool but they have several APIs (functions) to do that, we need to call those internal functions.
In according to that we wrote an application in "bluez5.28/attrib/" directory from where we called several internal functions from files of
"bluez5.28/attrib/", "bluez5.28/profiles/" and "bluez5.28/src/" directories and tried to build it with bluez Makefile.
Since bluez have automated generated make file from automake it is quiet hard to make any change in that Makefile. But when we tried it showed lots of errors
regarding dependencies and libraries e.g. undefined references, no such files of directories, etc.
Is their any easier way to use bluez functions to make a GattServer Application ?
Thanks in advance for your valuable answers.....

bluez gatt dbus apis are now complete as of version 5.29. You may consider using those if going via the dbus rather than directly through library calls is acceptable for you.

correlate pg:1950 in bluetooth spec4.0 APPENDIX: EXAMPLE ATTRIBUTE SERVER
ATTRIBUTES with gatt-example.c in plugins in bluez5.28

Related

How to do bluetooth pair between raspberry pi and phone from script?

I want to connect my phone to asterisk, who installed on the rbpi3 with chan_mobile.
I want to do web-interface for connect.
First step its scan for phones - its simple. Many hundreds path.
Second step - pairing intit. For send request from rbpi to phone (or revert, nevermind)
I have trouble with this step.
Old bluez (<5) have simple-agent and i can do pair with shell command:
bluetooth-agent --adapter hciX _pin_ mac_for_pair
Actual bluez(5.47 on this moment) dont have analog.
Only interactive bluetoothctl console.
I'll try to search libs for node js, python, but i dont see method of pair request init(or accept, if init from phone).
Can you help me? In fact, I need any path suitable for use in a script in which I want to pass the adapter and the target.
bluez has DBus API's to perform operations you need. See doc/ directory from bluez source. Go through doc/adapter-api.txt, doc/device-api.txt and doc/agent-api.txt files. These document files gives you fair understanding on scanning for bluetooth devices, running agent for authentication and pairing with your phone.
You can get sample codes for the DBus API's in the test directory of bluez source. See test/test-discovery and test/test-agent code to understand how to start a bluetooth scan using bluez DBus API. All the sample codes in test directory are in python and some scripts can be directly used in your application.
The bluetooth-agent you mentioned is an agent for authentication that is available with older bluez versions. You can create your own agent; see test/simple-agent python script in bluez source directory.
I already have a C function in this post , you could just easily convert it into a script or just compile the C code and call it from the script.

Best way to include Socket MvvmCross with PCL

First I would like to thank you (Stuart in special) for this amazing framework MvvmCross.
I have an application case that involves socket connectivity, and I would like to go with PCL for Android, WP7 and iOs.
Unfortunately, the PCL subset doesn't support sockets usage as is (I think NCL is supported only for Microsoft different frameworks).
I thought may be MvvmCross Plugin is the way to go, but still needs plugin implementation for each platform (I mean ...plugin.Droid, ..plugin.WP7 etc..) while it should be the same code at the end.
What do yo suggest?
Thanks
I thought may be MvvmCross Plugin is the way to go
Yes, this is exactly the sort of situation that Plugins were designed for.
I'd certainly implement this as a socket plugin:
The PCL part of the plugin would provided a socket interface, although it might also perhaps include some shared base class 'buffer copy' type functionality in the shared code too.
The platform specific socket implementations which handle raw socket connection and IO.
It's likely that these platform plugin additions would use quite a lot of file linking between several of the platform implementations - I'd expect there to be a lot of code that would have to be shared this way.
I think a sockets plugin will be quite a common requirement - so if you were to tackle this via open source, then you might find some willing contributors ... or, if you were to go closed source, then you might find some customers.
While no-one has open-sourced an IP network socket implementation at this stage, the Sphero project did include a Bluetooth socket example - albeit one that wasn't entirely network efficient in the way it communicated.
This Bluetooth socket code is open sourced within Ms-PL at https://github.com/slodge/BallControl/tree/master/Cirrious.Sphero.WorkBench/Plugins/Sphero
This Sphero plugin doesn't expose a PCL Sphero-Socket level API - instead at the plugin level it chooses to expose a Sphero-Robot level API.
With the benefit of hindsight (a wonderful thing), if I implemented this again then I'd implement:
a bluetooth serial port plugin exposing bluetooth scanning, connecting and socket streaming
an additional PCL library which consumed the plugin to drive the robot - this perhaps might be called a plugin but would not have any non-PCL code within it.

RPC from Windows to linux

Is there some (working) example how to create RPC from windows to linux?
Client should be windows NT application, server is linux.
It needs to be MSRPC.
No Corba, no XML-RPC, SUN-RPC etc
MSDN says this:
RPC can be used in all client/server applications based on Windows
operating systems. It can also be used to create client and server
programs for heterogeneous network environments that include such
operating systems as Unix and Apple.
Unfortunately after spending few hours on google I'm giving up.
My expectation:
Linux node should have samba installed, because their MSRPC implementation works.
Using IDL file I generate stubs for both client and server
Client is built using MSVC
Server is build using gcc with some includes/libraries from samba (or other libs)
Linux node must have such RPC port mapper
Can someone point me out?
I think you have 2 possible ways to deal with this:
1- You can try using DCOM with wine, which means that you will actually write your code for windows, but at the same time you can test your results in the process and avoid using WinAPI calls that wine is not able to handle properly. This approach will allow you to generate stubs code from your IDL files.
2- You can try using Samba RPC Pluggable Modules, but I am afraid in this case the RPC communication will be more primitive.
Edit:
It seems there are many other ways. I found a list of libraries in DCOM-Wikipedia, j-Interop for example looks particularly promising.

Detecting CDROM media removal/insertion in Linux

Is there a clean way to detect or receive events when a user inserts or removes a CD on a Linux platform?
Udev monitors hardware and forwards events to dbus. You just need some dbus listener. A quick check using the dbus-monitor tool shows this in my system:
dbus-monitor --system
signal sender=:1.15 -> dest=(null destination) serial=144 path=/org/freedesktop/UDisks; interface=org.freedesktop.UDisks; member=DeviceChanged
object path "/org/freedesktop/UDisks/devices/sr0"
This is the DeviceChanged event from Udisks, and the device path is included.
So, in whatever programming language you want that supports dbus bindings you can listen for those (system bus) events.
Traditionally there has been HAL (Hardware Abstraction Layer) for this, but the web page says
HAL is in maintenance mode - no new
features are added. All future
development focuses on udisks, UPower
and other parts of the stack. See
Software/DeviceKit for more
information.
and the DeviceKit page lists
udisks, a D-Bus interface for dealing with storage devices
So udisks should probably be what you are asking for.
The best way I was able to find was Halevt. Halevt is apparently a higher level abstraction than using HAL directly. It uses an XML based configuration file that may or may not be to your liking. The configuration file properties documentation is somewhat lacking. A list of all the supported properties are listed here:
http://www.marcuscom.com/hal-spec/hal-spec.html
Also, the link to Halevt: http://www.nongnu.org/halevt/

Is there an equivalent to DBus on OSX?

Is there an equivalent to Linux DBus on OSX? I mean, is there a "message bus" available by default on OSX?
Disclaimer: OSX newbie here.
If you need to use DBus you can install it via Homebrew.
Homebrew is a package manager for OS X providing a lot of libraries which where mostly written with Linux as their primary target.
The DBus package can be found here
However, this is not installed by default and if you intend to write Cocoa applications the way to go would be to use the (distributed) notification center as mipadi explained in his post (which you also accepted).
If you need a robust middleware for communication you can also have a look at IceTouch from ZeroC which is a Cocoa library for using the services and functionality offered by their Ice framework.
The package contains IceStorm for example which is a publish/subscribe server or the IceGrid service which can be used to build large scale distributed systems
Probably the closest analog would be distributed notifications (or notifications for same-process communication). It's not a perfect analog, but it fits into roughly the same niche. You can read more about it in Apple's Notification Programming Topics, particularly the part about the distributed notification center.
There's Mach's ports, which will probably do what you need: http://en.wikipedia.org/wiki/Mach_(kernel) .
You could check DarwinPorts. It should include the dBus libraries.

Resources