Hi, I have been trying really hard to replace a string of text, that I have no problem in sending and receiving, but I simply cannot figure out how to change my string of text with my sensor data (Accumulated number of pulses from sensor).
I have the sensor data running fine, it’s called “totalFlow”
The current working string is based on Andreas Spiess’ code which is based on Thomas Telkamp and Matthijs Kooijman’s code.
This is the current string stating the message, located in the beginning:
Thank you, unfortunately I wasn’t able to find anything solving my problem…
I “fear” this is really simple, and I just haven’t cracked the code… I suppose it is only a single string i need to change in order to send the data instead of the message.
I want to replace “test1234” with the accumulated number of pulses from my sensor, and have that number sent to ttn, and keep sending the new accumulated numbers onwards
First link I clicked on when googling “LMIC sending sensor data” has this in it.
void do_send(osjob_t* j){
float temperature = getTemp();
if (LMIC.opmode & OP_TXRXPEND) {
Serial.println(F("OP_TXRXPEND, not sending"));
} else {
// Prepare data transmission at the next possible time.
LMIC_setTxData2(1,(uint8_t*)&temperature),sizeof(float),0);
}
}
Where getTemp() is your flow value from before the do_send loop, and temperature is the place holding value for getTemp() that is within the do_send loop.
That should be easy enough to change to your liking. Just as a heads up since I don’t know your level of programming experience I just want to explain that you really shouldn’t be trying to change something that’s set as static because that defeats the whole purpose of it being static besides the possibilities that something could be wrong in another part of your program that would ultimately screw up the static value or have it get stuck.
Don’t send numbers as text, that’s just a waste of bandwidth.
While in the example declaring static does not seem to be helpful, and in other use cases changing static values might be troublesome when handling concurrent invocations without proper locking, in general it’s perfectly fine to change static values.
I agree that it’s perfectly fine to change the static values, and I apologize to @flowplan if that was what was taken from my comment. I’ve just seen too many people have a coding error or having something screwed up because the usage of a static variable either wasn’t followed properly or they did something else that ended up screwing up that value because of something else in their code like the always possible simple error caused by bad programming or misspelling something.