2. Overview of the functionality

Endpoints working in SubG-FSK mode must be synchronized with a gateway before an uplink or downlink transmission is performed. The synchronization mechanism uses periodic frames sent by gateways, namely Beacon frames. This process can be divided into three phases, each controlled by the Gateway Discovery and Selection feature.

Phase Description
Gateway Discovery The procedure of discovering nearby gateways through their periodic Beacon transmissions. During this phase, the Endpoint performs a passive scan listening for Amazon Sidewalk FSK beacons. Each discovered gateway to which an Endpoint can connect is added to a list. The discovery process is described in detail in the Amazon Sidewalk Specification, section 5.2.1 Beacon discovery.
Gateway Selection The second phase is the gateway selection process in which the Endpoint selects the best gateway from the list of gateways identified during the first phase based on preconfigured selection criteria.
Connection Health Monitoring The third phase is the monitoring of connection health with the connected gateway to take corrective action early in case the health of the connection with the connected gateway is deteriorating.

Table 2.1: Gateway Discovery and Selection phases.

The following sections describe the parameters and algorithms that are used in each of the three phases.

2.1 Gateway discovery parameters

The following table describes the parameters for gateway discovery.

Parameters for gateway discovery Description
Scanning timeout in seconds Gateway discovery scanning timeout in seconds. The time spent scanning before the best gateway is selected, or before a no-gateway failure is reported. See Gateway Discovery Control Events for details.
Scanning back-off The parameters that determine the scanning back-off algorithm. These parameters set the scanning intervals and also the sleep intervals between scanning. To reduce power consumption, the back-off algorithm increases the sleep intervals if the discovery process fails (when there are no gateways available for connection). See section 2.1.2 for details.
Continue scanning after fail If this option is set to true, the stack will continue the scanning process even after reporting failure to the developer of no gateways found after Scanning timeout is expired. A new Gateway Discovery scanning cycle will start after the back-off timeout ends.

Table 2.2: Parameters for gateway discovery.

2.1.1 Discovery algorithm

The gateway discovery is performed according to the following algorithm:

  1. The Scanning timeout in seconds parameter determines the total time of the SubG-FSK discovery process that the Endpoint will perform.
  2. During the discovery process, the Endpoint adds to the discovery list all gateways it can connect to.
  3. During the discovery process, the Endpoint scans during the time intervals specified in the Scanning back-off parameter. See section 2.1.2 for details.
  4. If the list contains gateways when discovery completes, control passes to the Gateway Selection algorithm.
  5. If the list contains no gateways to connect to when discovery completes, the developer is notified of the discovery failure status through the on_control_event_notify callback. See Gateway Discovery Control Events for details.
  6. Continue scanning after fail determines whether scanning continues after the Scanning timeout in seconds expires and the failure is reported.
  7. If the gateway was not selected or the connection to the gateway did not occur, the next discovery iteration will be performed according to the intervals specified in the Scanning back-off parameter.

2.1.2 Scanning back-off

In the case of an unsuccessful Gateway Discovery, when no gateway was selected, the Amazon Sidewalk MCU SDK uses timeout intervals to resume scanning (back-off). The duration of the interval depends on the number of unsuccessful discovery iterations.

Each policy has its own back-off intervals (see section 2.4). The default policy uses the following timeout intervals:

Iteration 1–5 6–15 > 15
Scan duration (s) 40 40 40
Sleep time (s) 60 300 3600

Table 2.3: Default policy back-off intervals.

If no gateway is found, the Endpoint scans for the scan duration of the current iteration, then sleeps for the matching sleep time before the next iteration.

The iteration counter is reset every time after a successful connection to the gateway or if the SubG-FSK link is restarted.

2.2 Gateway selection parameters

After the gateway discovery process is complete, the gateway selection algorithm determines the best gateway to be selected based on the list of the gateways discovered during the gateway discovery phase. The selection of the best gateway is based on the information obtained from the beacons.

The following table describes the parameters for gateway selection.

Parameters for gateway selection Description
Minimum RSSI to connect Minimum RSSI level of the beacon which should be considered for Gateway Selection. On the platforms that support LQI, RSSI is replaced by LQI.
Use Gateway Load Indicator Use the gateway load value carried in the beacon payload to evaluate the gateway during selection. See section 2.2.1 for details.
Use Cloud Connection Health Use the Cloud Connection Health value carried in the beacon payload to evaluate the gateway during selection. See section 2.2.2 for details.
Use Transmit Power Rank Use Transmit Power Rank to evaluate the gateway during selection. In this case, the algorithm will use EIRP power of the gateway indicated in the beacon’s payload to evaluate the gateway during selection. See section 2.2.3 for details.

Table 2.4: Parameters for gateway selection.

2.2.1 Gateway Load Indicator

The Load Indicator is a composite metric (0–3) of gateway load. It is transmitted in the corresponding field in the beacon. Value 0 means low gateway load, value 3 means high load.

Load Indicator is calculated on the gateway side and includes such factors as current throughput, number of connected EPs, CPU utilization, RAM utilization, etc. The calculation mechanism is platform-dependent and is not included in the scope of this document.

The developer can use this parameter to score the gateway during gateway selection and during connection health monitoring.

2.2.2 Cloud Connection Health

With Cloud Connection Health, the gateways pass additional information to the Endpoints about the status of the connection to the cloud. By passing this value through a beacon, Endpoints are able to select a more reliable gateway.

There are the following values of the Cloud Connection Health:

Cloud Connection Health Description
0 Temporarily disconnected. This state means that the gateway is not connected to the cloud at the moment, but is able to receive messages from Endpoints and buffer them. New connections are not allowed, but already-connected Endpoints stay connected.
1 Experiencing recent intermittent disconnects. This state means that the gateway is currently connected to the cloud, but has recently been disconnected. In this state, the Endpoints can connect to the gateway, but its score may be reduced.
2 No connection with the cloud. In this state, new Endpoint connections are not allowed. All connected Endpoints will be disconnected.
3 Healthy connection.

Table 2.5: Cloud Connection Health.

During the Discovery process, only gateways with Cloud Connection Health of ‘1’ or ‘3’ are considered.

2.2.3 Transmit Power Rank

The beacon payload has a field that indicates the maximum equivalent isotropic radiated power (EIRP) of the Gateway used for the current Beacon round. Using this value and the RSSI level of the received beacon, the Endpoint can estimate how close the gateway is and determine how much power is required to transmit a message to one gateway relative to another. Depending on the received EIRP and RSSI values, each gateway is assigned an evaluation characteristic called Transmit Power Rank, which can be used to score the gateway.

The table below shows the possible Transmit Power Rank values and their meaning.

Gateway EIRP used for beacon transmission Average RSSI of received beacons Transmit Power Rank Description
High High 2 The EP might be close to the gateway and might be able to use a lower TX power to communicate with the gateway. A high RSSI from a high-EIRP beacon suggests the gateway is close, but not as close as rank 1.
High Low 4 The EP might be far from the gateway and might not be able to reach the gateway or has to use higher TX power. A low RSSI even from a high-EIRP beacon suggests the gateway is the farthest of the four cases.
Low High 1 The EP might be close to the gateway and might be able to use a lower TX power to communicate with the gateway. A high RSSI from a low-EIRP beacon suggests the gateway is the closest of the four cases.
Low Low 3 The EP might be far from the gateway and might not be able to reach the gateway or has to use higher TX power. A low RSSI from a low-EIRP beacon suggests the gateway is far, but closer than rank 4.

Table 2.6: Transmit Power Rank.

A higher Transmit Power Rank means that the gateway is farther from the EP and more energy is needed for transmission.

2.2.4 Gateway score calculation

The Gateway scoring is used to determine the best Gateway to select for connection. This scoring is based on the received data from the beacon and the specified Gateway Selection parameters. Depending on the value of the criterion, a Weight (from 0 to 5) is used to calculate score points.

The table below shows the parameters for score calculation and their Weights.

Parameters for gateway score calculation Weight calculation Description
Gateway PAN Is PAN GW: Yes = 5, No = 0 If the gateway is private, then 5 points are added to its score.
Average gateway RSSI Difference from min RSSI in dBm: 0–10 = 1, 11–20 = 2, 21–30 = 3, 31–40 = 4, >= 41 = 5 The gateway with a higher RSSI level is a higher priority for selection. Points will be added to the gateway score depending on how much the signal level is above the Minimum RSSI to connect.
Gateway Load Indicator Load indicator: 0 = 4, 1 = 3, 2 = 2, 3 = 1 Load on the gateway indicated in the beacon’s payload. If the Use Gateway Load Indicator parameter is set to true, then points will be added to the gateway score.
Cloud Connection Health Experiencing recent disconnects (= 1) = 1, Healthy connection (= 3) = 3 Cloud Connection health indicated in the beacon’s payload. The gateways with connection health value ‘0’ and ‘2’ are not added to the gateway discovered list.
Transmit Power Rank Rank: 1 = 4, 2 = 3, 3 = 2, 4 = 1 Transmit Power Rank of the gateway. If the Use Transmit Power Rank parameter is set to true, then points will be added to the Gateway score.

Table 2.7: Parameters for gateway score calculation.

The following example calculates the gateway score using these Gateway Selection parameters:

  • Minimum RSSI to connect = -90 dBm
  • Use Gateway Load Indicator = true
  • Use Cloud Connection Health = true
  • Use Transmit Power Rank = true

Sample discovered gateway list that has three gateways and their parameters. In the following example, Gateway #1 with total score 14 will be selected for connection.

Gateway # Is PAN Average RSSI Load Indicator Cloud Connection Health Transmit Power Rank Score
1 true
Weight = 5
-60
Difference from min RSSI is 30
Weight = 3
2
Weight = 2
1
Weight = 1
2
Weight = 3
5 + 3 + 2 + 1 + 3 = 14
2 false
Weight = 0
-45
Difference from min RSSI is 45
Weight = 5
0
Weight = 4
3
Weight = 3
1
Weight = 4
0 + 5 + 4 + 3 + 4 = 13
3 false
Weight = 0
-90
Difference from min RSSI is 0
Weight = 1
3
Weight = 1
3
Weight = 3
4
Weight = 1
0 + 1 + 1 + 3 + 1 = 6

Table 2.8: Gateway score calculation example.

2.2.5 Gateway selection algorithm

The gateway selection is performed according to the following algorithm:

  1. From the list of discovered gateways, those gateways to which a connection is possible are considered.
  2. If there is more than one gateway to connect to in the list, the score of each gateway is calculated to determine the best one.
  3. The score is calculated by adding the weights of the parameters mentioned in the above table.
  4. Depending on policy settings, certain parameters may not be considered when calculating the score.
  5. If no gateway is found that satisfies the selection criteria, the developer is notified using the control event notify callback on_control_event_notify.
  6. If a gateway is selected for connection, the EP enters beacon synchronization mode with the selected gateway. In this case, the developer will be notified with the corresponding event using on_control_event_notify.
  7. After connecting the EP to the gateway, the control moves to the Connection Health Monitoring phase.

2.3 Gateway connection health monitoring

After connecting to a gateway, the Endpoint enters the connection health monitoring phase. During this phase, the Endpoint monitors key gateway parameters to determine if the gateway is still suitable for maintaining the connection.

The following table describes the parameters for Gateway Connection Health Monitoring.

Parameters for connection health monitoring Description
Threshold RSSI to disconnect RSSI level at which the EP initiates disconnection from the connected gateway. On the platforms that support LQI, RSSI is replaced by LQI.
Number of beacons for threshold RSSI Number of beacons to calculate the average RSSI level to initiate disconnection by Threshold RSSI to disconnect.
Maximum missed beacons The number of consecutive missed beacons at which the EP reports a disconnection and starts a new discovery process.
Maximum skipped beacons The maximum number of beacons the EP can skip listening to. This parameter does not affect the decision to disconnect, but is used to save power once connected.
Gateway Load to disconnect If the load indicator in the beacon is greater than or equal to this value, the EP initiates disconnection. Valid thresholds are 1–3. Zero means the parameter is not used.

Table 2.9: Parameters for connection health monitoring.

2.3.1 Monitoring algorithm

The Gateway Connection Health Monitoring is based on information from the connected gateway beacons. For a more detailed description of the beacon format and available fields, see the Amazon Sidewalk Specification, section 5.1.3.1 Beacon Frame format.

The Gateway Connection Health Monitoring is performed according to the following algorithm:

  1. The Endpoint monitors the beacons of the connected gateway and analyzes the values of its internal fields.
  2. If the Endpoint is connected to a WAN gateway, then the roam_opt flag from the Beacon Connection Status field is analyzed. If the roam_opt field is 0, the Endpoint disconnects from the gateway, notifies the developer through the on_control_event_notify callback, and immediately starts a new discovery process.
  3. If the Cloud Connection Health value is 2 (cloud_conn field), the Endpoint disconnects from the gateway, notifies the developer, and immediately starts the discovery process.
  4. The number of consecutive beacons from the connected gateway that are missed are tracked to determine whether the EP is still connected to the gateway. When the number of consecutive missed beacons reaches Maximum missed beacons, the EP switches from the connected state to gateway discovery state. The stack also reports the disconnected link status through the on_status_changed callback.
  5. If the average RSSI level of the received beacons is below the specified Threshold RSSI to disconnect, the Endpoint triggers disconnection from the connected gateway and starts a new discovery process. The number of beacons for calculating the average RSSI is specified in the Number of beacons for threshold RSSI parameter.
  6. If Gateway Load to disconnect is non-zero and the load indicator in the beacon is greater than or equal to Gateway Load to disconnect, the Endpoint disconnects from the gateway and starts a new discovery process.

2.4 Gateway Discovery and Selection policies

The Gateway Discovery and Selection feature is controlled at build time by the build flag SID_SDK_INTERNAL_CONFIG_ENABLE_GW_SELECTION. The flag is set to 1 (enabled) by default, so integrators normally do not need to change it. The OPTIMIZED_FOR_FAST_CONNECTION, OPTIMIZED_FOR_RELIABLE_CONNECTION, OPTIMIZED_FOR_POWER_SAVE, and CUSTOM policies are available only when the flag is enabled.

Call sid_init before setting the gateway discovery policy with sid_option. The gateway discovery policy can be configured successfully only if the sid_init function was called using the link_mask parameter with the flag SID_LINK_TYPE_2 (FSK).

The Gateway Discovery and Selection policy does not persist within the stack across reboots. The developer is expected to set the preferred gateway discovery policy on every reboot of the device.

The following enumeration shows the policies that are available to the developer to configure the gateway discovery policy.

/**
 * Describes the gateway discovery policy modes for FSK
 */
enum sid_link_type_2_gw_discovery_policy {
    /** Default policy applied. The GW discovery behavior
     *  is same as 1.16 SDK release which is to connect to
     *  the first beacon which has opt-in flag set to true
     */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_DEFAULT = 0,
    /** Policy optimized for connection latency: scans for 30 s,
     *  then selects the best gateway found.
     */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_FAST_CONNECTION = 1,
    /** Policy optimized for highest reliability to establish a connection,
     *  the gateway with the best RSSI and healthy connection is selected.
     */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_RELIABLE_CONNECTION = 2,
    /** Policy optimized for minimum power consumption. */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_POWER_SAVE = 3,
    /** Policy for implementing a custom user scenario */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM = 4,
    /** Delimiter to enum sid_link_type_2_gw_discovery_policy */
    SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_LAST,
};

The developer can change the discovery policy at any time after the Sidewalk stack has been initialized, even if the Endpoint is already connected to the gateway.

If the developer has started the stack with the sid_start function and the Endpoint is not connected to a gateway, changing the policy resets all timeouts and restarts the gateway discovery process with the new timeouts.

If the Endpoint is connected to a gateway, it stays connected and only the monitoring parameters change according to the new policy.

There are four discovery policies with predefined parameters and the SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM policy that allows the developer to use their own parameters.

Unless Continue scanning after fail is set to false, each policy continues to scan and follow its scanning back-off until the developer changes the policy or stops the SubG-FSK link.

The following sections describe each policy, its parameters, and behavior.

2.4.1 Default policy

Gateway Discovery and Selection policy: SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_DEFAULT

Description: This is the default policy. It selects the first gateway to which the EP can connect. The connection time depends on how long it takes for the EP to receive the first beacon. This algorithm is fully compatible with previous versions of the SDK.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 40
Continue scanning after fail true

Table 2.10: Default policy: gateway discovery parameters.

Scanning back-off

Iteration 1–5 6–15 > 15
Scan duration (s) 40 40 40
Sleep time (s) 60 300 3600

Table 2.11: Default policy: scanning back-off.

Gateway selection parameters: Not applicable to default policy.

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) Not used
Number of beacons for threshold RSSI Not used
Maximum missed beacons 3
Maximum skipped beacons 0
Gateway Load to disconnect Not used

Table 2.12: Default policy: connection health monitoring parameters.

2.4.2 Optimized for fast connection policy

Gateway Discovery and Selection policy: SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_FAST_CONNECTION

Description: The policy optimized for latency to establish a connection. The developer is notified of the discovery status sooner than with other policies. The EP scans for 30 seconds before selecting a gateway from the discovered list, so the connection time is at least 30 seconds, and the developer is notified within 30 seconds if no gateway matches the selection criteria.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 30
Continue scanning after fail true

Table 2.13: Optimized for fast connection policy: gateway discovery parameters.

Scanning back-off

Iteration 1–5 6–15 > 15
Scan duration (s) 30 30 20
Sleep time (s) 30 60 120

Table 2.14: Optimized for fast connection policy: scanning back-off.

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) -90
Use Gateway Load Indicator true
Use Cloud Connection Health true
Use Transmit Power Rank false

Table 2.15: Optimized for fast connection policy: gateway selection parameters.

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) -95
Number of beacons for threshold RSSI 3
Maximum missed beacons 2
Maximum skipped beacons 0
Gateway Load to disconnect Not used

Table 2.16: Optimized for fast connection policy: connection health monitoring parameters.

2.4.3 Optimized for reliable connection policy

Gateway Discovery and Selection policy: SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_RELIABLE_CONNECTION

Description: This policy prioritizes reliable delivery of messages in both uplink and downlink. It is recommended to configure this policy when there is a requirement for the EP to perform high throughput traffic. The EP scans for 90 seconds before selecting a gateway from the discovered list, so the connection time is at least 90 seconds, and the developer is notified within 90 seconds if no gateway matches the selection criteria.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 90
Continue scanning after fail true

Table 2.17: Optimized for reliable connection policy: gateway discovery parameters.

Scanning back-off

Iteration 1–5 6–15 > 15
Scan duration (s) 90 30 30
Sleep time (s) 30 300 3600

Table 2.18: Optimized for reliable connection policy: scanning back-off.

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) -75
Use Gateway Load Indicator true
Use Cloud Connection Health true
Use Transmit Power Rank true

Table 2.19: Optimized for reliable connection policy: gateway selection parameters.

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) -85
Number of beacons for threshold RSSI 3
Maximum missed beacons 2
Maximum skipped beacons 0
Gateway Load to disconnect 3

Table 2.20: Optimized for reliable connection policy: connection health monitoring parameters.

2.4.4 Optimized for power save policy

Gateway Discovery and Selection policy: SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_POWER_SAVE

Description: This policy is optimized for power consumption and recommended to be used when little data is sent or received, or data is sent infrequently.

The policy performs discovery according to the intervals specified in the scanning back-off parameter, i.e. 30 seconds of scanning alternates with 120 seconds of sleep. After the total scanning time is 120 seconds, the EP enters the phase of selecting a gateway from the discovered list. Four scan windows of 30 seconds separated by three sleeps of 120 seconds give a minimum connection time of 480 seconds. The developer is notified by the on_control_event_notify() callback if no gateway is found that matches the selection criteria.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 120
Continue scanning after fail true

Table 2.21: Optimized for power save policy: gateway discovery parameters.

Scanning back-off

Iteration 1–5 6–15 > 15
Scan duration (s) 30 20 10
Sleep time (s) 120 600 3600

Table 2.22: Optimized for power save policy: scanning back-off.

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) -80
Use Gateway Load Indicator true
Use Cloud Connection Health true
Use Transmit Power Rank true

Table 2.23: Optimized for power save policy: gateway selection parameters.

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) -85
Number of beacons for threshold RSSI 3
Maximum missed beacons 5
Maximum skipped beacons 2
Gateway Load to disconnect 3

Table 2.24: Optimized for power save policy: connection health monitoring parameters.

2.4.5 Custom policy

Gateway Discovery and Selection policy: SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM

Description: This policy allows the developer to set custom parameters. Using this policy, the developer sets all discovery, selection, and monitoring parameters to control the Gateway Discovery and Selection process. The connection time under this policy depends on the value specified by the developer.

The developer can optimize the parameters of this policy according to the application requirements. If no gateway was discovered with the given parameters, the developer can change the selection criteria before the next discovery cycle.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds Provided by developer
Continue scanning after fail Provided by developer

Table 2.25: Custom policy: gateway discovery parameters.

Scanning back-off (provided by developer; the following custom policy defaults are used when backoff_params is NULL)

Iteration 1–5 6–15 > 15
Scan duration (s) 30 30 30
Sleep time (s) 60 600 3600

Table 2.26: Custom policy: scanning back-off.

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) Provided by developer
Use Gateway Load Indicator Provided by developer
Use Cloud Connection Health Provided by developer
Use Transmit Power Rank Provided by developer

Table 2.27: Custom policy: gateway selection parameters.

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) Provided by developer
Number of beacons for threshold RSSI Provided by developer
Maximum missed beacons Provided by developer
Maximum skipped beacons Provided by developer
Gateway Load to disconnect Provided by developer

Table 2.28: Custom policy: connection health monitoring parameters.

2.4.6 Using the sid_option API to manage policies

The following data structures are used to manage Gateway Discovery and Selection policies and their parameters.

/** Defines the necessary constants for GW discovery */
enum sid_link_type_2_gw_discovery_defines {
    SID_LINK_TYPE_2_GWD_BACKOFF_ARRAY_MAX_SIZE = 4,
};

/** Describes parameters for gateway discovery backoff intervals */
struct sid_link_type_2_gw_discovery_backoff_params {
    /** Number of elements in the backoff table */
    uint8_t retry_arr_size;
    /** Retry threshold for transition to the next intervals */
    uint8_t retry_threshold[SID_LINK_TYPE_2_GWD_BACKOFF_ARRAY_MAX_SIZE];
    /** Scan duration in seconds */
    uint16_t retry_scan_duration_s[SID_LINK_TYPE_2_GWD_BACKOFF_ARRAY_MAX_SIZE];
    /** Sleep time in seconds between scanning */
    uint16_t retry_sleep_time_s[SID_LINK_TYPE_2_GWD_BACKOFF_ARRAY_MAX_SIZE];
};

The back-off table has up to SID_LINK_TYPE_2_GWD_BACKOFF_ARRAY_MAX_SIZE (4) tiers, and retry_arr_size gives the number of tiers in use. Each retry_threshold value is the exclusive upper bound of its tier: tier i applies while retry_threshold[i-1] <= scan retries < retry_threshold[i], and the last tier applies once the retry count reaches its threshold. The value 255 (0xFF) means infinite. The thresholds must be non-zero and strictly increasing.

/**
 * Describes parameters for the custom gateway discovery policy
 */
struct sid_link_type_2_gw_discovery_custom_policy_params {
    /** Gateway discovery scanning timeout in seconds */
    uint16_t scan_timeout_secs;
    /** Continue to scan even after scan_timeout_secs has expired */
    bool continue_scanning_after_fail;
    /** Gateway discovery backoff parameters.
     *  Set this parameter to NULL to use default values.
     */
    struct sid_link_type_2_gw_discovery_backoff_params *backoff_params;
    /** Minimum RSSI level at which connection is allowed.
     *  Zero means the parameter is not used
     */
    int8_t min_rssi_to_connect;
    /** RSSI level at which EP initiates disconnection from
     *  the connected gateway. Should be less than min_rssi_to_connect
     */
    int8_t threshold_rssi_to_disconnect;
    /** Number of beacons to calculate the average RSSI level
     *  for threshold_rssi_to_disconnect.
     *  Zero means the parameter is not used
     */
    int8_t threshold_rssi_msg_num;
    /** The number of consecutive missed beacons at which
     *  the EP reports a disconnection.
     */
    uint8_t max_beacon_miss;
    /** The maximum number of beacons the EP can skip listening */
    uint8_t max_beacon_skip;
    /** Use gateway load to calculate gw score */
    bool use_gateway_load_for_selection;
    /** Gateway load at which EP initiates disconnection from the
     *  connected gateway. The range is [0,3].
     *  Zero means the parameter is not used
     */
    uint8_t gateway_load_to_disconnect;
    /** Use gateway connection health to calculate gw score */
    bool use_gateway_connection_health_for_selection;
    /** Use gateway transmit power rank to calculate gw score */
    bool use_gateway_tx_power_rank_for_selection;
};
/**
 * The structure used to configure the gateway discovery policy
 */
struct sid_link_type_2_gw_discovery_policy_config {
    /** Gateway discovery policy */
    enum sid_link_type_2_gw_discovery_policy policy;
    /** Parameters for the custom gateway discovery policy */
    struct sid_link_type_2_gw_discovery_custom_policy_params *policy_params;
    /** True: Set policy config, False: Get policy config */
    bool is_set;
};

The sid_link_type_2_gw_discovery_policy_config structure is used to configure the discovery policy. To set a predefined policy, specify only the policy value. The parameters of predefined policies are applied inside the Amazon Sidewalk stack and therefore do not need to be specified. Also, the developer can get the current policy at any time.

The following example sets a predefined discovery policy and then gets the current policy. In this and the following examples, sidewalk_handle is the Sidewalk handle returned by sid_init().

// Set/get the gateway discovery and selection policy with sid_option()

// Set gateway discovery and selection policy to
// SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_FAST_CONNECTION
struct sid_link_type_2_gw_discovery_policy_config set_cfg = {
    .is_set = true,
    .policy = SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_OPTIMIZED_FOR_FAST_CONNECTION,
};
sid_error_t ret = sid_option(sidewalk_handle,
                             SID_OPTION_LINK_TYPE_2_GW_DISCOVERY_POLICY,
                             &set_cfg, sizeof(set_cfg));

// Get current gateway discovery and selection policy
struct sid_link_type_2_gw_discovery_policy_config get_cfg = {
    .is_set = false,
};
ret = sid_option(sidewalk_handle,
                 SID_OPTION_LINK_TYPE_2_GW_DISCOVERY_POLICY,
                 &get_cfg, sizeof(get_cfg));

To use the SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM policy, the developer must provide the parameters using the sid_link_type_2_gw_discovery_custom_policy_params structure.

To use the custom policy’s default scanning back-off intervals, the backoff_params parameter must be set to NULL. If the developer wants to override the default scanning back-off interval values, a filled sid_link_type_2_gw_discovery_backoff_params structure must be passed.

The stack rejects the custom policy parameters with SID_ERROR_INVALID_ARGS if any of the following is true:

  • scan_timeout_secs is 0.
  • gateway_load_to_disconnect is greater than 3 (SID_GWD_GATEWAY_LOAD_MAX).
  • The retry_threshold values in backoff_params are not strictly increasing.
  • threshold_rssi_to_disconnect is not consistent with min_rssi_to_connect (it should be less than min_rssi_to_connect).

The following sections contain several examples of configuring a custom discovery policy using the API.

Custom policy example 1

Custom policy conditions

This example shows the use of a custom policy with the custom policy’s default scanning back-off intervals (backoff_params = NULL) and the use of all possible parameters for gateway selection and further monitoring of the connected gateway’s health. The gateway will be selected after 30 seconds of scanning. In case of failure, the developer will be notified via the on_control_event_notify() callback and the scanning process will continue after the appropriate sleep interval.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 30
Continue scanning after fail true

Scanning back-off

Iteration 1–5 6–15 > 15
Scan duration (s) 30 30 30
Sleep time (s) 60 600 3600

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) -90
Use Gateway Load Indicator true
Use Cloud Connection Health true
Use Transmit Power Rank true

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) -100
Number of beacons for threshold RSSI 3
Maximum missed beacons 3
Maximum skipped beacons 0
Gateway Load to disconnect 3

Implementation

// Set parameters for the custom gateway discovery policy
struct sid_link_type_2_gw_discovery_custom_policy_params policy_params = {
    .scan_timeout_secs = 30,
    // set NULL to use default scanning back-off intervals
    .backoff_params = NULL,
    .continue_scanning_after_fail = true,
    .min_rssi_to_connect = -90,
    .use_gateway_load_for_selection = true,
    .use_gateway_connection_health_for_selection = true,
    .use_gateway_tx_power_rank_for_selection = true,
    .threshold_rssi_to_disconnect = -100,
    .threshold_rssi_msg_num = 3,
    .max_beacon_miss = 3,
    .max_beacon_skip = 0,
    .gateway_load_to_disconnect = 3,
};

// Preparing the structure to configure the gateway discovery policy
struct sid_link_type_2_gw_discovery_policy_config policy_config = {
    .policy = SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM,
    .policy_params = &policy_params,
    .is_set = true,
};

// Set the gateway discovery policy with sid_option()
sid_error_t ret = sid_option(sidewalk_handle,
                             SID_OPTION_LINK_TYPE_2_GW_DISCOVERY_POLICY,
                             &policy_config, sizeof(policy_config));

Example 2.1: Custom policy example 1.

Custom policy example 2

Custom policy conditions

This example shows the use of a policy with custom scanning back-off intervals. The gateway will be selected after 60 seconds of scanning. The gateway is selected by RSSI and Transmit Power Rank (plus PAN status), with no minimum RSSI. Disconnection from the selected gateway will be performed only when the beacon sync is lost.

In case of failure, the developer will be notified via the on_control_event_notify() callback and the scanning process will continue after the appropriate sleep interval.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 60
Continue scanning after fail true

Scanning back-off

Iteration 1–10 11–20 21–30 > 30
Scan duration (s) 60 60 60 60
Sleep time (s) 60 120 240 480

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) Not used
Use Gateway Load Indicator false
Use Cloud Connection Health false
Use Transmit Power Rank true

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) Not used
Number of beacons for threshold RSSI Not used
Maximum missed beacons 3
Maximum skipped beacons 0
Gateway Load to disconnect Not used

Implementation

// Set parameters for gateway discovery back-off intervals
struct sid_link_type_2_gw_discovery_backoff_params backoff_params = {
    .retry_arr_size = 4,
    .retry_threshold = {10, 20, 30, 255},  // the value 255 means infinite
    .retry_scan_duration_s = {60, 60, 60, 60},
    .retry_sleep_time_s = {60, 120, 240, 480},
};

// Set parameters for the custom gateway discovery policy
struct sid_link_type_2_gw_discovery_custom_policy_params policy_params = {
    .scan_timeout_secs = 60,
    .backoff_params = &backoff_params,
    .continue_scanning_after_fail = true,
    // set the value to 0 to disable the parameter
    .min_rssi_to_connect = 0,
    .use_gateway_load_for_selection = false,
    .use_gateway_connection_health_for_selection = false,
    .use_gateway_tx_power_rank_for_selection = true,
    // set the value to 0 to disable the parameter
    .threshold_rssi_to_disconnect = 0,
    .threshold_rssi_msg_num = 0,
    .max_beacon_miss = 3,
    .max_beacon_skip = 0,
    // set the value to 0 to disable the parameter
    .gateway_load_to_disconnect = 0,
};

// Preparing the structure to configure the gateway discovery policy
struct sid_link_type_2_gw_discovery_policy_config policy_config = {
    .policy = SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM,
    .policy_params = &policy_params,
    .is_set = true,
};

// Set the gateway discovery policy with sid_option()
sid_error_t ret = sid_option(sidewalk_handle,
                             SID_OPTION_LINK_TYPE_2_GW_DISCOVERY_POLICY,
                             &policy_config, sizeof(policy_config));

Example 2.2: Custom policy example 2.

Custom policy example 3

Custom policy conditions

This example shows the use of a policy with custom scanning back-off intervals. The gateway will be selected after two 20-second scan iterations, with a 20-second sleep interval between them. In total, the first gateway selection will be made after 60 seconds. If the gateway is not selected, the developer will be notified via the on_control_event_notify() callback and the discovery process will be stopped. In this case, to restart the discovery process, the developer must restart the link or select another policy.

Gateway discovery parameters

Parameter Setting
Scanning timeout in seconds 40
Continue scanning after fail false

Scanning back-off

Iteration >= 1
Scan duration (s) 20
Sleep time (s) 20

Gateway selection parameters

Parameter Setting
Minimum RSSI to connect (dBm) -85
Use Gateway Load Indicator true
Use Cloud Connection Health true
Use Transmit Power Rank true

Connection health monitoring

Parameter Setting
Threshold RSSI to disconnect (dBm) -95
Number of beacons for threshold RSSI 5
Maximum missed beacons 4
Maximum skipped beacons 0
Gateway Load to disconnect Not used

Implementation

// Set parameters for gateway discovery back-off intervals
struct sid_link_type_2_gw_discovery_backoff_params backoff_params = {
    .retry_arr_size = 1,
    .retry_threshold = {255},  // the value 255 means infinite
    .retry_scan_duration_s = {20},
    .retry_sleep_time_s = {60},
};

// Set parameters for the custom gateway discovery policy
struct sid_link_type_2_gw_discovery_custom_policy_params policy_params = {
    .scan_timeout_secs = 20,
    .backoff_params = &backoff_params,
    .continue_scanning_after_fail = false,
    .min_rssi_to_connect = -85,
    .use_gateway_load_for_selection = true,
    .use_gateway_connection_health_for_selection = true,
    .use_gateway_tx_power_rank_for_selection = true,
    .threshold_rssi_to_disconnect = -95,
    .threshold_rssi_msg_num = 5,
    .max_beacon_miss = 4,
    .max_beacon_skip = 0,
    // set the value to 0 to disable the parameter
    .gateway_load_to_disconnect = 0,
};

// Preparing the structure to configure the gateway discovery policy
struct sid_link_type_2_gw_discovery_policy_config policy_config = {
    .policy = SID_LINK_TYPE_2_GW_DISCOVERY_POLICY_CUSTOM,
    .policy_params = &policy_params,
    .is_set = true,
};

// Set the gateway discovery policy with sid_option()
sid_error_t ret = sid_option(sidewalk_handle,
                             SID_OPTION_LINK_TYPE_2_GW_DISCOVERY_POLICY,
                             &policy_config, sizeof(policy_config));

Example 2.3: Custom policy example 3.