RF-Bridge-EFM8BB1 icon indicating copy to clipboard operation
RF-Bridge-EFM8BB1 copied to clipboard

B1 to B0 helping tool

Open gerardovf opened this issue 6 years ago • 94 comments

After learning how bit bucket works from here https://github.com/Portisch/RF-Bridge-EFM8BB1/issues/23 I decided to prepare a python script to help calculate the right 'B0' message to send using 'RfRaw' command in Tasmota from the received 'B1' sniffing message (rename file from 'BitBucketConverter.txt' to 'BitBucketConverter.py'.

BitBucketConverter.txt Do not use this version, it's too old already!

In the command line give the 'B1' message string and the retries value (in decimal): i.e. BitBucketConverter.py "AA B1 04 07EB 0157 00FD 3EBC 010101010101101001010101101010100103 55" 20

Command Line : "AA B1 04 07EB 0157 00FD 3EBC 010101010101101001010101101010100103 55" 20 'RfRaw AAB01C041407EB015700FD3EBC01010101010110100101010110101010010355'

gerardovf avatar Sep 05 '18 14:09 gerardovf

Great work!

I was stumped trying to get the B1 / B0 working till I tried this - got my device to work at last with this firmware!

Many thanks for this - could be something to add to the wiki.

peterchs avatar Sep 06 '18 21:09 peterchs

Thanks @peteakalad

I've included it here: Sonoff RF Bridge 433

gerardovf avatar Sep 07 '18 09:09 gerardovf

https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-RF-Bridge-433#raw-sniffing-procedure

gerardovf avatar Sep 09 '18 16:09 gerardovf

May you can include a "nibble" to readable hex number convert!?

Example by this data: https://github.com/Portisch/RF-Bridge-EFM8BB1/issues/26#issue-353911232

AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55

bucket 0: 05E6 bucket 1: 016C bucket 2: 02D1 bucket 3: 12D4

A sync is normally first high than low. In the sniffed data the last nibble should be always the snyc start (bucket 3): 012122121211212211212121221121212121212121212122112121212121212211212122112121221 3 After a high snyc pulse a low time is following. This nibble is the first in the data (bucket 0): 0 121221212112122112121212211212121212121212121221121212121212122112121221121212213

So the real data is: sync: 30, data: 12122121211212211212121221121212121212121212122112121212121212211212122112121221

each 12 or 21 is one bit. The string length of 12122121211212211212121221121212121212121212122112121212121212211212122112121221 is 80 chars. This 80 chars divided by 2 is the amount of bits: 40

Now the convert to hex numbers: bucket 2 is the long pulse, bucket 1 the short. The data is normally starting with a high pulse.

bucket series: 12 Means short high, long low: so I guest a logical 0

bucket series: 21 Means long high, short low: so I guest a logical 1

Converted data:

12122121211212211212121221121212121212121212122112121212121212211212122112121221
0 0 1 1 1 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 1

Convert this binary data to hex: 0x3908010111

For sure this is only working for bit orientated protocols. Like with your data it isn't working: AA B1 04 07F0 0128 00F2 3822 010101010101101001010101101010100103 55

Sync: 30, data: 1010101010110100101010110101010010 bit 0: 10 bit 1: 01

1010101010110100101010110101010010
0 0 0 0 0 ? 1 ? 0 0 0 ? 1 1 1 ? 0

11 or 00 isn't defined...

Portisch avatar Sep 10 '18 08:09 Portisch

All right! Let's start with your proposal:

Command Line : "AA B1 04 07EB 0157 00FD 3EBC 010101010101101001010101101010100103 55" 20

Bucket 0: 07EB (2027)

Bucket 1: 0157 (343)

Bucket 2: 00FD (253)

Bucket 3: 3EBC (16060)

0 01 01 01 01 01 01 10 10 01 01 01 01 10 10 10 10 01 3

'RfRaw AAB00B041407EB015700FD3EBC0155'

Command Line : "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55" 20

Bucket 0: 05E6 (1510)

Bucket 1: 016C (364)

Bucket 2: 02D1 (721)

Bucket 3: 12D4 (4820)

0 01 21 22 12 12 11 21 22 11 21 21 21 22 11 21 21 21 21 21 21 21 21 21 22 11 21 21 21 21 21 21 22 11 21 21 22 11 21 21 22 3

'RfRaw AAB00B041405E6016C02D112D42255'

gerardovf avatar Sep 10 '18 10:09 gerardovf

Not correct, the first nibble is the second part of the sync - not data. The sniffing is searching for the longest bucket. After the longest bucket ocurre again the data recording is starting including the low part of the sync.

So not: 0 01 01 01 01 01 01 10 10 01 01 01 01 10 10 10 10 01 3

It is: 30 10 10 10 10 10 11 01 00 10 10 10 11 01 01 01 00 10

That are 4 "bits": 01, 10, 11 and 00 May here is the answer: A bit of theory

The reason why I am asking is because if you have the data in hex you can use the command 0xA8. Also this data can be used to define new protocols in the RF_Protocols.h

AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55

30   12 12 21 21 21 12 12 21 12 12 12 12 21 12 12 12 12 12 12 12 12 12 12 21 12 12 12 12 12 12 12 21 12 12 12 21 12 12 12 21
sync 0  0  1  1  1  0  0  1  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0  0  1  0  0  0  1
hex 3908010111

The data for command 0xA8 will be: SYNC_HIGH: bucket 3: 12D4 SYNC_LOW: bucket 0: 05E6 BIT_HIGH_TIME: bucket 2: 02D1 BIT_HIGH_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 2: 0x42 (66%) BIT_LOW_TIME: bucket 1: 016C BIT_LOW_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 1: 0x21 (33%) BIT_COUNT + SYNC_BIT_COUNT: 0x28 (40, SYNC_BIT_COUNT = 0) Data: 3908010111

AA A8 xx 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55 Protocol is 0x7F (unknown), Len xx is counting bytes: 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 == 0x11

AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55

Maybe a printout of the statistic of the sniffed data would also be usefull to check if this protocol is already defined. Like in this example it is protocol 0x02 (ROHRMOTOR24).

Portisch avatar Sep 10 '18 11:09 Portisch

Quick and dirty. I miss how to get the 'SYNC_BIT_COUNT' value (I used '0')

Command Line : "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55" 20

'RfRaw AAB033041405E6016C02D112D4012122121211212211212121221121212121212121212122112121212121212211212122112121221355'

Sync: 30    Data: 12 12 21 21 21 12 12 21 12 12 12 12 21 12 12 12 12 12 12 12 12 12 12 21 12 12 12 12 12 12 12 21 12 12 12 21 12 12 12 21 
Sync               0  0  1  1  1  0  0  1  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0  0  1  0  0  0  1  
Hex: 3908010111

The data for command 0xA8 will be:
SYNC_HIGH: bucket 3: 12D4
SYNC_LOW: bucket 0: 05E6
BIT_HIGH_TIME: bucket 2: 02D1
BIT_HIGH_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 2: 0x42 (66%)
BIT_LOW_TIME: bucket 1: 016C
BIT_LOW_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 1: 0x21 (33%)
BIT_COUNT + SYNC_BIT_COUNT: 0x28 (40, SYNC_BIT_COUNT = 0)
Data: 3908010111
7F12D405E602D142016C21283908010111
Protocol is 0x7F (unknown), Len xx is counting bytes: '7F 12D4 05E6 02D1 42 016C 21 28 3908010111' == 0x11

'AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55'

gerardovf avatar Sep 10 '18 15:09 gerardovf

The sync bit count is protocol defined. Default 0!? Maybe it can be defined if the bit count MOD 8 != 0.

Like the WS_1200 protocol. 7 sync bits and 64 data bits. The sum is 71 bits: 71 mod 8 = 7.

Portisch avatar Sep 10 '18 17:09 Portisch

Quick and dirty. I miss how to get the 'SYNC_BIT_COUNT' value (I used '0')

Command Line : "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55" 20

'RfRaw AAB033041405E6016C02D112D4012122121211212211212121221121212121212121212122112121212121212211212122112121221355'

Sync: 30    Data: 12 12 21 21 21 12 12 21 12 12 12 12 21 12 12 12 12 12 12 12 12 12 12 21 12 12 12 12 12 12 12 21 12 12 12 21 12 12 12 21 
Sync               0  0  1  1  1  0  0  1  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0  0  1  0  0  0  1  
Hex: 3908010111

The data for command 0xA8 will be:
SYNC_HIGH: bucket 3: 12D4
SYNC_LOW: bucket 0: 05E6
BIT_HIGH_TIME: bucket 2: 02D1
BIT_HIGH_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 2: 0x42 (66%)
BIT_LOW_TIME: bucket 1: 016C
BIT_LOW_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 1: 0x21 (33%)
BIT_COUNT + SYNC_BIT_COUNT: 0x28 (40, SYNC_BIT_COUNT = 0)
Data: 3908010111
7F12D405E602D142016C21283908010111
Protocol is 0x7F (unknown), Len xx is counting bytes: '7F 12D4 05E6 02D1 42 016C 21 28 3908010111' == 0x11

'AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55'

gerardovf avatar Sep 11 '18 07:09 gerardovf

This program needs at least one parameter (i.e. "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55")
Second parameter can be the number of repetitions (i.e. "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55" 20)
Default repetitions value is 20 (hex 14)

Next versions should be more 'user friendly'. Maybe a '-v' (verbose) option in the command line...

BitBucketConverter.txt Do not use this version, it's too old already!

gerardovf avatar Sep 11 '18 07:09 gerardovf

BitBucketConverter.py Do not use this version, it's too old already!

Usage: BitBucketConverter.py [options]

Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -i INPUT, --input=INPUT
                        input 'B1' string
  -r REPEAT, --repeat=REPEAT
                        number of times to repeat
  -d, --debug           show debug info
  -v, --verbose         show more detailed info
None
-------------------------------------------------
Command Line : -i "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55"

'RfRaw AAB033041405E6016C02D112D4012122121211212211212121221121212121212121212122112121212121212211212122112121221355'

'AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55'
-------------------------------------------------
Command Line : -v -i "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55"
Repeat: 20

'RfRaw AAB033041405E6016C02D112D4012122121211212211212121221121212121212121212122112121212121212211212122112121221355'

'AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55'
-------------------------------------------------
Command Line : -d -v -i "AA B1 04 05E6 016C 02D1 12D4 0121221212112122112121212211212121212121212121221121212121212122112121221121212213 55"
Repeat: 20

'RfRaw AAB033041405E6016C02D112D4012122121211212211212121221121212121212121212122112121212121212211212122112121221355'

Sync: 30    Data: 12 12 21 21 21 12 12 21 12 12 12 12 21 12 12 12 12 12 12 12 12 12 12 21 12 12 12 12 12 12 12 21 12 12 12 21 12 12 12 21 
Sync               0  0  1  1  1  0  0  1  0  0  0  0  1  0  0  0  0  0  0  0  0  0  0  1  0  0  0  0  0  0  0  1  0  0  0  1  0  0  0  1  
Hex: 3908010111

The data for command 0xA8 will be:
SYNC_HIGH: bucket 3: 12D4
SYNC_LOW: bucket 0: 05E6
BIT_HIGH_TIME: bucket 2: 02D1
BIT_HIGH_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 2: 0x42 (33%)
BIT_LOW_TIME: bucket 1: 016C
BIT_LOW_DUTY: (100% / (bucket 2 + bucket 1)) * bucket 1: 0x21 (33%)
BIT_COUNT + SYNC_BIT_COUNT: 0x28 (40, SYNC_BIT_COUNT = 0)
Data: 3908010111
7F12D405E602D142016C21283908010111
Protocol is 0x7F (unknown), Len xx is counting bytes: '7F 12D4 05E6 02D1 42 016C 21 28 3908010111' == 0x11

'AA A8 11 7F 12D4 05E6 02D1 42 016C 21 28 3908010111 55'

gerardovf avatar Sep 11 '18 14:09 gerardovf

I'd suggest that you fork the portisch RF-bridge git repository and add the python script there in order to get it properly revisioned

ErikAndren avatar Sep 11 '18 17:09 ErikAndren

Thank you - nice tool! :) some suggestions:

  • Remove the '...' around the RfRaw command
  • Allow directly copying things like: 18:30:23 MQT: /sonoff/bridge/RESULT = {"RfRaw":{"Data":"AA B1 05 02FD 0E48 14CF 05E6 503C 000000030102010103010103010101010101010104 55"}} (It would speed up copy and past from the console)
  • Send directly the command to a web interface, similar to curl 'http://10.0.0.201/ax?c2=191&c1=RfRaw%20AA%20A8%200B%207F%200102%2002C6%2017E8%2042%200C12%2021%200%20%2055' (Ok I'm using the ESP firmware from tasmoka)
  • Have a "direct input interface", it means something where I can just "copy commands" and get the result (no need to "start the command").

Greate job :)

gabrielklein avatar Sep 11 '18 19:09 gabrielklein

@gabrielklein Can you try if this is working and if you miss something else?

BitBucketConverter.py Do not use this version, it's too old already!

The script will keep asking for a string until you give an empty input. I love your approach for a tool that makes all the work. I just copied the idea from "decode-status.py" here tools (@arendst, @ascillato2)

@Portisch would you mind putting this tool in your repository? I don't feel like creating a fork for such a simple script as @ErikAndren suggested!

gerardovf avatar Sep 12 '18 11:09 gerardovf

It's great :+1:

I've just added a try - catch

        try:
           strInput = getInputStr()
           if (len(strInput) > 0):
               main(strInput, options.repeat)
           else:
               break
        except:
          print "Unexpected error:", sys.exc_info()[0]

I receive an error due to json decoding (as it's not json when it's coming back).

It's makes things really easy! You record events and just copy the messages in your tool to test if you can reproduce something.

What would be even more amazing is to respect the timing between messages - but you cannot do that with your script as you only have time in seconds :)

Thank you as it really simplify our life trying to replay what we receive!!


Concerning the point of ErikAndren, you fork the project, modify your script, and then do a "pull request" - but you will spend lot of energy if you are not used to GIT - but it's great to learn if you want to participate a bit more in opensource projects!

gabrielklein avatar Sep 12 '18 12:09 gabrielklein

@gerardovf You can create a gist instead, see https://gist.github.com A link to it can be added to the README here.

mcspr avatar Sep 12 '18 13:09 mcspr

@gerardovf You can create a gist instead, see https://gist.github.com A link to it can be added to the README here.

This looks like a good way

Portisch avatar Sep 12 '18 13:09 Portisch

I'm trying to use python3

https://gist.github.com/gerardovf/15109405e8a53dd075bbe650d70fafc6

gerardovf avatar Sep 12 '18 17:09 gerardovf

319914226746a5736e83049ef66b59b22b32d334

Portisch avatar Sep 17 '18 10:09 Portisch

@gerardovf THX Tool workes great!!

Jason2866 avatar Sep 20 '18 10:09 Jason2866

@Jason2866 Thanks! It's just something I thought I needed for myself. If you find some improvements could be made just ask. Anyway, the whole merit must be given to @Portisch, his code is working flawlessly.

gerardovf avatar Sep 20 '18 10:09 gerardovf

Sorry I am confused. neither with the "outdated" or the new phyton3 version (which have the same dates in the header anyway) I get a B1 string only an A8 command? Also in contraction to the description I have to enter the complete MQTT string "{"RfRaw":{"Data":"AA B1 06 03A1 ......" rather than the data string alone ("AA B1 06 03A1 ....") to get a result. Looking at code thats obvious as the script is searching for the "Data:" Keyword. Can you please clarify whether I using the script who is described on this site?

Thanks!

haegar33 avatar Oct 03 '18 10:10 haegar33

@haegar33 I can understand your confusion. This is a 'work in progress' tool :-) Please try to start the python3 version with '-d -v' options in the command line (use verbose and debug). I'm trying to make the tool more user friendly but I need feedback. You can also try this version BitBucketConverter181002.txt

gerardovf avatar Oct 03 '18 10:10 gerardovf

That version does not work for me. I btw also only get an A8 code. Trying to get my Flamingo Sockets with its remote to work (FA500R). I get a bunch of different B1 codes and I think without your tool I won't be able to figure it out.

ciB89 avatar Oct 03 '18 12:10 ciB89

@ciB89 Please try to start the python3 version with '-d -v' options in the command line (use verbose and debug). The new version (BitBucketConverter181002.txt) should also work with python2 (it's just that you won't be able to send the http command -using the '-e' option-)

gerardovf avatar Oct 03 '18 12:10 gerardovf

The new version(181002) has a syntax error in line 258 (missing the brackets for print()) - and it returns the error 'Unexpected error: <class 'NameError'>'

ciB89 avatar Oct 03 '18 12:10 ciB89

I guess you have to make a decision whether to go with Python 2 or 3. For example "raw_input" does not exist in V3. Also some loops in your code will crash as V3 is more sensitive to type conversion. Example:

for i in range(0, iLength/2)) needs: for i in range(0, int(iLength/2))

to be valid Python3 code. Actually I would prefer a much simpler V2 version without the sendCommand stuff (needing some modules I don't have..)

haegar33 avatar Oct 03 '18 12:10 haegar33

@haegar33 I agree with you! Currently I'm testing it in python2.

@ciB89 would you mind to test the script in python2?

gerardovf avatar Oct 03 '18 12:10 gerardovf

@gerardovf My vote goes to Python2 too.

Jason2866 avatar Oct 03 '18 12:10 Jason2866

@gerardovf I'll get back to it later, only had a few minutes, have to get back to work. Thanks for the help so far

ciB89 avatar Oct 03 '18 12:10 ciB89