rcSwitch: Trouble decoding protocol

So I have a remote and I'm trying to replicate the signal with an arduino. I read the raw data using the rcSwitch scanner tool and plotted them in the online tool. The results of 3 signals are:

Raw data #1 (Click to expand)

632,328,632,332,628,336,628,332,308,652,632,328,312,652,632,328,312,648,632,324,640,324,316,648,636,320,640,324,636,324,320,644,316,644,316,644,640,316,644,320,644,316,644,320,640,320,648,316,644,316,644,316,324,644,640,316,644,316,328,632,328,636,644,316,324,640,644,308,328,636,24244,320,620,340,300,660,304,656,624,340,300,656,308,652,308,652,632,332,628,332,628,336,628,336,304,652,632,332,308,652,632,328,308,652,632,328,632,328,316,648,632,324,640,320,644,320,316,648,316,644,316,644,640,316,644,320,644,316,644,320,640,320,644,320,640,324,640,320,320,644,636,320,644,316,324,644,320,636,644,316,324,636,648,308,328,636,24240,324,620,340,300,660,300,660,624,336,304,656,304,656,308,652,628,336,628,332,628,336,624,336,308,652,628,332,312,652,628,332,312,648,628,332,636,324,316,648,632,328,632,328,636,324,316,648,312,648,316,644,636,320,644,320,644,316,644,320,640,320,640,324,640,320,640,324,316,644,640,320,644,316,324,640,324,640,640,316,324,636,648,308,328,636,24240,324,616,348,296,660,300,660,624,336,304,660,300,656,308,652,628,332,632,332,628,332,628,336,304,656,628,336,308,648,632,332,308,652,628,332,632,328,312,652,632,324,636,328,632,332,312,648,312,648,312,648,640,316,644,320,640,320,644,320,640,320,640,324,640,320,640,320,324,644,636,320,640,320,324,640,320,640,644,312,324,640,644,312,324,636,24244,320,620,344,296,664,296,660,624,340,300,660,304,652,308,656,628,332,628,336,624,336,628,336,304,656,628,332,308,652,628,332,312,648,632,328,632,332,312,648,632,328,636,328,632,328,316,644,316,644,316,648,636,320,640,320,640,324,640,320,640,324,640,320,640,324,640,320,320,644,640,320,640,320,320,644,320,640,644,312,328,640,640,312,324,640,24240,320,620,344,296,664,296,660,624,340,304,656,300,660,304,656,624,336,628,336,624,336,628,332,308,652,632,332,308,652,628,332,312,648,632,328,632,332,308,652,632,328,636,324,636,324,316,648,316,644,312,648,636,320,644,320,640,320,640,320,648,316,640,324,640,320,640,324,320,644,644,312,644,316,324,644,316,640,640,320,324,640,644,308,324,636

Raw data #2 (Click to expand)

640,320,644,320,640,320,644,316,324,640,640,320,320,640,644,316,328,632,644,316,648,316,324,636,648,312,648,312,648,316,328,632,328,632,328,632,652,308,332,632,652,308,332,628,652,308,656,308,652,308,332,628,656,304,336,628,336,624,336,624,656,304,340,620,660,300,340,620,340,620,24256,308,632,332,308,652,308,652,632,324,316,644,316,644,320,644,636,324,640,320,640,324,640,320,320,640,640,320,324,640,640,320,320,640,644,316,644,316,328,632,648,312,648,316,652,308,328,632,328,632,332,628,652,312,328,632,652,308,332,628,656,304,656,308,656,304,332,632,652,308,332,632,332,624,336,624,656,304,340,624,656,300,344,616,340,620,24256,308,628,336,308,656,304,652,632,328,312,648,312,648,316,644,636,324,640,320,640,324,636,324,320,640,640,320,324,640,640,320,320,640,644,316,644,320,320,640,644,316,644,316,648,316,324,636,324,636,324,636,648,308,332,632,652,308,336,628,652,308,652,308,652,312,332,628,652,308,336,628,332,624,336,628,656,304,336,624,660,300,340,616,344,620,24252,312,628,332,312,652,304,656,628,332,308,652,312,644,316,644,636,324,640,320,640,324,640,320,320,644,640,320,320,640,644,316,324,636,644,316,648,312,324,640,644,316,648,312,648,316,324,636,328,632,328,632,648,312,332,628,656,304,332,632,652,308,652,308,652,312,328,636,648,308,332,632,332,628,332,628,656,300,340,624,660,300,336,624,336,620,24256,308,632,332,308,652,308,652,632,328,312,648,312,648,316,644,636,324,640,320,640,320,640,320,324,640,640,320,320,644,640,320,320,640,640,320,644,316,324,640,640,320,644,316,648,312,328,636,324,636,324,632,656,304,332,632,648,312,332,628,652,308,656,304,656,308,332,632,652,308,332,628,336,624,332,628,656,304,336,628,656,304,336,620,340,620,24256,308,632,332,304,656,308,652,632,328,312,648,312,648,312,648,636,324,640,320,640,324,640,320,320,640,644,316,324,636,644,320,320,640,644,316,644,316,324,636,644,316,648,316,648,312,328,636,324,636,324,636,648,308,332,632,648,312,332,628,652,308,656,308,652,308,336,628,652,308,332,628,332,628,336,624,656,304,340,624,656,304,336,620,340,616

Raw data #3 (Click to expand)

640,320,320,640,644,316,324,636,644,316,648,316,320,640,644,316,644,316,648,312,328,636,328,632,328,632,328,632,328,628,656,304,656,308,332,628,656,308,652,308,652,308,336,628,332,628,332,628,336,624,656,304,336,624,340,620,340,616,340,620,24252,308,632,332,308,656,308,648,632,328,312,652,312,640,320,640,644,316,644,316,644,320,640,320,320,644,640,320,324,636,640,320,324,636,644,316,648,312,328,636,648,312,648,312,652,312,324,636,324,632,332,628,332,632,332,628,652,308,652,308,332,632,652,308,652,308,656,304,336,628,332,628,332,628,336,620,660,300,344,620,340,620,340,616,344,616,24256,304,632,336,304,660,304,652,628,328,316,648,312,648,312,648,636,320,640,324,640,316,644,320,320,644,640,316,324,640,640,316,328,636,644,316,644,316,324,636,648,312,648,316,648,312,332,632,328,632,328,632,328,628,332,628,656,304,656,308,336,624,656,304,656,308,656,304,336,628,332,628,332,624,336,624,660,300,344,620,336,624,340,616,340,616,24260,304,632,332,308,656,304,652,632,324,316,652,312,644,316,644,636,320,640,324,640,320,640,320,324,640,644,316,320,640,648,312,324,636,644,316,648,312,328,636,644,316,648,312,648,316,324,636,328,632,328,632,328,632,328,628,656,304,656,308,332,628,656,304,656,304,660,304,336,624,336,628,332,624,340,620,660,300,344,620,340,620,344,612,340,620,24252,308,632,328,312,656,308,652,628,324,316,652,312,644,316,644,640,316,644,320,640,320,644,320,320,640,644,316,324,636,644,316,324,636,644,316,648,316,324,636,648,312,648,312,648,316,324,636,328,632,328,632,332,628,332,628,652,308,656,304,336,624,660,304,656,304,656,308,332,628,336,624,336,624,336,624,660,300,344,620,336,620,340,620,340,616,55480,692,276,688,276,688,280,684,284,680,284,680,288,676,288,672,292,676,292,672,296,668,296,664,304,660,304,660,308,656,308,644,5140,660,308,656,312,652,312,652,312,652,316,648,316,648,320,644,320,644,324,640,328,640,324,640,332,632,328,636,332,632,332,624,5160,640,328,636,328,636,328,636,332,636,328,636,332,632,336,628,336,628,340,624,344,624,340,624,344,624,340,624,340,624,344

Plotted they look like this (in the same order):

Now following the steps on Add_New_Remote_Part_1 · sui77/rc-switch Wiki · GitHub I came up with this protocol: { 320, { 76, 1 }, { 1, 2 }, { 2, 1 }, true }
An inverse protocol with a total of 42 bits (+1 sync bit) with 3 steps per bit.

  • 320 = Pulse length
  • 76x Low and 1 High = Sync bit
  • Low High High = 0
  • Low Low High = 1

I note the last 17 bit change so it must be some sort of rolling code (for now its not a problem, I just want to decode this protocol and be able to send it, even though its a rolling code). Is 17 a weird number and shouldnt it be 16 bit or maybe 24 if the other 7 bits are not changing that much?

When I add this protocol (and some minor variations of it) to the rcSwitch.cpp file. I still won't receive any correct data with the correct protocol. When I try to custom send data with this protocol and scan it with the scanner code. I get some weird data. When I send exactly the same binaries. The first part always seems to fail and the sync bit is way less then ~24256 miliseconds. Here is some data sent and its plot compared to the original remote data sent.

Raw data send by arduino (Click to expand)

696,280,700,280,384,600,380,588,392,584,708,268,708,268,708,272,704,268,712,264,708,268,704,272,704,272,376,596,704,268,708,264,384,592,380,592,696,268,388,584,708,264,388,580,11708,300,372,620,368,620,368,616,368,616,376,608,376,612,376,608,376,608,376,608,380,604,704,280,380,604,692,288,384,600,700,280,388,596,700,276,704,280,384,596,700,272,708,268,716,264,396,588,388,588,392,584,712,260,712,268,708,272,708,264,712,264,708,268,708,264,712,268,384,588,700,272,704,264,388,588,384,592,700,264,392,576,700,276,388,580,11704,312,356,632,360,624,364,620,368,624,364,620,368,612,372,624,360,616,372,616,368,612,688,292,380,608,688,292,376,608,692,280,388,596,700,280,704,276,388,592,708,272,704,272,708,272,384,596,380,600,380,596,704,272,704,272,704,276,700,272,700,276,700,272,696,280,696,280,380,596,696,272,700,264,396,580,388,580,712,260,392,580,712,256,400,576,11712,300,368,616,372,616,372,616,372,620,368,616,368,616,372,612,376,608,380,608,376,604,696,280,388,592,704,276,396,592,704,272,396,588,704,280,704,272,388,596,708,268,712,268,708,272,384,596,384,596,384,592,700,272,704,272,708,272,700,276,700,272,708,268,704,268,708,260,396,584,712,256,708,264,396,580,392,580,708,264,384,588,712,256,388,580,11708,304,372,620,364,624,368,620,364,616,392,588,400,584,384,604,384,596,400,584,396,588,716,260,412,576,720,260,412,572,720,264,396,584,720,260,720,260,408,568,736,244,736,244,728,252,408,568,412,568,412,564,724,252,728,248,728,248,732,240,736,236,740,236,736,240,728,252,408,564,728,240,724,252,400,572,404,572,724,240,412,564,724,244,408,560,11720,296,380,608,380,600,392,592,392,604,380,600,392,596,388,596,392,596,392,584,400,588,712,268,396,592,712,268,392,592,708,272,392,592,704,276,708,272,392,588,712,268,708,268,712,268,396,588,388,588,388,580,720,256,724,252,716,264,716,256,712,264,716,260,716,260,712,264,388,584,708,264,712,260,388,588,388,584,700,264,400,580,704,260,396,576,11708,300,376,612,376,608,380,608,384,604,376,612,372,608,384,604,380,604,380,604,380,604,704,280,388

So comparing these two. The last part of the code seems right. And I guess I do see the sync bit aswell. However the sync time is way off, almost half the time. Now the first 10 bits are off aswell. Why is that? I'm pretty sure I send the correct binary (100100011110101011011100011111111011001010).

What am I doing wrong?

1 Like

Okay I fixed it myself. I spitted to the C++ code of the rcSwitch lib and found out that it uses long types which are 32 bit. This is why my 10 bits (42-10=32) didnt came through. I altered the library to support 64 bit using long long types and now it works.

I also found out the issue on the bit sync. It cannot completely finish its delay because the arduino's delayMicroseconds method has a maximum of 16383

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.