From b0b026126c01778d0f164fee410b7269091ab6af Mon Sep 17 00:00:00 2001 From: Hasnain Virk Date: Thu, 26 Jul 2018 11:41:35 +0300 Subject: [PATCH] [IOTCELL-1181] Using higher data rates to connect The stack was trying to connect with default data rates which happened to be the lowest data rates in a specific region. In the beginning device and NS do not have agreed upon tx rx parameters and there can be synchronization issues. When we use lower datarates, we may end up having a minute and a half long transmissions that hnot only blocks the channel for a long time but also reduce the chance of proper synch between device and NS. That's why we have decided to begin with higher data rates and gradually decrease datarate if we do not hear from the network server. --- features/lorawan/lorastack/mac/LoRaMac.cpp | 4 +--- features/lorawan/lorastack/phy/LoRaPHY.cpp | 12 ++++++++++-- features/lorawan/lorastack/phy/LoRaPHY.h | 8 ++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/features/lorawan/lorastack/mac/LoRaMac.cpp b/features/lorawan/lorastack/mac/LoRaMac.cpp index 6d7ed946bd..de3d45bf3c 100644 --- a/features/lorawan/lorastack/mac/LoRaMac.cpp +++ b/features/lorawan/lorastack/mac/LoRaMac.cpp @@ -1755,9 +1755,7 @@ lorawan_status_t LoRaMac::initialize(EventQueue *queue) _params.timers.mac_init_time = _lora_time.get_current_time(); _params.sys_params.adr_on = MBED_CONF_LORA_ADR_ON; - - _params.is_nwk_public = MBED_CONF_LORA_PUBLIC_NETWORK; - _lora_phy->setup_public_network_mode(MBED_CONF_LORA_PUBLIC_NETWORK); + _params.sys_params.channel_data_rate = _lora_phy->get_default_max_tx_datarate(); return LORAWAN_STATUS_OK; } diff --git a/features/lorawan/lorastack/phy/LoRaPHY.cpp b/features/lorawan/lorastack/phy/LoRaPHY.cpp index f889a09161..5c288c9eb3 100644 --- a/features/lorawan/lorastack/phy/LoRaPHY.cpp +++ b/features/lorawan/lorastack/phy/LoRaPHY.cpp @@ -514,13 +514,16 @@ void LoRaPHY::reset_to_default_values(loramac_protocol_params *params, bool init params->sys_params.channel_tx_power = get_default_tx_power(); - params->sys_params.channel_data_rate = get_default_tx_datarate(); + // We shall always start with highest achievable data rate. + // Subsequent decrease in data rate will mean increase in range henceforth. + params->sys_params.channel_data_rate = get_default_max_tx_datarate(); params->sys_params.rx1_dr_offset = phy_params.default_rx1_dr_offset; params->sys_params.rx2_channel.frequency = get_default_rx2_frequency(); - params->sys_params.rx2_channel.datarate = get_default_rx2_datarate(); + // RX2 data rate should also start from the maximum + params->sys_params.rx2_channel.datarate = get_default_max_tx_datarate(); params->sys_params.uplink_dwell_time = phy_params.ul_dwell_time_setting; @@ -560,6 +563,11 @@ uint8_t LoRaPHY::get_default_tx_datarate() return phy_params.default_datarate; } +uint8_t LoRaPHY::get_default_max_tx_datarate() +{ + return phy_params.default_max_datarate; +} + uint8_t LoRaPHY::get_default_tx_power() { return phy_params.default_tx_power; diff --git a/features/lorawan/lorastack/phy/LoRaPHY.h b/features/lorawan/lorastack/phy/LoRaPHY.h index 2302064b8c..317c616297 100644 --- a/features/lorawan/lorastack/phy/LoRaPHY.h +++ b/features/lorawan/lorastack/phy/LoRaPHY.h @@ -423,6 +423,14 @@ public: */ uint8_t get_default_tx_datarate(); + /** + * @brief get_default_max_tx_datarate Gets the maximum achievable data rate for + * LoRa modulation. This will always be the highest data rate achievable with + * LoRa as defined in the regional specifications. + * @return Maximum achievable data rate with LoRa modulation. + */ + uint8_t get_default_max_tx_datarate(); + /** * @brief get_default_tx_power Gets the default TX power * @return Default TX power