Skip to content

Instantly share code, notes, and snippets.

View parthitce's full-sized avatar

Parthiban parthitce

View GitHub Profile
@parthitce
parthitce / hci_list.c
Created May 26, 2018 09:14
hci_list.c: Finds the list of available Bluetooth controller
/*
* hci_list.c : Find the list of bluetooth controller present as
* - If more the one controller found, prints the UP-RUNNING
* - If none is enabled, it prints the first found controller
* - If none found, prints nothing
* Compile: gcc -o ./hci_list ./hci_list.c -lbluetooth
*/
#include <stdio.h>
#include <stdlib.h>
@parthitce
parthitce / hci_list_gdbus.c
Last active August 22, 2020 19:19
List bluetooth controllers using GDBUS (both with and without using proxy)
/*
* hci_list_gdbus.c - List bluetooth controllers using GDBUS
* - The example uses GDBUS to get the list of bluetooth controllers using DBUS
* interfaces provided by bluez
* - If any controller is found, it prints the Name and MAC address of the controller
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -o ./bin/hci_list_gdbus ./hci_list_gdbus.c `pkg-config --libs glib-2.0 gio-2.0`
* dbus-send --system --print-reply --type=method_call --dest='org.bluez' '/' org.freedesktop.DBus.ObjectManager.GetManagedObjects
*/
#include <glib.h>
@parthitce
parthitce / bluez_adapter_get_properties.c
Created June 1, 2018 16:45
Get Bluetooth Adapter Properties using GDBUS
/*
* bluez_adapter_get_properties.c - Print all the properties of the controller
* - The example uses GDBUS to get the list of bluetooth controllers using DBUS
* interfaces provided by bluez
* - If any controller is found, it prints all the properites of the controller
* - GetAll method is explicitly used for Getting properties of the controller
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/bluez_adapter_get_properties ./bluez_adapter_get_properties.c `pkg-config --libs glib-2.0 gio-2.0`
*/
#include <glib.h>
@parthitce
parthitce / bluez_adapter_set_properties.c
Created June 3, 2018 18:18
Set powered state of the Adapter and Look for PropertiesChanged signal
/*
* bluez_adapter_set_properties.c - Set the Powered property of Adapter
* - The example uses GDBUS to set the Adapter Powered state to "on" and "off"
* in sequence.
* - It also registers signal handling for the PropertiesChanged event and prints
* the current powere state of the Adapter
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/bluez_adapter_set_properties ./bluez_adapter_set_properties.c `pkg-config --libs glib-2.0 gio-2.0`
*/
#include <glib.h>
#include <gio/gio.h>
@parthitce
parthitce / bluez_list_devices.c
Created June 4, 2018 18:08
List Bluetooth devices (previously paired/connected or appeared after adapter StartDiscovery)
/*
* bluez_list_devices.c - Find the Bluetooth devices
* - The example uses GDBUS to get the list of bluetooth devices using DBUS
* interfaces provided by bluez. This lists only the devices which are already or
* currently enumerated by the Adapter.
* - The device may be appeared in followind conditions,
* - Previously paired with Adapter
* - Previously paired and connected with Adapter
* - Appeared after StartDiscovery session (but not yet used/removed)
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/bluez_list_devices ./bluez_list_devices.c `pkg-config --libs glib-2.0 gio-2.0`
@parthitce
parthitce / bluez_adapter_scan.c
Last active November 17, 2022 22:58
StartDiscovery: Scan for new devices and list it
/*
* bluez_adapter_scan.c - Scan for bluetooth devices
* - This example scans for new devices after powering the adapter, if any devices
* appeared in /org/hciX/dev_XX_YY_ZZ_AA_BB_CC, it is monitered using "InterfaceAdded"
* signal and all the properties of the device is printed
* - Scanning continues to run until any device is disappered, this happens after 180 seconds
* automatically if the device is not used.
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/bluez_adapter_scan ./bluez_adapter_scan.c `pkg-config --libs glib-2.0 gio-2.0`
*/
#include <glib.h>
@parthitce
parthitce / bluez_adapter_remove.c
Created June 9, 2018 09:20
StartDiscovery + RemoveDevice: Scan and remove the Bluetooth device
/*
* bluez_adapter_remove.c - Scan and remove bluetooth devices
* - This example scans for new devices after powering the adapter, if any devices
* appeared in /org/hciX/dev_XX_YY_ZZ_AA_BB_CC, it is monitered using "InterfaceAdded"
* signal and all the properties of the device is printed
* - Device will be removed immediately after it appears in InterfacesAdded signal, so
* InterfacesRemoved will be called which quits the main loop
* gcc `pkg-config --cflags glib-2.0 gio-2.0` -Wall -Wextra -o ./bin/bluez_adapter_remove ./bluez_adapter_remove.c `pkg-config --libs glib-2.0 gio-2.0`
*/
#include <glib.h>
@parthitce
parthitce / bluez_adapter_filter.c
Last active November 17, 2022 22:58
SetDiscoveryFilter + StartDiscovery: Control discovery filter and scan for new devices
/*
* bluez_adapter_filter.c - Set discovery filter, Scan for bluetooth devices
* - Control three discovery filter parameter from command line,
* - auto/bredr/le
* - RSSI (0:very close range to -100:far away)
* - UUID (only one as of now)
* Example run: ./bin/bluez_adapter_filter bredr 100 00001105-0000-1000-8000-00805f9b34fb
* - This example scans for new devices after powering the adapter, if any devices
* appeared in /org/hciX/dev_XX_YY_ZZ_AA_BB_CC, it is monitered using "InterfaceAdded"
* signal and all the properties of the device is printed
@parthitce
parthitce / bluez_adapter_connect.c
Last active September 18, 2022 12:09
ConnectDevice: Connect bluetooth device without scanning
/*
* bluez_adapter_connect.c - Connect with device without StartDiscovery
* - This example registers an agen with NoInputOutput capability for the purpose of
* auto pairing
* - Use ConnectDevice method to connect with device using provided MAC address
* - Usual signal subscription to get the details of the connected device
* - Introduced new signal handler to exit the program gracefully
*
* Note: As "ConnectDevice" is new API and in experimental state (but mostly stable)
* one need to use "-E" option when starting "bluetoothd". Systems running systemd can
@parthitce
parthitce / uhubctl_2.0.0-19.bb
Last active September 19, 2018 17:13
bitbake recipe for uhubctl utility (vesion 2.0.0-19)
DESCRIPTION = "uhubctl - USB hub per-port power control"
HOMEPAGE = "https://github.com/mvp/uhubctl"
LICENSE = "GPLv2"
LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
file://LICENSE;md5=7a7d8e0fdffe495ff61f52ceee61b2f7"
DEPENDS = "libusb1"
RDEPENDS_${PN} = "libusb1"
SRC_URI = "git://github.com/mvp/uhubctl.git"