There seems to be the usual confusion here between a HEX representation of a value and the decimal representation of the same value
Where are you seeing RX= 7B FF 2C FF 2C FF FF 7D and how is it stored ?
There seems to be the usual confusion here between a HEX representation of a value and the decimal representation of the same value
Where are you seeing RX= 7B FF 2C FF 2C FF FF 7D and how is it stored ?
// 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}
I get this message in (RecvMsg->inData[i]);
The payload is generated and comes from Sigfox backend.
I can put any data value in there as long as its 8 bytes in HEX (only for test, ok?)
I have no idea what you are trying to say
If what you get is the HEX representation of 8 bytes of data then you are receiving 16 characters (2 per byte). If, however, you are receiving 8 bytes of data then you are receiving 8 bytes
How many bytes do you receive ?
When are you going to post the full sketch ?
when I worked with Sigfox the maximum uplink was 12bytes and downlink 8 bytes
longer messages had to be transmitted as a sequences of 12 bytes and the number was limited
my Sigfox antenna is dead at the moment so cannot test anything
Sorry guys for delay...
So my apologies for not being clear here.
The server (Sigfox-backend) sends to me an 8-byte string. Only that.
The processing performed by the library code returns to my main routine the message RX=7B FF 2C FF 2C FF FF 7D. This is true because if I execute the line Serial.print = (RecvMsg->inData[i]); I will get on the serial monitor the message RX=7B FF 2C FF 2C FF FF 7D.
So what I did:
I created a String named buffTrans;
I loaded this String with the value of (RecvMsg->inData[i]);
And I tried to use the substring function to remove from String buffTrans the three values that interest me: HazardZone, AlarmAck and Time to TX.
So I think if I can transform the value given by a true String (which is in the proper envelope {"RX=7B FF 2C FF 2C FF FF 7D"}) then the substring routines will work just fine....
if the library returns a String of the form "RX=7B FF 2C FF 2C FF FF 7D" you could parse it so
void setup() {
Serial.begin(115200);
String RX="RX=7B FF 2C FF 2C FF FF 7D";
int d[8]={0};
sscanf(RX.c_str(),"RX=%2x%2x%2x%2x%2x%2x%2x%2x",&d[0],&d[1],&d[2],&d[3],&d[4],&d[5],&d[6],&d[7]);
for(int i=0;i<8;i++) {
Serial.print(d[i],HEX);
Serial.print(' ');
}
}
void loop() {}
you can then pick out which elements of the array d[] you require, e.g. a run gives
7B FF 2C FF 2C FF FF 7D
Thank you Horace.
In reality the library just returns RX=7B FF 2C FF 2C FF FF 7D without the quotes.
Furthermore, the data that interests to me is in the position where the value is 0xFF and 0xFF FF only.
the other String values are ASCII of:
{ 0x7B
} 0x7D
and comma 0x2C
Those data don't be used.
What does this string look like when the final message after the library is RX=7B FF 2C FF 2C FF FF 7D and is it actually a string ?
I'm not sure I understood your question, but the message is as shown in the picture.
It is the 8 byte string that I was asking about. The one that you mentioned in an earlier reply
Can you please post an example of it ?
In Sigfox backend I manually put the values 7BFF2CFF2CFFFF7D and the library routine returns me RX= 7B FF 2C FF 2C FF FF 7D
that's just it.
If I try to treat this data as a String, the substring function doesn't work.
However, if I can encapsulate this data with {" data "} the substring function works.
I was wondering if it would be possible to use concat() in this case...
What happens if you treat it as a C style string (lowercase s) ?
Hi UKHeliBob,
well if I understand your suggestion then it doesn't work.
Thanks.
Actually I think the whole question boils down to: how to put the " mark at the beginning and at the end of the String
Has the OP looked into the Arduino Sigfox library for the Arduino MKRFOX1200 to see how they receive thingies and adapt to the MCU being used?
I think that you're barking up the wrong tree.
Please tell us what the type of inData is. Is it a String (capital S), a character array or a byte array. If it's not a String (capital S), substring will never work.
typedef struct _recvMsg{
int len;
char* inData;
} recvMsg;