cancel
Showing results for 
Search instead for 
Did you mean: 

Simple BLE advertising application

Exeu
Associate II

Hi there :waving_hand:

I am quite new to the topic of developing BLE hardware.

My goal of the current project is quite simple:

I have a custom board featuring stm32wb55ceu6 and a ambient temperature/humidity sensor.

All hooked up including the RF part with an impedance matching network to 50 ohms and an antenna for 2.4 GHz (BLE).

Now I would like to read the sensor using i2c and get the values for temp and humidity every let's say 10 minutes.

After getting the values I would like to just send out a ble advertisement containing the sensor data in bthome format (so that my home assistant can just read it).

There should be nothing else involved. The board is just sending out once every 10 minutes and after sending it goes back to sleep.

My question: can you maybe provide me a startingpoint where I can find information about BLE advertisement, etc.? 

I saw that there is a stm32wpan module but I am not sure if this is total overkill for this simple use case.

I am a bit lost with this :(

I was inspired by the following project: https://github.com/rbaron/b-parasite/blob/main/code%2Fnrf-connect%2Fsamples%2Fble%2Fsrc%2Fble.c

And would like to build sth. Similar just with an stm32wb55.

 

Thank you 

1 ACCEPTED SOLUTION

Accepted Solutions
_Joe_
ST Employee

Hi, there,
To begin with, here is an introductory page on the STM32WB and its environment:
Connectivity:STM32CubeWB_BLE 

From this page, you'll be able to find examples of projects similar to your use case. For example, the "BLE_Sensor" and "BLE_HealthThermometer" projects.

Best regards, 
Joé

View solution in original post

4 REPLIES 4
_Joe_
ST Employee

Hi, there,
To begin with, here is an introductory page on the STM32WB and its environment:
Connectivity:STM32CubeWB_BLE 

From this page, you'll be able to find examples of projects similar to your use case. For example, the "BLE_Sensor" and "BLE_HealthThermometer" projects.

Best regards, 
Joé

Exeu
Associate II

Hey Joe,

thanks for the answer. I was just checking out the example of the BLE_Sensor.

Am i right that advertising is happening in "app_ble.c" of this "WPAN" stack?

Found this here:

 

  ret = aci_gap_set_discoverable(ADV_IND,
                                 Min_Inter,
                                 Max_Inter,
                                 CFG_BLE_ADDRESS_TYPE,
                                 NO_WHITE_LIST_USE, /* use white list */
                                 sizeof(a_LocalName),
                                 (uint8_t*) &a_LocalName,
                                 BleApplicationContext.BleApplicationContext_legacy.advtServUUIDlen,
                                 BleApplicationContext.BleApplicationContext_legacy.advtServUUID,
                                 0,
                                 0);

 

And then:

ret = aci_gap_update_adv_data(sizeof(a_ManufData), (uint8_t*) a_ManufData);

So i guess ManufData is containing the "raw" data which should be advertised?

I wanted to avoid using this whole GAP/GATT thingy. It seems to much for this usecase..

As an alternative i was seeing that there is an HCI - Interface which may is a shortcut to just do some advertising?

HCI_LE_SET_ADVERTISING_ENABLE()

Would this also work somehow?

If you don't need to set up a connection, you can look at the BLE_Beacon example to make an ADV only.
BLE_Beacon 

Yes, if you don't want to use GAP commands as in the examples, you can use HCI commands.

Here's where you can find out more about these commands:
STM32WB_BLE_Wireless_Interface.html 

BR, Joé

Exeu
Associate II

Thanks for the Answer Joe!

That helped me now and i am able to at least run the ble example app using clion.

So now i have the next question.

How would i solve the issue to change my advertising data from outside?

So i baked in the service data (hardcoded) in the class ibeacon_service.c the following:

 

 

  uint8_t service_data[21] =
  {
          sizeof(service_data)-1,
          AD_TYPE_SERVICE_DATA,

          // 0xfcd2 - bthome.io service UUID.
          0xd2,
          0xfc,

          // Service header - no encryption, bt home v2.
          0x40,

          // Temperature.
          0x02, // Type Flag (Temperature)

          0x44, // 21,16 Degrees
          0x08, // 21,16 Degrees

          // Humidity.
          0x2E, // Type Flag (Humidity)
          0x51, // 81% rel

          // Illuminance.
          0x05, // Type Flag (Illuminance)
          0x02, // 10,26 lx (LUX)
          0x04, // 10,26 lx (LUX)
          0x00, // 10,26 lx (LUX)

          // Battery voltage.
          0x0C, // Type Flag (Battery Voltage)
          0xA8, // 2,984 V
          0x0B, // 2,984 V

          // Soil moisture.
          0x2F, // Typeflag (moisture)
          0x30, // 48 %

          // Battery percentage.
          0x01,
          0x5C // 92%
  };

 

 

This represents the BT Home format with static data.

Now i would like to update this data every 10 minutes (so i guess i need a timer somewhere).

Am i supposed to do this update from my main.c? Or from where i should update it?

So the flow is the following:

Device Boots -> Starts Advertising for 2 seconds -> Stop Advertising -> Then goes to deep sleep -> 10 minutes of sleep -> Wake up -> Advertising for 2 seconds ... -> repeat indefinitly this cycle.