ameltech / sme-le51-868-library

This is a library for SmartEverything LE51-868 SIGFOX module.
3 stars 10 forks source link

CRC issue sending data to Telit LE51-868S #1

Closed SimonTernoir closed 8 years ago

SimonTernoir commented 8 years ago

Hi,

I've found an interesting issue when giving specific values to the SigFox.print function. This issue can be illustrated with the SmeIoT Library - DataModeEu Example.

In this example, if you choose to send "H", instead of "Hello":

char helloMsg[2]= {'H', 'e'};

You will get an error _SFX_DATA_ACKKO due to _TELIT_SFX_SERIAL_TIMEOUTERROR. :confused:

But, if you try this message:

char helloMsg[3]= {'H', 'e', 'l'};

Everything is fine! :hushed: And if you try:

char helloMsg[1]= {0xFF};

Everything is fine again! :open_mouth:

So, let's have a look to the real message sent through in SigFox.print in SmeSFX::sfxSendData (file SmeSFX.cpp):

According to the documentation, The frame format is: | Header | Length | Type | Sequence Number | Payload | CRC2 | CRC1 | Tailer |

We define Sequence Number = 25 for below examples.

For {'H', 'e'} the frame is: | A5 | 2 | 1 | 25 | 48 | 65 | D5 | 0 | 5A | -> Error For {'H', 'e', 'l'} the frame is: | A5 | 3 | 1 | 25 | 48 | 65 | 6C | 42 | 1 | 5A | -> Success For {0xFF} the frame is: | A5 | 1 | 1 | 25 | FF | 26 | 1 | 5A | -> Success

So, if you haven't guessed the problem yet, let's try other values : For {0xD9} the frame is: | A5 | 1 | 1 | 25 | D9 | 0 | 1 | 5A | -> Error For {0xDA} the frame is: | A5 | 1 | 1 | 25 | DA | 1 | 1 | 5A | -> Success For {0xFF, 0xD9} the frame is: | A5 | 2 | 1 | 25 | FF | D9 | 0 | 2 | 5A | -> Error For {0xFF, 0xDA} the frame is: | A5 | 2 | 1 | 25 | FF | DA | 1 | 2 | 5A | -> Success

So, When at least one of the two CRC bytes is 0, an error occurs (The CRC is the sum of all bytes except header and tailer).

Thus, an error will occurred when (hex addition): (Length + Type + Sequence Number) < 256 OR (Length + Type + Sequence Number) %256 = 0

Do you think you could fix it in the SigFox module or this is an issue from the Telit chip?

Thank you!

cc @connesc for the help

smkkHw commented 8 years ago

Hi Simon.

This is a known bug of this library. I have the possible fix, but never had chance to test it.

The problem is due by the use of the UART.print()

function to send message to Telit chip. If U like to test for Us I'm adding the changes here in an unofficial way , and it could be pushed after.

I'm in a middle of development of 2 new features, so I cannot use the more correct approach to share the SW

Rename it in SmeSFX.cpp and copy on the library directory Be sure to do out of any IDE open because otherwise it will not be used since there is a SmeSFX.o object file in the temp directory used by Arduino.

SmeSFX.txt

Mik

SimonTernoir commented 8 years ago

Hi Mik,

.write(buf, len) seems better than .print(buf) to avoid such issues. I've tested it on several cases and everything's fine.

In your HelloWorld example, you shouldn't use strlen as payload length parameter. With the payload helloMsg[2]= {0x0,0x0} you'll get: strlen((char*)helloMsg) == 0

Thanks.

smkkHw commented 8 years ago

Thank For Your test.

I will release the changes together with the latest features.

smkkHw commented 8 years ago

Resolved in v2.0.0