wguerlich / RFSwitch

Interface TI CC1101 based transceivers with cloud based services. Runs on Raspberry Pi and other boards with a SPI interface.
MIT License
1 stars 0 forks source link

How to Decode the Packets? #1

Open thmang82 opened 6 years ago

thmang82 commented 6 years ago

Hello,

first, the Reception of Packets is working, thanks for the code!!! I attached a CC1101 Module directly to a PI Zero via SPI and this was the only code on the Internet that enabled to receive Packets from Intertechno Compatible Remotes and Wall-Switches. Big Thumbs up.

However, I intend to replace the CUL in my FHEM installation with this. But the packet payload that RFSwitch reports is completely different to what CUL / FHEM Report. That would not be an issue per se, simple Payload match would be enough for my purpose, but the 3-4 packet receptions per press so slightly differ in payload on RFSwitch :-( I suspect the payload is Rising/Falling Flanks of the Signal or something similar, but I did not get the system behind it yet ...

Can somebody, or the author of this nice litte Go Code, help me with this?

Here is what I found out by testing:

All Data from same button pressed once on an Intertechno ITT-1500 Remote.

Serial Log of CUL (CC1101@Adruino) with X07 Debug Out Command:

p 9 336 1680 336 336 1 8 0 5A5969595AA69655 p 9 240 1232 240 240 1 8 0 5A5969595AA69655 p 9 288 1440 288 288 1 8 0 5A5969595AA69655 p 9 256 1248 256 256 1 8 0 5A5969595AA69655

RFSwitch Output (enabled a debug LogLine in Code):

Buf: (690) [2 1b 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 3 3 3 2 d 2 3 2 d 3 d 2 3 2 3 2 e 2 3 2 e 2 d 2 3 2 d 2 4 2 3 2 d 2 3 3 d 2 3 2 d 3 d 2 3 2 3 2 e 2 3 2 d 2 4 2 d 2 d 2 4 2 d 2 3 2 e 2 3 2 d 2 3 2 3 3 d 2 d 2 4 2 d 2 3 2 3 2 e 2 3 2 d 2 e 2 3 2 3 2 d 3 3 2 d 2 3 2 e 2 3 2 d 2] Buf: (692) [2 1b 2 3 2 e 2 3 2 d 2 d 2 4 2 d 2 3 3 3 2 d 2 3 2 e 2 d 2 3 2 4 2 d 2 3 3 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 d 3 3 2 d 2 d 2 4 2 3 2 d 3 3 2 d 2 3 2 e 2 d 2 3 2 e 2 3 2 d 2 4 2 d 2 3 2 4 2 d 2 d 2 4 2 d 2 3 2 3 3 d 2 3 2 d 3 d 2 3 2 3 3 d 2 3 2 d 3 3 2 d 2 3 2 e 2] Buf: (691) [3 1a 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 3 3 2 d 2 e 2 3 2 3 2 e 2 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 2 3 2 e 2 3 2 d 2 e 2 3 2 3 2 e 2 3 2 d 3 3 2 d 2 d 2 4 2 d 2 3 2 e 2 3 2 d 2 4 2 3 2 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 e 2 d 2 3 2 3 2 e 2 3 2 d 2 3 3 d 2 3 2 d 2] Buf: (691) [2 1b 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 2 4 2 d 2 d 2 4 2 3 2 d 2 4 2 d 2 d 2 3 3 d 2 3 2 3 2 e 2 3 2 d 2 3 3 d 2 d 2 3 3 3 2 d 2 4 2 d 2 3 2 d 2 e 2 3 2 d 2 3 3 d 2 3 2 d 2 4 2 3 2 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 e 2 d 2 3 2 3 2 e 2 3 2 d 2 4 2 d 2 3 2 e 2]

And lastly the FHEM Decoding of the 5A5969595AA69655 String from CUL:

2018.10.14 13:29:45 5: CUL/RAW: /i5A5969595AA69655FC 2018.10.14 13:29:45 4: CUL_Parse: CUL1 i5A5969595AA69655FC -76 2018.10.14 13:29:45 5: CUL1: dispatch i5a5969595aa69655 2018.10.14 13:29:45 4: CUL1 IT: message "i5a5969595aa69655" (17) 2018.10.14 13:29:45 4: CUL1 ITv3: bin message "0101101001011001011010010101100101011010101001101001011001010101" (64) 2018.10.14 13:29:45 4: CUL1 IT: msgcode "00110010011000100011110110010000" (32) bin = 0101101001011001011010010101100101011010101001101001011001010101 2018.10.14 13:29:45 3: CUL1 IT: IT_V3_13207798 off->on

wguerlich commented 6 years ago

Hello,

good to hear the code looks useful to you... It's actually been in use by me for a few years now and has never crashed on me. I use it in my private home control installation for both getting sensor data and also for controlling a number of switches.

I prefer doing the encoding/decoding in Javascript... so I'm attaching the code that does the actual encoding/decoding of the IT command... the first function is for decoding the classic Intertechno senders (those with coding wheels) and the 2nd for protocol version 3 for the newer devices with the code learning switches...

However sending codes with the V3 protocol is not working reliable... it depends on more precise timing which does not cause issues for receiving but for sending it does... Adapting the Go code to the new V3 protocol (sending mode) should work, but the internal CC1101 buffer is to small to hold an entire frame... so it would take some more work to do the sending in continous mode... it's something i'm working on but for the ESPxx platform... I've also tried to match the new timing for the v3 protocol in receiving mode, but discovered that the much higher sampling rate will significantly decrease the sensitivity...

Best regards, Wolfram

so here goes, i hope you can figure it out:

=======================

function val2code(v) { var s = "" for (var b = 1; b < 16; b <<= 1) { s += (v & b) ? "f" : "0" } return s }

function code2val(c) { var n = 0 for (var i = 0; i < c.length; i++) { var a = c.charAt(i) if (a == "f") n += (1 << i) else if (a != "0") return -1; } return n }

function sendCodeV1(params) { var code = params.code.toUpperCase() var houseCode = code.charCodeAt(0) - "A".charCodeAt(0) var deviceCode = parseInt(code.substring(1, 3), 10)

var funcCode = code.substring(3, 4) switch (funcCode) { case "1": funcCode = "0fff" break case "G": funcCode = "ffff" break default: funcCode = "0ff0" }

var seq = val2code(houseCode) + val2code(deviceCode - 1) + funcCode

var p = [] for (var i = 0; i < seq.length; i++) { var c = seq[i] switch (c) { case "0": p.push(1) p.push(3) p.push(1) p.push(3) break; case "1": p.push(3) p.push(1) p.push(3) p.push(1) break; case "f": p.push(1) p.push(3) p.push(3) p.push(1) break; } }

p.push(1)

var m = { freq: 433.92, repeat: 20, pause: 25, pulsewidth: 360, payload: p }

}

function sendCodeV3(params) { var code = params.code var houseCode = parseInt(code.substring(0, 7), 16) var deviceCode = parseInt(code.substring(7, 8), 16) var funcCode = parseInt(code.substring(8, 9), 16)

p = []

function out(val, len) { var b = 1 << (len - 1) while (b) { if (val & b) { p.push(2) p.push(9) p.push(2) p.push(2) } else { p.push(2) p.push(2) p.push(2) p.push(9) }

b >>= 1 } }

p.push(2) p.push(20) out(houseCode,26) out(funcCode,2) out(deviceCode,4) p.push(2) //p.push(1) //p[p.length-1]+=2

var l=0

for(var i=0;i<p.length;i++) { l+=p[i] }

var m = { freq: 433.92, repeat: 15, pause: 180, pulsewidth: 137, payload: p, len:l }

return m

}

function decodeIntertechno(frame) { var s = "" for (var i = 0; i < frame.length; i++) { var n = frame[i] if (n >= 2 && n <= 6) s += "1" else if (n >= 9 && n <= 13) s += "3" else s += "x" }

var c = "" for (i = 0; i < s.length; i += 4) { var a = s.substring(i, Math.min(s.length, i + 4)) switch (a) { case "1313": c += "0"; break; case "3131": c += "1"; break; case "1331": c += "f"; break; case "1": c += "s"; break; default: c += "x" } }

if (c.length != 13 || c.substring(12) != "s") return c;

var itc = "" //house code var a = code2val(c.substring(0, 4)) if (a < 0) return c; itc += "ABCDEFGHIJKLMNOP".charAt(a)

//device code var a = code2val(c.substring(4, 8)) if (a < 0) return c; itc += "01020304050607080910111213141516".substring(a 2, a 2 + 2)

//function code if (c.substring(8, 12) == "0ff0") { itc += "0" } else if (c.substring(8, 12) == "0fff") { itc += "1" } else if (c.substring(8, 12) == "ffff") { itc += "G" } else return c

return "IT-" + itc }

/*****/

function decodeIntertechnoV3(frame) { var s = "" for (var i = 0; i < frame.length; i++) { var n = frame[i] if (n >= 2 && n <= 5) s += "1" else if (n >= 11 && n <= 16) s += "5" else if (n >= 24 && n <= 30) s += "A" else s += "x" }

if (s.substring(0, 2) != "1A") return "nosync"

var c = "" for (i = 2; i < s.length; i += 4) { var a = s.substring(i, Math.min(s.length, i + 4)) switch (a) { case "1115": c += "0"; break; case "1511": c += "1"; break; case "1111": c += "D"; break; case "1": c += "s"; break; default: c += "x" } }

if (c.length != 33 || c.substring(32) != "s") return c;

var itc = parseInt(c.substring(0, 26), 2).toString(16) itc = "0000000".substring(itc.length) + itc itc += parseInt(c.substring(28, 32), 2).toString(16) itc += c.substring(27, 28)

return "IT3-" + itc }

========================

On Sun, Oct 14, 2018 at 1:54 PM thmang82 notifications@github.com wrote:

Hello,

first, the Reception of Packets is working, thanks for the code!!! I attached a CC1101 Module directly to a PI Zero via SPI and this was the only code on the Internet that enabled to receive Packets from Intertechno Compatible Remotes and Wall-Switches. Big Thumbs up.

However, I intend to replace the CUL in my FHEM installation with this. But the packet payload that RFSwitch reports is completely different to what CUL / FHEM Report. That would not be an issue per se, simple Payload match would be enough for my purpose, but the 3-4 packet receptions per press so slightly differ in payload on RFSwitch :-( I suspect the payload is Rising/Falling Flanks of the Signal or something similar, but I did not get the system behind it yet ...

Can somebody, or the author of this nice litte Go Code, help me with this?

Here is what I found out by testing:

All Data from same button pressed once on an Intertechno ITT-1500 Remote.

Serial Log of CUL (CC1101@Adruino) with X07 Debug Out Command:

p 9 336 1680 336 336 1 8 0 5A5969595AA69655 p 9 240 1232 240 240 1 8 0 5A5969595AA69655 p 9 288 1440 288 288 1 8 0 5A5969595AA69655 p 9 256 1248 256 256 1 8 0 5A5969595AA69655

RFSwitch Output (enabled a debug LogLine in Code):

Buf: (690) [2 1b 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 3 3 3 2 d 2 3 2 d 3 d 2 3 2 3 2 e 2 3 2 e 2 d 2 3 2 d 2 4 2 3 2 d 2 3 3 d 2 3 2 d 3 d 2 3 2 3 2 e 2 3 2 d 2 4 2 d 2 d 2 4 2 d 2 3 2 e 2 3 2 d 2 3 2 3 3 d 2 d 2 4 2 d 2 3 2 3 2 e 2 3 2 d 2 e 2 3 2 3 2 d 3 3 2 d 2 3 2 e 2 3 2 d 2] Buf: (692) [2 1b 2 3 2 e 2 3 2 d 2 d 2 4 2 d 2 3 3 3 2 d 2 3 2 e 2 d 2 3 2 4 2 d 2 3 3 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 d 3 3 2 d 2 d 2 4 2 3 2 d 3 3 2 d 2 3 2 e 2 d 2 3 2 e 2 3 2 d 2 4 2 d 2 3 2 4 2 d 2 d 2 4 2 d 2 3 2 3 3 d 2 3 2 d 3 d 2 3 2 3 3 d 2 3 2 d 3 3 2 d 2 3 2 e 2] Buf: (691) [3 1a 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 3 3 2 d 2 e 2 3 2 3 2 e 2 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 2 3 2 e 2 3 2 d 2 e 2 3 2 3 2 e 2 3 2 d 3 3 2 d 2 d 2 4 2 d 2 3 2 e 2 3 2 d 2 4 2 3 2 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 e 2 d 2 3 2 3 2 e 2 3 2 d 2 3 3 d 2 3 2 d 2] Buf: (691) [2 1b 2 3 2 d 3 3 2 d 2 e 2 3 2 d 2 4 2 3 2 d 2 4 2 d 2 d 2 4 2 3 2 d 2 4 2 d 2 d 2 3 3 d 2 3 2 3 2 e 2 3 2 d 2 3 3 d 2 d 2 3 3 3 2 d 2 4 2 d 2 3 2 d 2 e 2 3 2 d 2 3 3 d 2 3 2 d 2 4 2 3 2 d 2 d 2 4 2 d 2 3 2 4 2 d 2 3 2 e 2 d 2 3 2 3 2 e 2 3 2 d 2 4 2 d 2 3 2 e 2]

And lastly the FHEM Decoding of the 5A5969595AA69655 String from CUL:

2018.10.14 13:29:45 5: CUL/RAW: /i5A5969595AA69655FC 2018.10.14 13:29:45 4: CUL_Parse: CUL1 i5A5969595AA69655FC -76 2018.10.14 13:29:45 5: CUL1: dispatch i5a5969595aa69655 2018.10.14 13:29:45 4: CUL1 IT: message "i5a5969595aa69655" (17) 2018.10.14 13:29:45 4: CUL1 ITv3: bin message "0101101001011001011010010101100101011010101001101001011001010101" (64) 2018.10.14 13:29:45 4: CUL1 IT: msgcode "00110010011000100011110110010000" (32) bin = 0101101001011001011010010101100101011010101001101001011001010101 2018.10.14 13:29:45 3: CUL1 IT: IT_V3_13207798 off->on

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wguerlich/RFSwitch/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AF_WDdowhuXkVoFzwl0Qv7ns9F8QrKRkks5ukyX-gaJpZM4XbF72 .

thmang82 commented 6 years ago

Thanks a lot for the code! The inside that the code is running reliably since 3 years is also nice to hear ;-) I only need to receive signals. Therefore I have no issue with the sending problem for V3.

How did you interconnect the Go Code and the Javascript? Do you send the frames from Go via a Rest Call to a small Node Webserver? Or do you start the Go code inside Node via the ChildProcess Library (spawn)?

wguerlich commented 6 years ago

Well the Go code on the raspberry sends the data to a cloud server, where i do all the further processing. I use a server side framework which my company is developing to run the Javascript code... we don't use NodeJS but Rhino which compiles the JS to Java and then runs in inside Google Appengine. But NodeJS should work just fine... In newer project I actually use the node-red framework with sensors based on ESPxx talking to it via MQTT...

So, the server protocol is probably not ideal for integration. MQTT might be a much better choice, also with Go.

On Mon, Oct 15, 2018 at 10:01 PM thmang82 notifications@github.com wrote:

Thanks a lot for the code! The inside that the code is running reliably since 3 years is also nice to hear ;-) I only need to receive signals. Therefore I have no issue with the sending problem for V3.

How did you interconnect the Go Code and the Javascript? Do you send the frames from Go via a Rest Call to a small Node Webserver? Or do you start the Go code inside Node via the ChildProcess Library (spawn)?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wguerlich/RFSwitch/issues/1#issuecomment-429992651, or mute the thread https://github.com/notifications/unsubscribe-auth/AF_WDQSslHD7dHixR77WLPP3z_Q5D4-Kks5ulOmGgaJpZM4XbF72 .

thmang82 commented 6 years ago

Thanks for the Infos. I wrote a small node server that starts the go code, reads the std in, decodes the messages, and publishes the decoded messages to MQTT: https://github.com/thmang82/RF_InterTechno