sehaas / yfmos

Control your Somfy receivers with a Sonoff RF Bridge
MIT License
9 stars 5 forks source link

RF bridge doesn't accept every 16th-32th B0 string #11

Open rplevka opened 4 years ago

rplevka commented 4 years ago

I was trying to nail down the issue, where after several commands, the RF bridge stopped transmitting the messages and just beeped. So i focused on yfmos as it might compose the messages wrong.

and what i found out is, whenever I start clean - and transmit exactly 16 messages, the 17th-32th messages don't work. Funny enough, after trying to transmit 16 another messages where none of them came through, it started to work for another 16 messages again.

Isn't there a bug in the way you compose the message (strLen maybe)?

rplevka commented 4 years ago

this 16-16 rule applies on using the same command. whenever you change the command within the 16 requests (e.g. from DOWN to UP), this 'doom count' seems to be reset.

Here's some output from running yfmos in bash loops - so you can visually compare the Frames and raw data:

# THIS WORKS
$ for i in {1..16}; do ./yfmos.py run --profile obyvka --host 192.168.1.202 --command DOWN; sleep 0.4; done
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xB  !    0x0160     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3C 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332222223333222233332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xA  !    0x0161     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3C 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332222333333332222222333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x9  !    0x0162     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333222333323333222332332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x8  !    0x0163     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333222332333333222333322333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xF  !    0x0164     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333322333322333322333333332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xE  !    0x0165     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333322333333333333223333222333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xD  !    0x0166     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333223323323333223322332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xC  !    0x0167     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333223322333333223323322333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x3  !    0x0168     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323333222333323333233332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x2  !    0x0169     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323333233333333233332222333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x1  !    0x016A     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332333333332333323333332332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x0  !    0x016B     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332333333233333323333333322333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x7  !    0x016C     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323323322333323323333332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x6  !    0x016D     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323323333333333233233222333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x5  !    0x016E     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333233223323333233222332333322233233223333332332332332222233233233234 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x4  !    0x016F     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333233222333333233223322333322233233223333332332332332222233233233234 55

# AND THIS DOESN'T

(yfmos) [ w1pko@localhost:master:yfmos ]$ for i in {1..16}; do ./yfmos.py run --profile obyvka --host 192.168.1.202 --command DOWN; sleep 0.4; done
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xA  !    0x0170     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332222333333332222222332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xB  !    0x0171     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3D 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332222223333222233332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x8  !    0x0172     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333222332333333222333322332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x9  !    0x0173     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333222333323333222332332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xE  !    0x0174     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333322333333333333223333222332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xF  !    0x0175     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333322333322333322333333332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xC  !    0x0176     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333223322333333223323322332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0xD  !    0x0177     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333223323323333223322332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x2  !    0x0178     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323333233333333233332222332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x3  !    0x0179     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323333222333323333233332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x0  !    0x017A     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 40 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332333333233333323333333322332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x1  !    0x017B     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 40 05 01 0A28 1324 050A 0280 7F58 000000000000001222233333323333332333333332333323333332332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x6  !    0x017C     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323323333333333233233222332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x7  !    0x017D     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3F 05 01 0A28 1324 050A 0280 7F58 0000000000000012222333333233333323323322333323323333332332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x4  !    0x017E     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333233222333333233223322332332223333233233333322333322233332333322333334 55
Group       A       B       C       D       F               G                    
Byte:       0H      0L      1H      1L      2       3       4       5       6    
        +-------+-------+-------+-------+-------+-------+-------+-------+-------+
        !  0xA  + R-KEY ! C M D + C K S !  Rollingcode  ! Remote Handheld Addr. !
        !  0xA  +  0x1  !  0x4  +  0x5  !    0x017F     !       0xAABB03        !
        +-------+-------+-------+-------+MSB----+----LSB+LSB----+-------+----MSB+
RfRaw AA B0 3E 05 01 0A28 1324 050A 0280 7F58 00000000000000122223333332333333233223323333233222332332332223333233233333322333322233332333322333334 55
sehaas commented 4 years ago

I know the problem, that sometimes the RF bridge does not send the command but starts beeping and stops working. It happens randomly and I could not find a pattern like you describe.

It usually works by sending the exact same command again after rebooting the bridge. So maybe it is not really the problem of the last command, but more an invalid state caused by previous commands.

Do you have any suggestions, what could be wrong with the strlen?

rplevka commented 4 years ago

@sehaas - it is indeed a problem with the length of the string - whenever yfmos starts to generate the 'faulty' codes, the encoded payload is 1 character shorter then the declared length. I tried to re-send the same command with added an extra 0 to the front of the payload - rf bridge was happy to accept it and retransmit it. It's not the solution tho - somfy motor doesn't respond to that.

What i did for now is a workaround, which checks whether the length of the generated encrypted payload is an odd number - if it is, it doesn't transmit it, but increments the rolling code counter and tries again until it gets an even payload length (tl;dr it discards the invalid b0 strings). Absolutely not elegant but it works. I just hope the virtual remote won't end up out of sync with the somfy motor after some time (i don't know how the syncing works).

EDIT: regarding the issue you're describing - there were issues reported on some older version of Portisch firmware regarding rfraw mode being eventually switched off. That might be your case. there was some workaround suggested to make a rule to automatically turn it on on boot as well as turning in on in regular intervals. I'm using the latest release (af of today), so maybe that's why you can't spot the pattern i'm seeing.

21:49:51 CMD: rfraw 255
21:49:51 MQT: stat/tech/bridge/RESULT = {"RfRaw":"ON"}
21:49:51 MQT: tele/tech/bridge/RESULT = {"Time":"2020-04-12T21:49:51","RfRaw":{"Data":"AA0355"}}