How to monitor bluetooth device connectivity status in xamarin Forms? - xamarin.forms

Can someone guide me on how to monitor the connection status of Bluetooth device?
When the device is disconnected I need the notification. Please guide. Does Bluetooth LE plugin work for the normal Bluetooth?

Yes, Shiny is one of the more commonly used plugin, which is a Xamarin Framework for Backgrounding & Device Hardware Services.
First you should read the README.md file of this plugin. They provides two interfaces, IBluetoothLE is helping you to access the Bluetooth status and related things and the IAdapter is for handling the device and communicate with it.
The following information should be helpful for you to understand the plugin.
[IBluetoothLE].StateChanged => To know the Bluetooth status, like its off/on
[IAdapter].DeviceDiscovered => This will trigger when any device is discovered
[IAdapter].ConnectToDeviceAsync => For connecting with a device
[IAdapter].GetServicesAsync => To read the Bluetooth device service (The service is
providing the characteristic to read and write the query between connected device)
[service].GetCharacteristicsAsync => To get the characteristics from the selected
service
[characteristic].ReadAsync => Read the data from the device
[characteristic].WriteAsync => Write the data to the device
[characteristic].ValueUpdated => This will trigger when the data through from the
device
[characteristic].StartUpdatesAsync => Start to get the notifying the value updates
And there are samples about almost every single function point within Shiny.
https://github.com/shinyorg/shinysamples
For more details, you can check: https://shinydocs.azurewebsites.net/docs/ble/

You can use Shiny.
You will be able to get the connected devices and get status changes:
https://shinydocs.azurewebsites.net/docs/ble/central/centralmanager

Related

How to handle the device watcher "cache" of old devices on start-up?

I have one BLE application.
When I start the device scanning, the DeviceWatcher.Added event will call immediately and shows the previously connected devices which is currently powered off. But in the DeviceWatcher.Removed event it will be cleared.
How can I prevent this situation. In my application I am trying to connect the device immediately when ever there is the device listed in the DeviceWatcher.Added event. I don't want to wait till the DeviceWatcher.EnumerationCompleted event.
Because of this implementation, the connection API BluetoothLEDevice bluetoothLEDevice = BluetoothLEDevice::FromIdAsync(GetId()).get(); is returning success. And in the service scan API GattDeviceServicesResult result = m_BluetoothLEDevice.GetGattServicesAsync(BluetoothCacheMode::Uncached).get(); I am getting GattCommunicationStatus::Unreachable status.
I need this status in the initial time of scanning. Or there is any other way I can check the device is unreachable or not?
The sample written here is in C#, you could find the C++ replacement in the learn.microsoft.com
You could get all the paired BLE devices like this.
var pairedBleDevices = await DeviceInformation.FindAllAsync(BluetoothLEDevice.GetDeviceSelectorFromPairingState(true)); # Return all the paired Bluetooth LE devices
Now, if you want to remove the pairing of a specific device, you could loop through the pairedBleDevices and find your removal device by matching specific property, let's say device name or address.
foreach (var device in pairedBleDevices )
{
if (!device::Name.Contains("myDevice")) continue;
await device.Pairing.UnpairAsync();
break;
}
Now, as you have all the previously paired LE devices with properties, as Mike suggested, you could use BluetoothLEAdvertisementWatcher to discover BLE devices and filter the advertisement by matching the BluetoothAddress(from the paired device). If you find a new device, pair the device or execute the GATT operation and start communicating.
You are getting GattCommunicationStatus::Unreachable that's probably the device you are trying to communicate with is in sleep mode. So the best way is to capture the advertisement first using BluetoothLEAdvertisementWatcher and, after that, initiate the pairing or GATT operation.

Advertising and connection establishment using nRF52 DK with nrf52832 chip on Segger Embedded studio

I want to know how to send out an advertisement with some specific user number and data such that a connection can be established using the the sdk 15.3.0.
could anyone suggest me what changes i need to make in the ble app beacon code given in the sdk examples.
Thanks
One idea would be to start with the ble_peripheral example of the Nordic SDK.
You can find the following two guides on their forum : https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial and https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial
This explains how to build a custom service with a custom characteristic to handle read / write and notification of values from the embedded device to a BLE central device (e.g: smartphone).

Asterisk chan_mobile concurrent calls

New to Asterisk here.
I've setup my phone as a gsm gateway using bluetooth adapter. I then direct calls from the mobile device to a queue that has one member. The member is a soft phone.
extensions.conf looks like:
[incoming-mobile]
exten => s,1,Answer()
same => n,Queue(support)
same => n,Hangup()
This works pretty well. I get the call to the sip soft phone. However, while the call is active, if I receive antother call to my phone device, that call deosn't even reach asterisk. I see the multiple call notification on my phone but it does not go through to asterisk. So my questions:
Is it even possible to queue concurrent calls via chan_mobile or does that kind of thing require more advanced hardware (e.g. gateways with multiple channels)
Even if I had some gsm gateway with 30 sim cards, what happens to the 31st call. How do people handle queuing the calls, once all channels are taken? Seems like it's certainly possible
Any pointers much appreciated
Some facts
1) chan_mobile not support any gsm gateway, it is clearly stated in project docs.
2) there are no gsm gates or channel drivers supporting second call on same gsm sim card.
3) There are no even PHONES which support that. On all phones you have pause/hold first caller to get second call.
Nobody need this feature, so no expect it will be developed in near future.

HM-10/CC41 talk to BLE server

I've done a lot of searching but have yet to find any examples of the data format for accessing a simple BLE characteristic. I have a CC41 (HM-10 clone) that I have set to master mode and successfully connected to a BLE server device using a PC terminal program and the AT commands. I now want to send the proper data to access a service such as Immediate Alert (0x1802) and it's Alert Level characteristic (0x2A06). I know the full service and characteristic UUIDs and the data value for turning the alert on/off. I can do so from the nRF phone app but it doesn't tell me the data protocol that is actually sent from the app. I assume that the UUID needs to be sent as hex data, not a string, but nothing I've tried so far works. If the phone app can do it, then I would think that I can do it manually as well. Any ideas?

How Can IBM Bluemix Node-RED Iotout node be set up correctly to send command to Device (Arduino)?

I have an Arduino Uno that is successfully registered as a device with IBM IoTF. It can send information to the Bluemix Node-RED app without any issues now.
Now, I would like the Node-RED app to send commands to the device (the Arduino Uno). The Arduino is subscribed to the MQTT without any error. But, it is not receiving any commands from the Node-RED. I followed the directions at the link below to create another flow in Node-RED to show when a command is published and the commands are being shown, so they seem to be going to the MQTT broker. But, the device (Arduino) is not receiving them.
How can I figure out how to get this working?
Node-RED, IOT Foundation Out Node Not Sending Commands
I have the IBM IoT Out Node parameters set as follows:
Authentication: Bluemix Service
Output type: Device command
Device type: Arduino-tempsensor (this is the same string I used for the device type (name) when I registered it in IoTF)
Device ID: I put the MAC address here, should it be more
Command Type: status (I used the word "status" here. Does capitalization matter? Where should I get this value from? I used "status" because it is in the topic: "iot-2/cmd/status/fmt/json" is that correct?)
Format: json (does capitalization matter here?)
data: {"d":{"myName":"Arduino Uno", "temperature":989}} (I used this because it's JSON and I wanted to just see anything at the device)
Name: IBM IoT App Out
I typed up this whole question and then it occurred to me that the test flow to look for the published command should have all of the parameters set to exactly the same as the output. When I tried that, I was not getting the command message coming back. Then, I realized that my mac address (device ID) was capitalized in one place, but not the other. The MAC address (Device ID) I used to register the device was all in caps, so I make the Iot-out node for the command so that it was all capitalized and made the Iot-in node to test for the message so that it was all capitalized. Now it works! Then, I looked back at the device (which was printing to the serial monitor so I could see what was happening) and I am now seeing the messages! So, make sure your parameters follow the same capitaliztion!

Resources