33 BLE fail to discover attributes

Hi everyone. from South Korea.

I'm trying to do a project of smart system for my pot.

Peripheral & Central are made of all Arduino nano 33 BLE.

The peripheral is sensing temperature/humidity/lux from AM2301 and MAX44001.

Those data of them will transmit from the peripheral (in a garden) to the central (in my room).

The problem is that the central can't discover attributes of the peripheral.

Could you tell me how I can solve this problem?

======================================================
BLE Central - Peripheral Explorer
Found 77:48:87:92:82:31 'SensingHTL01' 00001801-0000-1000-8000-00805f9b34fb
Connecting ...
Connected
Discovering attributes ...

[stop an step, Discovery attributes, loading and loading and loading...]

Peripheral.ino (9.9 KB)
PeripheralExplorer.ino (4.5 KB)

One major issue is that you do not update now_time inside while(central.connected()). Once a central device is connected your peripheral is stuck in that while loop doing nothing.

Here are a few other things I noted about your code:

  • If you want to use Bluetooth SIG defined UUID you can just use 16-bit UUID e.g., "2AF7"
  • If you want to create an Environmental Sensing Service here is an example in reply #2
    https://forum.arduino.cc/t/bluetooth-communications/902610/2
  • using string characteristics will make your central code a lot more complicated and will cost you more battery
  • I would recommend using Arduino naming convention and stick with it
    -- CAPITAL_WITH_UNDERSCORE for constant values
    -- camelCase for functions and variables
  • h and t are not good variable names
  • temp is not a good variable name e.g., why do you store humidity in temp(erature) :slight_smile:
  • setManual_Mode is not a good function name e.g., what is set to manual mode, you call this function once, make it a good long name
  • avoid using while in loop, this will stop you from extending your code later (see my example for how to avoid this altogether)
  • your code uses many number values, use consts instead and give them some name to allow others to understand your code. Remember in two month you are one of the "others" because you will have forgotten what you wrote and why.

Just a tip, I would recommend sticking with the millis naming used in the official Arduino examples. now_time is not a valid description. The value does not contain a time value and it is not now. Now is what you see on your watch. currentMillis tells you it is just a current value of millis() which is a number of milliseconds and it will repeat after some time.

2 Likes

Good day, Chuseok (Korean Thanksgiving Day) from South Korea.

Thanks, your advcies!

I'm trying to follow your advice, today. Then... I made it!!!

Thanks, Klaus_K.

If you want to use Bluetooth SIG defined UUID you can just use 16-bit UUID e.g., "2AF7"
==> So good. I's changed to Service of Enviromental sensing "181A", txDataString of Fixed String "2AF7", rxInString of Fixed String "2AF6"
(I tried to connect my another BLE 4.0 device, HM-10 (central) to 33 BLE (pheripheral). It was failed.)

If you want to create an Environmental Sensing Service here is an example in reply #2

using string characteristics will make your central code a lot more complicated and will cost you more battery
==> Thanks, your advice. I already read your code before.
==> Somedays, I think this system is more updated with various Arduino modules.
I want to make Pheripheral do something according as rx_String from Central.
I tried to make four BLE characteristics in Service and I successed from my phone.
but finally, I decided four Char to two Char in service.

I would recommend using Arduino naming convention and stick with it
-- CAPITAL_WITH_UNDERSCORE for constant values
-- camelCase for functions and variables
==> Okay. I'll keep in mind.

h and t are not good variable names
==> Good advice. I change them.

temp is not a good variable name e.g., why do you store humidity in temp(erature)
==> Thanks. I change temp array to test array.

setManual_Mode is not a good function name e.g., what is set to manual mode, you call this function once, make it a good long name
==> Thanks. I change setManual_Mode to MAX4401_set_Manual_Mode.

avoid using while in loop, this will stop you from extending your code later (see my example for how to avoid this altogether)
==> I got it. I change "while" to "if" in loop. (I think it's a critical point.)

your code uses many number values, use consts instead and give them some name to allow others to understand your code. Remember in two month you are one of the "others" because you will have forgotten what you wrote and why.
==> You're right. I'll keep in mind.

===============================================================================
Found 43:c1:83:f0:db:45 ''
Found 77:48:87:92:82:31 'SensingHTL01' 181a
Connecting ...
Connected
Discovering attributes ...
Attributes discovered

Device name: Peripheral01
Appearance: 0x0

Service 1800
Characteristic 2a00, properties 0x2, value 0x5065726970686572616C3031
Descriptor 2803, value 0x020500012A
Descriptor 2a01, value 0x0000
Characteristic 2a01, properties 0x2, value 0x0000
Service 1801
Characteristic 2a05, properties 0x20
Descriptor 2902, value 0x0000
Service 181a
Characteristic 00000000-0000-0000-0000-00000000af7b, properties 0x13, value 0x4431204835352E37205432362E33204932372E31204C39312E3830
Descriptor 2902, value 0x0000
Descriptor 2803, value 0x1B0F00F62A
Descriptor 2af6, value 0x4431205354414E4420425921
Characteristic 2af6, properties 0x1B, value 0x4431205354414E4420425921
Descriptor 2902, value 0x0000

Disconnecting ...
Disconnected