Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 7 months ago.
I don't want to wait for the server response.
Quote:
I have modified 'setTxWait' to false at Line 107, but the 'time_used' is same when 'setTxWait' is true. How can I let my mDot send the data without waiting response?
ota_example.cpp
#include "dot_util.h" #include "RadioEvent.h" #include <sstream> #if ACTIVE_EXAMPLE == OTA_EXAMPLE static uint8_t network_id[] = { ... }; static uint8_t network_key[] = { ... }; static uint8_t frequency_sub_band = 1; static lora::NetworkType public_network = lora::PUBLIC_LORAWAN; static uint8_t join_delay = 5; static uint8_t ack = 0; static bool adr = false; mDot* dot = NULL; lora::ChannelPlan* plan = NULL; AnalogIn CAin(PA_4); //D10 AnalogIn CAout(PA_7); //D11 float threshold_voltage = 0.5; float sensorResultAin; float sensorResultAout; bool isAin_raise = false; bool isAout_raise = false; uint8_t In_counter = 0; uint8_t Out_counter = 0; Timer timer; void counter() { sensorResultAin = CAin.read(); //A in sensorResultAout = CAout.read(); //A out // logInfo("Ain %f, Aout %f",sensorResultAin, sensorResultAout); if(!isAin_raise && sensorResultAin > threshold_voltage) In_counter++, isAin_raise = true; else if(sensorResultAin < threshold_voltage - 0.2) isAin_raise = false; if(!isAout_raise && sensorResultAout > threshold_voltage) Out_counter++, isAout_raise = true; else if(sensorResultAout < threshold_voltage - 0.2) isAout_raise = false; wait_ms(50); } int main() { plan = new lora::ChannelPlan_US915(); assert(plan); dot = mDot::getInstance(plan); assert(dot); if (!dot->getStandbyFlag()) { logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); // start from a well-known state logInfo("defaulting Dot configuration"); dot->resetConfig(); dot->resetNetworkSession(); // make sure library logging is turned on dot->setLogLevel(mts::MTSLog::INFO_LEVEL); // update configuration if necessary if (dot->getJoinMode() != mDot::OTA) { logInfo("changing network join mode to OTA"); if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) { logError("failed to set network join mode to OTA"); } } // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY // only one method or the other should be used! // network ID = crc64(network name) // network KEY = cmac(network passphrase) // update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack); update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); // configure network link checks // network link checks are a good alternative to requiring the gateway to ACK every packet and should allow a single gateway to handle more Dots // check the link every count packets // declare the Dot disconnected after threshold failed link checks // for count = 3 and threshold = 5, the Dot will ask for a link check response every 5 packets and will consider the connection lost if it fails to receive 3 responses in a row // update_network_link_check_config(3, 5); // enable or disable Adaptive Data Rate dot->setAdr(adr); // Configure the join delay dot->setJoinDelay(join_delay); // Configure TxPower dot->setTxPower(20); // Configure LBT dot->setLbtTimeUs(5000); dot->setLbtThreshold(-80); // Configure TxDataRate dot->setTxDataRate(0); if (dot->setTxWait(false) != mDot::MDOT_OK) logError("Failed to set TxWait"); // save changes to configuration logInfo("saving configuration"); if (!dot->saveConfig()) { logError("failed to save configuration"); } // display configuration display_config(); } else { // restore the saved session if the dot woke from deepsleep mode // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep logInfo("restoring network session from NVM"); dot->restoreNetworkSession(); } while (true) { // join network if not joined if (!dot->getNetworkJoinStatus()) { join_network(); } timer.start(); counter(); if(timer.read() > 15) { stringstream ss; string data_str; vector<uint8_t> tx_data; ss << (int)In_counter << "@" << (int)Out_counter; ss >> data_str; for (string::iterator it = data_str.begin(); it != data_str.end(); it++) tx_data.push_back((uint8_t) *it); logInfo("TxWait: %d", dot->getTxWait()); logInfo("sending uplink with IN = %d, OUT = %d", In_counter, Out_counter); float time_used; time_used = timer.read(); send_data(tx_data); time_used = timer.read() - time_used; logInfo("Time used: %fs", time_used); timer.reset(); } } } #endif
Question relating to:
1 Answer
6 years, 7 months ago.
Modify the send_data function to call dot->send without blocking.
From mDot.h /**
- Send data to the gateway
- validates data size (based on spreading factor)
- @param data a vector of up to 242 bytes (may be less based on spreading factor)
- @returns MDOT_OK if packet was sent successfully (ACKs disabled), or if an ACK was received (ACKs enabled)
- / int32_t send(const std::vector<uint8_t>& data, const bool& blocking = true, const bool& highBw = false);