Here's some code to get started:

  /* Set tx power level. */
  rc = ble_phy_txpwr_set(tx_pwr_lvl);  // tx_pwr_lvl == 4
  if (rc != 0) {
    BLEPRPH_LOG(ERROR, "error setting tx power level; rc=%d\n", rc);
    return;
  } else {
    BLEPRPH_LOG(DEBUG, "tx_pwr_lvl=%d\n", ble_phy_txpwr_get());  // prints
'4' as expected
  }

  /* Set the data included in advertisement packet. */
  memset(&fields, 0, sizeof(fields));
  fields.tx_pwr_lvl = (uint8_t) tx_pwr_lvl;
  fields.tx_pwr_lvl_is_present = 1;
  /* ... */
  rc = ble_gap_adv_set_fields(&fields);
  if (rc != 0) {
    BLEPRPH_LOG(ERROR, "error setting advertisement data; rc=%d\n", rc);
    return;
  }

The above doesn't seem to have an effect on the contents of the advertising
packet; it still advertises 0dBm. The comment in
https://github.com/apache/incubator-mynewt-core/blob/master/net/nimble/host/src/ble_hs_adv.c#L188
implies that this should be handled automatically, and the provided value
is ignored. Is this implemented as described, or am I doing something wrong?

The actual tx power does change, for what it's worth - I see the expected
difference in received signal between +4, 0, -12, -20.

Cheers,
simon.

Reply via email to