Unable to reconnect to BLE after disconnection when working with one central and multiple Peripherals

Welcome to the forum.

That is not how BLE works. From your applications point of view, the central device is reading data from a peripheral. The peripheral just updates its internal state it does not send the data.

Where is that in your code?

Here are a few other things I noted in your code.

  • You use delay. That is not a good idea in general but especially when you use communication stacks. Use millis() instead for timing code. Make sure your loop runs as often as possible. Try to avoid while and waiting for things to happen. Use state variables and move on as soon as you can.
  • You must not use 16-bit UUIDs other than how they have been defined by the Bluetooth SiG. For your own characteristics and services you must use 128-bit random UUIDs. There are UUID generator available online.
  • Try to avoid using UUIDs to differentiate between devices with the same functionality. The service and characteristics should stay the same if they provide the same functionality. That is what the UUID should describe. You can differentiate in the values or the device name.
  • Make sure you use the correct data type and convert them explicitly so the reader of your code knows you did not make a mistake. helloWorldChar is a unsigned char characteristic but you assign a int value. What happens if helloWorld is larger than 255.
  • Avoid using Char in the name for characteristics. Char is used for a data type. In 2023 you no longer need to save a few bytes in your source files by using short names. Make you code easy to read.
  • Try to avoid commenting every line of your code. If you feel like writing a comment. Try re-writing your code first. Some comments can be useful.
  • Peripheral_3 is not a UUID
  • "value" and "arr" and "n" are not good variable names, chose names well and make your code easy to read, "i" for loop index is commonly used and therefore a good exception

Here you can find an example I wrote while ago for a peripheral device in reply #2. Maybe you find it useful.

1 Like