How to implement BLE communication with two devices? - bluetooth

I have an IoT device which I wish to implement:
A mobile app - where the phone is the master when communication is initiated by the user's phone
A remote key - where a click on said key should make the iot device do something. The remote key should be paired one time with the iot device.
Now, the issue that I'm experiencing is that I can not communicate with both. I would like to enable connection with the mobile app at all time, but I would also like to listen for a click on the remote key at all time (unless I'm connected to the app).
What would be the best architecture for such communication? Who would be the master and who would be the slave? Should I use a beacon device for the remote key? What's the best practice here?

Depending on the BLE stack, a device can certainly be a Central and a Peripheral at the same time (the use of 'Master' and 'Slave' is inaccurate here).
If I understand correctly, you have 3 devices - a phone, a key, and an IoT Device. There are several options here:
Phone is Central, and is connected to both Key and Device as Peripherals. A click on the Key will notify the phone, which in turn will send some message to the Device. Pros - easy pairing. Cons - the phone app must run all the time.
Phone is Central, Key is both Central and Peripheral, Device is Peripheral. Phone connects to the Key Peripheral, Key connects to the Device as Central. Pros - Key controls Device even with no phone. Cons - probably harder to setup and pair Key with Device (depends on their I/O capabilities)

Related

Do I need to set up a PKI to secure D2C and C2D (IOT) communication in Azure?

Im wondering if I need to set up a Public Key Infrastructure in order to ensure a secure Device to Cloud and Cloud to Device connection?
I have several IoT devices which should communicate over MQTT.
To ensure that the device X is actually device X that is sending the data to IoT Hub in Azure, do i need to set up a Managed PKI?
I've read several microsoft documentations but I did not understand.
Do I only have to upload the device certificate in Azure IoT Hub and afterwards when writing the device client give the device certificate as parameter?
How can I achieve a secure communication between the device and Azure and also make sure that the device is the device it is pretending to be?
You have two options to secure device connections to IoT Hub. In both cases, you need to register your device in the IoT Hub device registry before it can connect:
SAS tokens. You can obtain a SAS token for a device from the device registry. When the device presents the token, IoT Hub verifies that it was issued by your IoT hub and that the device is registered.
X.509 certificates. This approach requires you to upload a root or intermediate certificate to your IoT hub. If a device presents a leaf certificate derived from the root or intermediate certificate, then it's allowed to connect.
To learn more, see https://learn.microsoft.com/azure/iot-hub/iot-hub-dev-guide-sas.
Additionally, IoT Hub uses TLS to secure all communications. See: https://learn.microsoft.com/azure/iot-hub/iot-hub-tls-support. This typically doesn't require any setup or configuration on your behalf before it's allowed to connect.

How communicate between sensors and IoT Hub through Field Gateway? [duplicate]

In our scenario, we have a bunch of devices that communicate locally with a gateway. The gateway is responsible to aggregate events from the devices and send it to the cloud. It should also receive device configuration changes from the the cloud and transport it to the specific device.
Based on my reading I would think that this is actually a typical IoT Hub scenario. And we would very much like to use the device management, messaging and maybe even twins that IoT Hub provides.
However, the way the devices communicate is already implemented and shall not be changed. That means the devices themselves cannot create connections and provide IoT Hub credentials. This rules out using the azure-iot-protocol-gateway or similar.
We would rather need the gateway to act as a device that can act on behalf of other devices. The gateway would detect which devices are in his local network and subscribe to their topics (via MQTT or AMQP).
Is this even possible? Can devices send events or listen to Cloud-To-Device messages in place of other devices?
Your scenario is a perfect fit for Azure IoT Edge:
https://learn.microsoft.com/en-us/azure/iot-edge/
"Azure IoT Edge is an Internet of Things (IoT) service that builds on top of IoT Hub. This service is meant for customers who want to analyze data on devices, a.k.a. "at the edge", instead of in the cloud. By moving parts of your workload to the edge, your devices can spend less time sending messages to the cloud and react more quickly to changes in status."
And I would suggest that you use IoT Edge as an identity or protocol translation Gateway:
https://learn.microsoft.com/en-us/azure/iot-edge/iot-edge-as-gateway
"Gateways in IoT solutions provide device connectivity and edge analytics to IoT devices that otherwise wouldn't have those capabilities. Azure IoT Edge can be used to satisfy all needs for an IoT gateway regardless of whether they are related to connectivity, identity, or edge analytics. "

Act for other devices on Azure IoT Hub

In our scenario, we have a bunch of devices that communicate locally with a gateway. The gateway is responsible to aggregate events from the devices and send it to the cloud. It should also receive device configuration changes from the the cloud and transport it to the specific device.
Based on my reading I would think that this is actually a typical IoT Hub scenario. And we would very much like to use the device management, messaging and maybe even twins that IoT Hub provides.
However, the way the devices communicate is already implemented and shall not be changed. That means the devices themselves cannot create connections and provide IoT Hub credentials. This rules out using the azure-iot-protocol-gateway or similar.
We would rather need the gateway to act as a device that can act on behalf of other devices. The gateway would detect which devices are in his local network and subscribe to their topics (via MQTT or AMQP).
Is this even possible? Can devices send events or listen to Cloud-To-Device messages in place of other devices?
Your scenario is a perfect fit for Azure IoT Edge:
https://learn.microsoft.com/en-us/azure/iot-edge/
"Azure IoT Edge is an Internet of Things (IoT) service that builds on top of IoT Hub. This service is meant for customers who want to analyze data on devices, a.k.a. "at the edge", instead of in the cloud. By moving parts of your workload to the edge, your devices can spend less time sending messages to the cloud and react more quickly to changes in status."
And I would suggest that you use IoT Edge as an identity or protocol translation Gateway:
https://learn.microsoft.com/en-us/azure/iot-edge/iot-edge-as-gateway
"Gateways in IoT solutions provide device connectivity and edge analytics to IoT devices that otherwise wouldn't have those capabilities. Azure IoT Edge can be used to satisfy all needs for an IoT gateway regardless of whether they are related to connectivity, identity, or edge analytics. "

Can I whitelist one ChromeCast device for multiple applications?

I have a ChromeCast device that I use for development. I have whitelisted the device and have received an AppId.
I am also developing an application for another company. Does the whitelisting support multiple AppIDs per device? Should I have them add my device to their whitelist request, or should I update the URLs associated with my AppID to the other company's receiver url(s)?
If you want to share your device with them, you can request for more app-id/urls to be added to your device. Obviously, if you want them to use their own device, you need to get the serial number of their devices to whitelist theirs for your app or have them whitelist directly.å

J2ME Bluetooth - discover a service with unknown details

Lets say I have a device which my cell phone can connect to via bluetooth (it can be any device on the market...)
For being able to connect this device using a J2ME application on my cell phone, I need to discover the device first, and then discover the service which the device lets cell phones connect to.
My problem is that I don't know how to discover that service.... the device is being discovered with no problems by the J2ME application, but for discovering the service of this device, I need service's UUID and Attributes (J2ME API requirements), which I have no idea where and how to get.
Does anyone know how can I still connect the device's service using a J2ME application, without knowing service's UUID and Attributes ?
Thanks!
As far as I know, there is nothing in the API to directly do "remote service discovery", but I found this, which I think is about that:
Service discovery allows you to find
nearby services, regardless of what
devices are offering them.
DiscoveryAgent provides methods to
discover services on a Bluetooth
server device and to initiate
service-discovery transactions. Before
a service can be discovered, it must
first be registered or advertised on a
Bluetooth server device. The server is
responsible for a number of things,
including creating a service record
that describes the service offered,
accepting connections from clients,
and adding a service record to the
server's Service Discovery Database
(SDDB). In general, it works like Web
services.

Resources