Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial protocol between EFM8 & ESP #3605

Closed
1 task done
Portisch opened this issue Aug 27, 2018 · 5 comments
Closed
1 task done

Serial protocol between EFM8 & ESP #3605

Portisch opened this issue Aug 27, 2018 · 5 comments
Labels
awaiting feedback Action - Waiting for response or more information bug Type - Confirmated Bug fixed Result - The work on the issue has ended

Comments

@Portisch
Copy link
Contributor

Describe the bug
The firmware just look for the data 0x55 (sync end) on receiving RF data from the EFM8 chip.
The len have to be also checked when receiving data from the EFM8. Otherwise it is possible to loose data:

#3419 (comment)
or:
Portisch/RF-Bridge-EFM8BB1#26 (comment)

Also, make sure these boxes are checked [x] before submitting your issue - Thank you!

  • Searched the problem in issues and in the wiki

To Reproduce
Just receive RF data from the EFM8 with 0x55 in the data. The data will be truncated.

Expected behavior
The len of the expected data to be received should be checked.

@ascillato2 ascillato2 added the bug Type - Confirmated Bug label Aug 27, 2018
@arendst
Copy link
Owner

arendst commented Aug 27, 2018

Did you check the latest development version?

Pls provide status 0 output as requested when the issues was raised.

I know I made some changes regarding this 0x55 so I need to know what version you experience this problem with.

@arendst arendst added the awaiting feedback Action - Waiting for response or more information label Aug 27, 2018
@Portisch
Copy link
Contributor Author

Portisch commented Aug 27, 2018

No, I didn't test your firmware. I just got issues reported by sniffing unknown RF data when the data is including 0x55.

In your function: SonoffBridgeSerialInput

    if (sonoff_bridge_receive_raw_flag) {
      if (!serial_in_byte_counter) {
        serial_in_buffer[serial_in_byte_counter++] = 0xAA;
      }
      serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
      if (0x55 == serial_in_byte) {  // 0x55 - End of text
        SonoffBridgeReceivedRaw();
        sonoff_bridge_receive_flag = 0;
        return 1;
      }
    }

This will break the receive. You have to check for each command the expected len to be received. If the len got received the next (last) byte have to be the sync end 0x55.
For sure it is the bad thing that the original EFM8 firmware do not have such len byte in the protocol...

Like AAA60602390801015555 will result to: AAA606023908010155

@arendst
Copy link
Owner

arendst commented Aug 27, 2018

So in short:

  • Original firmware only uses commands A0 - A5 without len byte and can be decoded until first 0x55 end-of-text
  • Portisch supports original commands A0 - A5 also without the len byte
  • In addition Portisch supports commands from A6 up where the byte after A6 will contain the len byte excluding the 0x55 end-of-text

Is this correct?

@Portisch
Copy link
Contributor Author

Data from EFM8 -> ESP:
0xA0: len = 0
0xA2: len = 0
0xA3: len = 9
0xA4: len = 9

Alternative commands:
0xA6: len = data[2]
0xAA: len = 0
0xAB: len = data[2]
0xB1: do not have a len byte

The len is every time data[len position + 1] ... data[n-1]

@arendst
Copy link
Owner

arendst commented Aug 27, 2018

Ok.

So only A6 and AB contain a len byte I have to check and once received the next byte would be 0x55?

arendst added a commit that referenced this issue Aug 27, 2018
Fix Sonoff Bridge data reception when using Portisch EFM8 firmware and in data buffer length (#3605)
@arendst arendst added the fixed Result - The work on the issue has ended label Aug 27, 2018
curzon01 pushed a commit to curzon01/Tasmota that referenced this issue Sep 7, 2018
Fix Sonoff Bridge data reception when using Portisch EFM8 firmware and in data buffer length (arendst#3605)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Action - Waiting for response or more information bug Type - Confirmated Bug fixed Result - The work on the issue has ended
Projects
None yet
Development

No branches or pull requests

3 participants