Report
2 years, 12 months ago.

mDot_LoRa_Connect_Example string clearing?

Hi, I'm using the mDot_LoRa_Connect_Example. I moved the format string section into the while loop, so I can constantly read an ADC value and update the string. My problem is that the string does not stop growing. How can I clear the string after it is sent?

Here is my modified code:

while (true) {

format data for sending to the gateway for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) data.push_back((uint8_t) *it);

logInfo("The data length is %d",data_str.length());

adc = analog_in1.read_u16(); source1 = !source1; myled = source1;

data_str = "ADC= "; ss << adc; tempstr = ss.str(); data_str.append(tempstr);

send the data to the gateway if ((ret = dot->send(data)) != mDot::MDOT_OK) logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str());

else { logInfo("successfully sent data to gateway"); logInfo("SNR is %d",dot->getSnrStats().last); logInfo("RSSI is %d",dot->getRssiStats().last); logInfo("The adc is %d",adc); logInfo("The led is %d",myled); data_str.clear(); }

in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs()));

data_str.clear(); data.clear(); data_str.erase(0,52);

}

return 0; }

Question relating to:

The MultiConnect® mDot™ offers significantly longer range and improved radio performance compared to traditional wireless solutions—resulting in greater transmission range and reduced capital expense.
Comment on this question

1 Answer

2 years, 12 months ago.

What portion is growning? The data portion after "ADC="?

I assume 'ss' is a stringstream. Try clearing that out in the loop to or it will accumulate.

ss.clear(), ss.str("");

http://www.cplusplus.com/reference/sstream/stringstream/

Hi Jason,

Yes, the ADC value keept adding the new value and I was not able to clear the old one, so it kept growing. The ss.str("") is clearing it the string stream and I also do the data.clear(). Both were needed to clear the string with my updated my values.

Thanks a lot.

posted by Erick Gomez 27 Apr 2016

To post an answer, please log in.