Connecting to Bluetooth LE devices from raspberry pi using Bluez libraries in C language - c

I am using my raspberry pi to perform LEScan at fixed intervals and connect to new found BLE devices.
Performing a general scan is easy and can be easily done by using the bluez libraries.
http://people.csail.mit.edu/albert/bluez-intro/x45.html
But i can't figure out how to perform LE scan using Bluetooth programming in C language.
I have to find new BLE devices, connect to them and receive json data from the connected devices.

To write a C program to scan BLE devices you can have a look at BlueZ hcitool sources.
To connect to the BLE device and interact with the GATT protocol you can either use the experimental DBUS Bluez API in Bluez v5.x (recommended to use v5.39+) or use a library like 'gattlib'.

The link you are pointing is for classic bluetooth;for BLE lescan go
through scantest.c in link
https://github.com/carsonmcdonald/bluez-experiments/tree/master/experiments

Related

How to implement MQTT on Zephyr OS with cellular devices?

I am a beginner on Zephyr OS and wanted to know if it is possible to implement MQTT on Zephyr OS with Cellular Devices like SIM800 or Quectel BG96 that usually work on UART and support TCP protocol which is the base of MQTT.
I looked through the example for MQTT given for Zephyr which is done over LAN but could not figure out how to implement the same with a cellular device.
MQTT itself does not necessitate TCP as the transport layer but you may need one transport layer. Most of the implementation out there are relying on TCP as the transport layer e.g.:
Paho MQTT Client C Library
Paho MQTT Client C++ Library
There is an implementation that only serializes and deserializes MQTT compliant packages. But this implementation is based on the MQTT-SN (sensor-network) standard and needs a MQTT-SN compliant MQTT-gateway or MQTT-Broker. Theses packages you may transfer as you like: As UART stream, memory map IO, etc.
Paho MQTT-SN Package C Library
In addition, check to implement and provide a TCP/IP socket to a MQTT client Library that wraps the AT Command specification of both devices:
AT Commands for TCPIP Application Toolkit
BG96 TCP/IP AT Commands Manual

connection between windows and Linux sockets in c

I am using the socket module in python to send commands to my raspberry pi to turn GPIO pins on and of.
I am switching to C, where I will use winsock.h and winsock2.h to create the server on my PC and sys/socket.h to create a client on the raspberry pi.
Is it possible to establish a connection between these two different libraries?
I only want to create a socket, bind, send and recv. No other operations.
I recommend you to check this documentation, there are some examples for a Windows Server / Client connection:
https://learn.microsoft.com/en-us/windows/win32/winsock/getting-started-with-winsock
For Linux you need to do some adaptations as you might know or you have already implemented, I did the same for 2 desktop applications to send data from a Linux PC (client) to a Windows PC (server). As mentioned in the comments it doesn't matter the devices while they are in the same network and follow the TCP/IP protocol.
I was able to do this even connected through a VPN. Unfortunatelly I can not share the code. But I developed this communication based on the documentation from the link above.
I hope it helps. Actually if you want to use Python in the raspberry Pi there is also a python built-in package that you could use: https://docs.python.org/3/library/socket.html
And you can use the code from the link above in Windows. It should be straighforward.

develop BLE peripheral using C on intel edison

I am trying to develop a bluetooth LE peripheral in intel-edison, by using C library. The device should be able to :
advertise (GAP)
accept connection (GAP)
support custom GATT service, simply read/write value of characteristic.
I try to use HCI and bluez to implement this. bluez-experiments, intel-edison-playground, which demonstrate how to advertise and scan, can be compiled and run on edison. BLE advertising and scanning do work.
But I have hard time to figure out how to accept connection and support GATT service. I try to search on goolge about the HCI document but have no luck. Can someone provide a snippet of code (c or pseudo or a description)?
Thank you so much!
Andrew
If you download the bluez source you'll find documentation on the hci protocol in /doc/mgmt-api.txt. I'm not using the hci interface myself, and I'm not sure if the developers intend for implementors to use this interface to implement peripherals, so I'm not sure how well this will work.
I went with the DBus API approach for my project, which is outlined in /doc/gatt-api.txt and /doc/advertising-api.txt. This approach involves writing a program which creates DBus objects which support specific org.bluez DBus interfaces (GattService1 which contains GattCharacteristic1 and GattDescriptor1) and the ObjectManager interface to expose everything to bluez. You then use LEAdvertisment1 to define what is advertised and register the advertisement using the LEAdvertisingManger1 interface on the adapter.
I used Qt to simplify the DBus communication parts.
The DBus API for BLE on bluez is still in heavy development, and not all features are supported (I still haven't found a way to start and stop advertising, for example). 5.31 contains a lot of added supported and some critical bug fixes for descriptors, but requires a newer kernel.

Connecting an Adobe AIR mobile app to Arduino wirelessly - what are the options?

Is there a way to connect an Adobe AIR mobile app to an Arduino hardware wirelessly with no pc or router?
either with bluetooth or directly to an Xbee piece connected to the Arduino?
I need both iOS and android solutions
thanx
You could use the Native Extensions for Adobe AIR (ANE) for iOS and Android, although it means you might have to do a bit of C coding (or at least have basic understanding of the C programming language). A couple of projects have been created for either Bluetooth or Arduino connection using ANE already.
There is an ANE based project called as3-arduino-connector on Google Code, which gives you an ActionScript 3 API and mimics the Arduino serial port.
Another useful project might be AirNativeiOS-Bluetooth, an AIR Native Extension to add Bluetooth support for iOS apps. A corresponding project for Android is Bluetooth ANE, although the website mentions that it's early beta only, not ready for production.
Digi International has a Wi-Fi XBee now; that might be a good option since Android and iOS devices have Wi-Fi already. The more commonly used XBee modules (Series 1 and 2) use 802.15.4 networking (instead of Wi-Fi's 802.11).
I haven't used one yet, personally, so I don't know how you access the serial port connected to the Arduino. It might be possible to telnet to the XBee and send/receive data from Arduino.

How can I read in M-bus metering data with an Arduino Uno?

I am trying to send data from a Kamstrup Multical 601 to an Arduino Uno using the M-bus protocol.
I am considering trying to use the libmbus c libraries to do this. However, I do not have a lot of experience in c programming so was wondering if:
you think this is a realistic/achievable approach?
anyone could suggest an alternative/easier approach?
The main chip on the Arduino Uno is the Atmel Atmega382P-PU.
After getting the data to the Arduino I aim to perform some calculations and send data to an LCD (this I think I can do).
On the Arduino Website there is a short how-to about the use of external C-Libraries with Arduino.
Note that you cannot simply connect M-Bus with a RS-232 interface. There is a so called "level-shifter" device necessary inbetween to do the "electrical transition". See the EN 13757-2 standard doucment for what this device is exactly doing with the signal. Without such a device you won't get any word out of your M-Bus device.
The library you link to appears to be for Linux. The Arduino, of course, doesn't run Linux so a library won't compile for it directly.
You should probably try implementing the library yourself, but using the Arduino's standard libraries to access ports and so on.

Resources