Does anyone have an idea that could help me please.
The Arduino receives a message that is available in the buffTans variable, for example: RX=7B FF 2C FF 2C FF FF 7D. I need to get the three values sent, which in this case are FF, FF, FF FF. As I said, I used the substring function, but the result was not what I expected.
void getDLMsg(){ // Sigfox Downlink Payload ************************************
recvMsg *RecvMsg;
int result;
RecvMsg = (recvMsg *)malloc(sizeof(recvMsg));
result = Isigfox->getdownlinkMsg(RecvMsg);
for (int i=0; i<RecvMsg->len; i++){
// Downlink string example RX=7B FF 2C FF 2C FF FF 7D
buffTrans = (RecvMsg->inData[i]); // { FF , FF , FF FF }
Serial.print (buffTrans); // {HazardZone, Alarm ack, Time to TX}
}
parseData();
Serial.println ("");
free(RecvMsg);
}
//------------------------------------------------------------------------------------------------------------------
void parseData() { // split the data into its parts
//
BlinkLED();
pinMode(redLED, OUTPUT);
//
hazardZone = buffTrans.substring (6,8);
alAck = buffTrans.substring (12,14);
tTTx = buffTrans.substring (18,23);
Serial.print ("Hazard Zone: "); // Only for test. The data will be used in another part of the code
Serial.println (hazardZone);
Serial.print ("Alarm Ack: ");
Serial.println (alAck);
Serial.print ("Time to TX: ");
Serial.println (tTTx);
}
Are you sure that the message has string format "7B FF 2C FF 2C FF FF 7D" and not the bytes with this binary values?
From what program do you receive it?
Hello b707,
Thanks for the answer.
Actually the data is not marked ". It might work if I include the marks ", but I still don't know how I would do that.
This data comes from the Sigfox Backend and I capture the data by the payload sent through the Sigfox IoT module
That's the problem. I'm not sure what kind of data is it. See below:
buffTrans = (RecvMsg->inData[i]);
The message comes by expression (RecvMsg->inData[i])
I only load the content in a String created by me buffTrans, but I don't do any processing on this String.
buckfast bee keeper, I understand. I believe that if I can create a real String with this data it will work.
When I say true String, I mean using the " marks between the data.
exactly GoForSmoke... that's my difficulty.
the Payload looks like a String, but when I treat it as a String, it doesn't behave like one.
I believe that if I take the data RX=7B FF 2C FF 2C FF FF 7D and manage to transform it into {"RX=7B FF 2C FF 2C FF FF 7D"} I solve my problem
if (SigFox.parsePacket()) {
Serial.println("Response from server:");
while (SigFox.available()) {
Serial.print(" 0x");
Serial.print(SigFox.read(), HEX);
}
looks like SigFox.read() returns a byte which I printed in HEX format, e.g. function prototype
Result checks if the received message is ok. If it is correct, the "serial monitor" prints OK on the screen. So the whole message on the screen will be:
OK
RX=7B FF 2C FF 2C FF FF 7D
Actually the Sigfox backend sends the 8 byte downlink only. In HEX.
However, we have two libraries involved in the process: #include <WISOL.h>
and also
Isigfox *Isigfox = new WISOL();
I'm trying to simplify the process by using the substring function to pull out the data I really need.