I want to build a small system that is operable with different devices (Ex - a bluetooth speaker). I still have not purchased the device since I couldn't find any topic that mentions the maximum number of devices you can pair to Nano 33 ble. I would like to know if it is capable enough to pair at least 3 devices. And if so, can it autoconnect to a device that it has paired to earlier?
Welcome to the forum.
The Arduino Nano 33 BLE uses BLE and Bluetooth speakers use Bluetooth Classic. They have the name in common and the frequency band (2.4GHz) otherwise they are incompatible.
Thank you Klaus. Could you maybe elaborate a bit, just to clarify
Sure. Bluetooth Classic was originally designed to replace serial communication. It became widely used to connect wireless headphones to mobile phones. These headphones had to be recharged every few hours.
BLE was developed to allow new application where users would not be happy to charge the device every day e.g., sensors for heart rate, cycling, temperature, humidity ... These devices should be able to run for month or a year on a coin cell. Because nothing in live is free, BLE cannot support all applications where Bluetooth Classic was used e.g., audio.
Mobile phones have dual mode Bluetooth modules/chips. They support Bluetooth Classic and BLE. It is branded under the same name to ensure the end customer. Bluetooth is what connects your phone to stuff. Under the hood its different things. Clever.
Can you explain you project a bit more e.g., why do you want to connect your devices to the Arduino? Maybe this will allow me to give you some more specific guidance. It would also be good to get an idea of your skills.
Thank you for the elaboration, I think I got it. I'm a complete novice in the field of Edge computing. Since you asked for the use case, It is more of a research project I plan on doing for my final year at college. TinyML (ML on MCUs) has sparked my interest, and I wanted to research on a decentralised learning environment for MCUs.
OK, from what I understand now, you only need to connect a few Arduinos from time to time to update some data.
- for this you do not need to have multiple connections at the same time
- in BLE there are two type of devices peripherals/servers and centrals/clients (both names are used)
- you could make your Arduino 1of3 the central and all others peripherals
- the central decides when the peripherals get a new update
- pairing is an optional feature in BLE and not supported by the ArduinoBLE library
- BLE centrals can just connect to peripherals
- if you need to, you could add some application level authentication
Oh okay, This makes more sense. thanks a lot.
One doubt I have is, you state that pairing is "Optional". What do you mean by that?
Pairing is a process where two devices exchange some information that allows them to authenticate the link and share some keys that allow them to communicate in the future without others being able to read the information. Usually, the user is involved in the pairing by confirming some code or numbers displayed.
With BLE this process is optional, it is not mandatory. Central devices can just connect to peripherals without pairing. So, if I walked into your lab, I could use my phone and connect to your Arduino.
Is there a real risk if somebody would do that?
Well there is an associated risk of someone just grabbing whatever data is in the arduino itself, it it's sensitive
OK, no problem you can do application-level access control. How complicated you make this depends on how serious the attack will be and how sophisticated the attacker is going to be.
A peripheral can disconnect a central whenever it wants to. You decide when, e.g., when a central connects you check the address of the central and disconnect when it is not in the list of allowed devices. If you want to have it more dynamic, you use a access control characteristic. When a device does not write a certain value within a specific time you disconnect.
Thank you for the answer @Klaus_K , I will look into what I can do.
Another thing... Can I create my own protocol/wrapper for BLE communication?
BLE uses the GATT to exchange data between devices. It is flexible and smart.
There are services and characteristics. Both are identified by a UUIDs.
16-bit UUIDs are reserved for things defined by the Bluetooth SIG.
128-bit random UUIDs are used to describe your own services and characteristics.
A service is a collection of characteristics.
Characteristics are a bunch of bytes that contain the data. You can store individual data types like uint32_t, small arrays or structures with multiple primitive data types.
The client will look at the UUID and ether knows what the data is e.g., a 16-bit signed value representing a temperature, or you could even add descriptors that describe in detail what that data is. This way a client that knows how to read descriptors will automatically be able to parse them.
Once you set this all up, all you need to do is write new values to the characteristic. Everything else will be done by the BLE stack. It will notify a client if it has subscribed to a characteristic or call your callback function when a value is written by the client.
I recommend you get a board and try some examples from the ArduinoBLE library. There are several generic BLE apps available for iOS and Android to interact with the services and characteristics e.g., BLE Scanner, EFR Connect, nRF Connect, and a few more.
Oh right. This makes way more sense, and clears out a few of my doubts. Now that I've tried a few BLE examples with the nano 33. are these devices capable of autoconnecting?
The short answer is two Arduinos (one client and one central) can "automatically" connect to each other via BLE. This happens at the application layer (your code).
A peripheral device usually advertises the services it provides the whole time and awaits connections from central devices.
A client can connect whenever it wants. When the client is an Arduino, it can do that depending on your code e.g., when a button is pushed, a timer triggers or as soon as BLE is initialized. When the client is running on a PC or similar device the operating system might require some user interaction e.g., ask the user to select a device.
Assuming there are 2 Arduinos (A1, A2), A1 is the central, and A2 is peripheral. Are they capable of switching roles? A1 being peripheral, and A2 being central?
Sure. You would just need to make sure both are peripherals most of the time. A device could then switch the become a client, do whatever it needs doing and then switch back. If it does not find a peripheral it needs to switch back to become a peripheral again as well, waiting for a slightly random time to try again.
This will ensure they are not synchronizing. Otherwise they might end up becoming a client at the same time again and again.
Understood, I have one more question. Is there any way a beacon transmitter can know when the transmission has reached another device?
Well, yes and no. Yes, if it can receive a signal from someone. No, if the receiver does not answer the sender does not know whether the signal was received. Just think TV and radio. The station do not know whether someone watches/listen to their program unless they call back.
Why do you ask?
So if a device (A) is notified that a nearby device has picked up its signal, I'm assuming the devices are close by and device(A) can switch from beacon mode to allow data transfer
Also is there a way I can public-key encryption on such a device? Or is it too resource constrained?