4. SDK integration
4.1 Build configuration
| Setting | Value | Notes |
|---|---|---|
SID_SDK_CONFIG_ENABLE_LINK_TYPE_1 | 1 | BLE link. Beacon data is a BLE feature. |
SID_SDK_CONFIG_ENABLE_BEACON_DATA | 1 in the SDK libraries | Compiles the beacon feature into the SDK libraries. The value is fixed when the libraries are built: the SDK 2.0.0 BLE static library is built with 1. The default in the public header sid_sdk_config.h is 0; the application does not set it and cannot change it in a prebuilt library package. |
link_mask in struct sid_config | includes SID_LINK_TYPE_1 | The options return SID_ERROR_NOSUPPORT otherwise. |
Headers: sid_api.h (the sid_option identifiers) and sid_ble_config_ifc.h (struct sid_ble_beacon_config and SID_BLE_BEACON_DATA_MAX_SIZE).
Beacon data requires SDK 2.0.0 or later with the BLE link enabled. The BLE-only static library package sid_sdk_ble_static_lib_nrf52840-DK 2.0.0 includes it.
4.2 API
The application uses two sid_option identifiers.
| Option | Value type | Description |
|---|---|---|
SID_OPTION_SET_BLE_BEACON_CONFIG | struct sid_ble_beacon_config | Sets the beacon configuration. A configuration with is_data_send, location and response_requested all false switches the beacon off. |
SID_OPTION_GET_BLE_BEACON_CONFIG | struct sid_ble_beacon_config | Copies the current configuration, including the payload, into the application’s structure. |
The configuration structure struct sid_ble_beacon_config is defined in sid_ble_config_ifc.h.
| Field | Type | Meaning |
|---|---|---|
location | bool | true: Location Beacon mode, the cloud reports the device location. false: Normal mode, the payload is delivered without a location event. |
response_requested | bool | Sets the response-requested flag of the advertisement (bit 1 of byte 13). See the explanation below the table. Set it to false in this revision. |
seq_update_period_s | uint32_t | Sequence number update period in seconds, 1 to 7200 (2 hours). 0: the sequence number advances only when the configuration changes. The period applies only to a beacon that carries a sequence number, that is, a beacon with a payload or in Location Beacon mode. |
is_data_send | bool | true: the beacon carries the payload in data, encrypted. false: no payload. |
data | uint8_t[SID_BLE_BEACON_DATA_MAX_SIZE] | The plaintext payload, always all 6 bytes. Used only when is_data_send is true. |
Pass sizeof(struct sid_ble_beacon_config) as the length argument of sid_option. The payload is part of the structure, so the application does not keep a separate buffer.
Response-requested flag. The Amazon Sidewalk BLE advertisement has a flag with which a device tells the network that it expects a reply to what it sends and that it can receive one. response_requested sets that flag in the beacon. In this revision the Amazon Sidewalk cloud does not reply to a beacon and does not act on the flag, so set the field to false. The flag has no effect on the payload, on the location estimate or on the delivery to your application. The SDK accepts and advertises any value of the flag. A configuration with the flag set, is_data_send == false and Normal mode is a valid beacon with byte 13 = 0x02; it carries no sequence number, so the update period has no effect on it. Changing the flag counts as a configuration change and advances the sequence number of a beacon that carries one (see Section 3.3).
In the example, handle is the Sidewalk handle returned by sid_init(), and counter, temp_hi, temp_lo, status and battery are values from your application.
#include <string.h>
#include <sid_api.h>
#include <sid_ble_config_ifc.h>
/* 6-byte payload in Location Beacon mode; the sequence number advances every 10 minutes */
const uint8_t payload[SID_BLE_BEACON_DATA_MAX_SIZE] = { 0x01, counter, temp_hi, temp_lo, status, battery };
struct sid_ble_beacon_config cfg = {
.location = true,
.response_requested = false,
.seq_update_period_s = 600,
.is_data_send = true,
};
memcpy(cfg.data, payload, sizeof(cfg.data));
sid_error_t ret = sid_option(handle, SID_OPTION_SET_BLE_BEACON_CONFIG, &cfg, sizeof(cfg));
/* Read the configuration back */
struct sid_ble_beacon_config current = { 0 };
ret = sid_option(handle, SID_OPTION_GET_BLE_BEACON_CONFIG, ¤t, sizeof(current));
/* Switch the beacon off */
struct sid_ble_beacon_config off = { 0 };
ret = sid_option(handle, SID_OPTION_SET_BLE_BEACON_CONFIG, &off, sizeof(off));
4.3 Return codes
| Return code (value) | Meaning |
|---|---|
SID_ERROR_NONE (0) | The configuration was accepted. This includes setting the same configuration again, which changes nothing. |
SID_ERROR_NOSUPPORT (-6) | The BLE link is not in link_mask, or the SDK libraries were built without beacon data (SID_SDK_CONFIG_ENABLE_BEACON_DATA = 0). |
SID_ERROR_INVALID_ARGS (-11) | seq_update_period_s is larger than 7200, the value pointer is NULL, or the length argument of sid_option is not sizeof(struct sid_ble_beacon_config). |
SID_ERROR_INVALID_STATE (-40) | A payload (is_data_send == true) was set while the device is not registered or does not have network time. Set the payload after the time synchronization status is SID_STATUS_TIME_SYNCED. A configuration without payload, and switching the beacon off, are accepted at any time. |
4.4 When the beacon is advertised
The SDK advertises the beacon configuration only when all of the following are true:
- The device is registered and time-synchronized.
- The device advertises in Normal mode: it is not advertising for registration (out-of-box experience, OOBE), not requesting a connection, not requesting time and not performing field activation.
- The transmit identifier is time-based, which follows from network time being available.
In every other state the advertisement is the usual Amazon Sidewalk advertisement without beacon data. The configuration is kept and is advertised again as soon as the conditions hold.
4.5 Interaction with other BLE features
| Feature | Effect on the beacon |
|---|---|
| Time synchronization request (SDK) | While the SDK requests network time, the device advertises a time request and accepts a short gateway connection. The beacon is paused and resumes afterwards with the same sequence number. The application does nothing. |
Connection request (sid_ble_bcn_connection_request(handle, true)) | The beacon is paused while the request is set and during the connection. It resumes when the request is cleared or the connection ends. |
| Field activation of a factory-registered device | The device advertises its field-activation beacon until a gateway completes the activation. The beacon configuration is advertised afterwards. |
sid_start | A configuration without payload (is_data_send == false, for example Location Beacon mode only) may be set before sid_start. It is kept and advertised when the link starts. A payload needs network time and can therefore be set only after time synchronization. |
sid_stop(handle, SID_LINK_TYPE_1) | Stopping the BLE link clears the whole beacon configuration inside the SDK, including the mode and the update period. Set it again after the next sid_start. The SDK keeps network time across sid_stop for at least SID_TIME_SYNC_MIN_PERIOD, so a payload can usually be set again right after sid_start. |
| Factory reset | Clears registration and the beacon configuration, and restores the beacon destination to 33. The device must be registered again. |