sui77 / rc-switch

Arduino lib to operate 433/315Mhz devices like power outlet sockets.
1.91k stars 659 forks source link

Problem sending sync bits with EMW100T protocol #325

Closed Skapells closed 4 years ago

Skapells commented 4 years ago

Hello!

To start off I'd like to let you know that I'm not that experienced in the RF area, dibbledabbles in a lot of things in my spare time, software and (very recently) also RF, being some of them. With that said, some patience may be required with me and if I'm out of line, let me know.

I have an old COTECH 433Mhz mains IO controller that I've been trying to reverse-engineer using a cheap transmitter, receiver and an Arduino. I've been using Audacity and URH to decode the messages sent from the controller and figure out the protocol.

I then found this: https://github.com/sui77/rc-switch/issues/222

Following the procedure that Frownbreaker did;

  • { 605, { 1, 28 }, { 1, 2 }, { 1, 1 }, false }
  • "1 sync bit + 52" =53 bits, "You need up+down for each bit." = 2 state changes per bit = Low to high, high to low = 2* 53 =106 #define RCSWITCH_MAX_CHANGES 106
  • "(calculate to accommodate 64 bits)" void send(unsigned long long code, unsigned int length);Guaranteed by the C standard (ISO C99) to be at least 64 bits✓
  • void RCSwitch::send(unsigned long long code, unsigned int length) {
  • unsigned long long getReceivedValue();
  • static unsigned long long nReceivedValue;This was line 142 in RCSwitch.h not line 170
  • unsigned long long RCSwitch::getReceivedValue() {
  • unsigned long long code = 0;
  • unsigned long long RCSwitch::nReceivedValue = 0;

I got the receiving part to work.

{ 605, { 1, 28 }, { 1, 2 }, { 1, 1 }, false } // protocol 12

Output from Arduino:

Received 4317329419299498 / 52bit Protocol: 12 //1 OFF
Received 4317329419299498 / 52bit Protocol: 12 //1 OFF
Received 4317329419299498 / 52bit Protocol: 12 //1 OFF
Received 4317329419299413 / 52bit Protocol: 12 //1 ON
Received 4317329419299413 / 52bit Protocol: 12 //1 ON
Received 4317329419299413 / 52bit Protocol: 12 //1 ON

Real happy result! I then proceeded to the sending test:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
  Serial.begin(9600);
   // Transmitter is connected to Arduino Pin #10  
  mySwitch.enableTransmit(10); 
}

void loop() {
  // Test code for new protocol 7
  mySwitch.setPulseLength(605);
  mySwitch.setProtocol(12);
  mySwitch.setRepeatTransmit(7);
  mySwitch.send(4317329419299498 ,52); //OFF
  delay(20000);
  mySwitch.send(4317329419299413 ,52); //ON
}

This is where my understanding of what the crap I'm doing starts to plummet D: I have kinda got the point that this library does not really support more that 32-bit but then again we've seen it work with the modifications that frownbreaker did?

With the above code I'm able to transmit and the signals I'm receiving seem correct when I compare them to the ones I get from the controller;

Waveform comparison

Using URH I applied the correct linecoding;

OFF SIGNAL Cont OFF

ON SIGNAL Cont ON

To the problem: I do not seem to be transmitting the { 1, 28 } sync bits, because this is what my signals look like when sending them from the Arduino:

Full send from arduino

I tried sending the same send but with another protocol just to try something;

Protocol test

From here I'm not quite sure where to proceed, maybe I need to look at other ways of sending? Guessing this has something to do with the 32bit limit even though some steps have been taken to try sending larger?

If you've read this far, thanks and if I need to post more data let me know.

I should note: I am not able to send and receive with only Arduino since I only have one. I do however posses a RPI but it's collecting dust somewhere at the moment.

edit: grammar

Skapells commented 4 years ago

Oh and here is the HIGH and LOW from the recordings:

101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100101001010010100101001 //artificial OFF
101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100101001010010100101001 //artificial OFF
101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100101001010010100101001 //artificial OFF

101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100100101001010010100101 //artificial ON
101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100100101001010010100101 //artificial ON
101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100100101001010010100101 //artificial ON
101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100101001010010100101001 //artificial ON (last sequence sent is same as OFF?)

101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100101001010010100101001 //controller OFF

101010101001010010100101010010100100101001010100101001001010010101001001010100101001010010010101001010010100100101001010010100101 //controller ON

There seems to be some inconsistencies here also, the last sequence in the cluster of "ONs" is the bits corresponding to "OFF"..

Skapells commented 4 years ago

New information: I started fooling around with the pulselenght since I remembered that my pulses weren't exactly the same as the protocol would suggest: { 605, { 1, 28 }, { 1, 2 }, { 1, 1 }, false }

Yesterday I averaged the high and lows to something like:

HIGH = 520 microseconds
short LOW = 733 microseconds
long LOW = 1335 microseconds

I changed the protocol to:

{ 520, { 1,  33 }, {  1,  2 }, {  1,  1 }, false }

Aaaand.. The result were the same, no syncbit zeroes..

All of a sudden the COTECH receiver started going ON OFF ON OFF etc..

So I captured the signal and it was still transmitting without the syncbits but it seems to read the signal as it should either way.

The question still stands though, why am I not getting the sync-bits to transmit as expected?