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.
8 years, 1 month 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:
1 Answer
8 years, 1 month 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/