Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement this but with rawdata #4

Closed
royfocker19 opened this issue Jun 22, 2019 · 26 comments
Closed

Implement this but with rawdata #4

royfocker19 opened this issue Jun 22, 2019 · 26 comments

Comments

@royfocker19
Copy link

Hi Maxim, quick question, what should I modify on your code to work with rawdata?
Also, do you know how could I implement codes for carrier AC found here? http://arduino.fisch.lu/index.php?menu=36&page=&portal=9
this is What I read for example when I turn on in 26 HEAT mode.

Decoded packet (size = 199):
4438 -4387 569 -1621 563 -537 562 -1627 566 -1621 567 -533 564 -534 565 -1621
565 -538 563 -535 565 -1625 567 -532 564 -534 563 -1623 567 -1620 567 -533
563 -1628 568 -1625 565 -536 563 -1625 569 -1618 532 -1656 561 -1626 564 -1624
557 -1632 532 -571 529 -1656 561 -539 556 -541 528 -570 561 -537 528 -570
558 -541 559 -1632 562 -1626 561 -538 562 -1628 562 -1625 564 -1622 562 -538
561 -538 561 -538 560 -538 561 -1629 563 -536 561 -537 560 -538 560 -1628
565 -1623 500 -5296 4434 -4377 568 -1624 563 -535 563 -1627 565 -1622 565 -534
564 -533 564 -1622 566 -536 563 -536 563 -1627 565 -533 565 -534 562 -1622
566 -1621 564 -536 563 -1628 565 -1628 565 -534 564 -1626 567 -1620 565 -1623
566 -1621 565 -1621 567 -1626 563 -535 565 -1620 565 -536 563 -535 562 -534
564 -535 563 -533 564 -536 563 -1628 567 -1621 565 -533 566 -1626 563 -1623
566 -1623 564 -534 563 -535 564 -536 564 -535 562 -1628 564 -534 564 -534
563 -535 562 -1626 566 -1624 500

@royfocker19
Copy link
Author

If I’m not wrong first value should be discarded (4438), signal is sent 2 times, separator would be -5296. Is that a correct way to start the analysis?

@maximkulkin
Copy link
Owner

Most IR protocols use encoding similar to NEC protocol: there is a preamble, there is a bit encoding with short mark and then either short or long silence, then there is a mark and long silence signaling end of packet. You just need to figure out all timings. From your example I would say that there is a 4400us carrier + 4400us silence, mark is ~565us mark followed by either 565us or 1625us silence; an finally - 5300us of silence at the end. Incorporate all those timings into a config, use code you mentioned above to encode AC state into sequence of bytes and then transmit them.

@maximkulkin
Copy link
Owner

As of raw data: it is fine for stateless devices like TV remotes (pressing same button generates same code), but for AC is kind of inconvenient as it has a lot of combinations of state and storing them all in raw is inconvenient and error prone.
But you can do that by replacing this line with ir_raw_send(pulses, sizeof(pulses) / sizeof(*pulses)); (assuming pulses is array of your raw pulse data)

@royfocker19
Copy link
Author

royfocker19 commented Jun 24, 2019 via email

@maximkulkin
Copy link
Owner

you mean already converted to ones and zeros?

Just take that numbers, put them into signed int array (e.g. pulses) and use ir_raw_send() to send them.

Well, 1) I haven't checked that it is the same bits, might be that this is part of a longer data packet; 2) if those two halves are the same, I think most likely you need only one half; 3) you might not need to worry about that if you plan to use raw signals: just hardcode whatever you read from remote and be done with it.

@royfocker19
Copy link
Author

royfocker19 commented Jun 24, 2019 via email

@maximkulkin
Copy link
Owner

maximkulkin commented Jun 25, 2019

My usual workflow is:

  1. Build a receiver on a protoboard (ESP + IR receiver).
  2. Flash an IR raw dumper, dump and examine some raw codes.
  3. Ensure that raw codes look like generic protocol (like NEC) and deduce generic protocol parameters (lengths of different pulses).
  4. Implement a generic protocol dumper and collect some decoded command samples (same way as raw_dumper, but instead of ir_decoder_t *raw_decoder = ir_raw_make_decoder(); you do following:)
ir_generic_config_t generic_config = {
    .header_mark = 4400,
    .header_space = -4400,

    .bit1_mark = 565,
    .bit1_space = -1625,

    .bit0_mark = 565,
    .bit0_space = -565,

    .footer_mark = 565,
    .footer_space = -5100,

    .tolerance = 20,
};

ir_decoder_t *decoder = ir_generic_make_decoder(&generic_config);
  1. Figure out what data and how is packed into commands.
  2. Implement a command encoder (and decoder, if needed)

@royfocker19
Copy link
Author

I make this, but can't get any code
#include <stdio.h>
#include <stdlib.h>
#include <esp/uart.h>
#include <FreeRTOS.h>
#include <task.h>

#include <ir/ir.h>
#include <ir/generic.h>

#define IR_RX_GPIO 12

static ir_generic_config_t generic_config = {
.header_mark = 4400,
.header_space = -4400,

.bit1_mark = 565,
.bit1_space = -1625,

.bit0_mark = 565,
.bit0_space = -565,

.footer_mark = 565,
.footer_space = -5100,

.tolerance = 20,

};
void ir_dump_task(void *arg) {
ir_rx_init(IR_RX_GPIO, 1024);
ir_decoder_t *generic_decoder = ir_generic_make_decoder(&generic_config);

uint8_t buffer[32];
while (1) {
    uint16_t size = sizeof(buffer);
    if (ir_recv(generic_decoder, 0, buffer, &size) <= 0)
        continue;

    printf("Decoded packet (size = %d):\n", size);
    for (int i=0; i < (size + 7) / 8; i++) {
        printf("0x%02x ", buffer[i]);
        if (i % 16 == 15)
            printf("\n");
    }

    if ((size + 7) % 128)
        printf("\n");
}

}

void user_init(void) {
uart_set_baud(0, 115200);

xTaskCreate(ir_dump_task, "IR dump", 2048, NULL, tskIDLE_PRIORITY, NULL);

}

@royfocker19
Copy link
Author

royfocker19 commented Jun 29, 2019

ok, make it read something with this code

#include <stdio.h>
#include <stdlib.h>
#include <esp/uart.h>
#include <FreeRTOS.h>
#include <task.h>

#include <ir/ir.h>
#include <ir/generic.h>

#define IR_RX_GPIO 12

static ir_generic_config_t generic_config = {
.header_mark = 4400,
.header_space = -4400,

.bit1_mark = 565,
.bit1_space = -1625,

.bit0_mark = 565,
.bit0_space = -565,

.footer_mark = 565,
.footer_space = -5100,

.tolerance = 20,
};
void ir_dump_task(void *arg) {
ir_rx_init(IR_RX_GPIO, 1024);
ir_decoder_t *generic_decoder = ir_generic_make_decoder(&generic_config);

uint8_t buffer[48];
while (1) {
uint16_t size = sizeof(buffer);
if (ir_recv(generic_decoder, 0, buffer, &size) <= 0)
continue;

printf("Decoded packet (size = %d):\n", size);
for (int i=0; i < (size + 7) / 8; i++) {
    printf("0x%02x ", buffer[i]);
    if (i % 16 == 15)
        printf("\n");
}

if ((size + 7) % 128)
    printf("\n");

}
}

void user_init(void) {
uart_set_baud(0, 115200);

xTaskCreate(ir_dump_task, "IR dump", 2048, NULL, tskIDLE_PRIORITY, NULL);
}

I use a 48 buffer, I think I should read everything with that size, right?

@royfocker19
Copy link
Author

I was able to read this
17
0x4d 0xb2 0xfd 0x02 0x00 0xff

18
0x4d 0xb2 0xfd 0x02 0x08 0xf7

19
0x4d 0xb2 0xfd 0x02 0x0c 0xf3

20
0x4d 0xb2 0xfd 0x02 0x04 0xfb

21
0x4d 0xb2 0xfd 0x02 0x06 0xf9

22
0x4d 0xb2 0xfd 0x02 0x0e 0xf1

23
0x4d 0xb2 0xfd 0x02 0x0a 0xf5

24
0x4d 0xb2 0xfd 0x02 0x02 0xfd

25
0x4d 0xb2 0xfd 0x02 0x03 0xfc

26
0x4d 0xb2 0xfd 0x02 0x0b 0xf4

27
0x4d 0xb2 0xfd 0x02 0x09 0xf6

28
0x4d 0xb2 0xfd 0x02 0x01 0xfe

29
0x4d 0xb2 0xfd 0x02 0x05 0xfa

30
0x4d 0xb2 0xfd 0x02 0x0d 0xf2

mode
auto
0x4d 0xb2 0xf8 0x07 0x1d 0xe2

mode
cool
0x4d 0xb2 0xfa 0x05 0x0d 0xf2

mode
dry
0x4d 0xb2 0xf8 0x07 0x2d 0xd2

mode
heat
0x4d 0xb2 0xfa 0x05 0x2d 0xd2

mode
fan
0x4d 0xb2 0xfa 0x05 0x27 0xd8

fan speed
0
0x4d 0xb2 0xfd 0x02 0x07 0xd8

fan speed
1
0x0d 0xb2 0xfd 0x02 0x07 0xd8

fan speed
2
0x4d 0xb2 0xfa 0x05 0x07 0xd8

fan speed
3
0x4d 0x12 0xfa 0x05 0x07 0xd8

swing
vert short
0x4d 0xb2 0xf0 0x0f 0x07 0xf8

swing
vert long
0x4d 0xb2 0xd6 0x29 0x07 0xf8

swing
hor short
0xad 0x52 0xaf 0x50 0x4d 0xb2

swing
hor long
0xad 0x52 0xaf 0x50 0x35 0xca

turbo
0xad 0x52 0xaf 0x50 0x45 0xba

sleep
0x05 0x52 0xaf 0x50 0x45 0xba
no sirve este codigo

sleep
0x4d 0xb2 0x07 0xf8 0xc0 0x3f

sleep off
0x4d 0xb2 0xfd 0x02 0x0d 0xf2

sleep on
0x4d 0xb2 0x07 0xf8 0xc0 0x3f

fresh
0xad 0x52 0xaf 0x50 0x95 0x6a

self clean
0xad 0x52 0xaf 0x50 0x55 0xaa

follow me
0x5d 0xa2 0x9a 0x65 0x4d 0xb2

follow me off
0x4d 0xb2 0x07 0xf8 0xc0 0x3f

led
0xad 0x52 0xaf 0x50 0xa5 0x5a

silence
0xad 0x52 0xaf 0x50 0x6d 0x92

silence off
0xad 0x52 0xaf 0x50 0xed 0x12

I cannot understand how the temperature is being coded. Also, it seems what I get is inverted from the raw data.

@maximkulkin
Copy link
Owner

Ok, first of all: some data you've presented look as outliers, I think you had either error copy-pasting them or there were errors cap[turing those sequences.

Then, the codes look like 6 byte sequence. I've decoded raw data manually and indeed it looks like they are repeated twice. Also, I've noticed that every odd byte is the inverse of corresponding even byte ( byte 1 is inverse of byte 0, byte 3 is inverse of byte 2, etc).

Then, I've started decoding temperature codes (as they are the easiest). Looks like the temperature is encoded by lower 4 bits of 4'th byte (or 3rd if you do not count inverses) and counts from 17 (and corresponding code is 0). Also it seems that they are big endian (most significant bits come first, although it might be the consequences of IR library reversing them). But, numbers do not come in sequence. I've reversed the bits and got sequence (0, 1, 3, 2, 6, 7, 5, 4, ...). Then I just googled that sequence and found out that this is a Gray code, a way to represent data that is more error prone in some cases.

Haven't looked into others as for decoding codes I need more data (repeated is even better) and don't want to spoil all the fun. Hope it will get you started.

@royfocker19
Copy link
Author

You were right about the temp. I found a library that works with my remote.
crankyoldgit/IRremoteESP8266#484
So do you think I can add accesories to have all the buttons available?

@maximkulkin
Copy link
Owner

Yes you can

@royfocker19
Copy link
Author

I'll work on it and let you know. Thanks for all your help.

@royfocker19
Copy link
Author

Hi Maxim, may I ask you for help on the decoder code? I don't understand how to include it on the dumper. It seems some part of the code is inverted. I read 0x4d 0xb2 for example and it should be b2 4d.

@maximkulkin
Copy link
Owner

What does it mean "it should be b2 4d" ? Who defines that? What's the problem of it being reverse as long as you can interpret and generate it properly?

@royfocker19
Copy link
Author

If I try to manually translate to binary the raw data I get that B2 4D on the prefix, for example. Thing is that I cannot get hex code that I can't tell has something to do with the original binary from the raw data. Maybe there is an error on the way I print the decoded signal.
Sorry, to bother you with so many questions

@maximkulkin
Copy link
Owner

That does not make any sense. I would imagine bits in numbers being reversed, not like whole bit sequences swapped. Of course if you want to encode integers, you need to pay attention to endianness.

This is all handwaving and to be more specific you have to provide real data (e.g. raw data)

@royfocker19
Copy link
Author

royfocker19 commented Aug 3, 2019

Hi Maxim, this is the raw data that I have for Power off for example:

Mesg Desc.: Power: Off
Raw Timing[199]:
   +  4406, -  4420,    +   566, -  1624,    +   562, -   538,    +   560, -  1630, 
   +   562, -  1624,    +   524, -   574,    +   560, -   536,    +   558, -  1628, 
   +   562, -   538,    +   560, -   540,    +   560, -  1630,    +   560, -   536, 
   +   562, -   536,    +   558, -  1626,    +   562, -  1626,    +   560, -   538, 
   +   560, -  1632,    +   562, -   538,    +   560, -  1624,    +   562, -  1624, 
   +   564, -  1626,    +   560, -  1626,    +   558, -   540,    +   560, -  1628, 
   +   560, -  1636,    +   520, -  1666,    +   558, -   542,    +   558, -   540, 
   +   560, -   536,    +   558, -   540,    +   558, -  1626,    +   560, -   540, 
   +   560, -   540,    +   558, -  1632,    +   564, -  1626,    +   562, -  1624, 
   +   562, -   536,    +   558, -   540,    +   558, -   538,    +   560, -   538, 
   +   558, -   540,    +   560, -   540,    +   560, -   538,    +   558, -   538, 
   +   558, -  1630,    +   560, -  1628,    +   560, -  1626,    +   562, -  1626, 
   +   560, -  1626,    +   544, -  5262,    +  4432, -  4380,    +   562, -  1626, 
   +   560, -   538,    +   556, -  1630,    +   562, -  1626,    +   560, -   538, 
   +   560, -   538,    +   558, -  1624,    +   560, -   540,    +   558, -   540, 
   +   558, -  1630,    +   560, -   538,    +   558, -   538,    +   558, -  1628, 
   +   560, -  1626,    +   560, -   538,    +   558, -  1632,    +   560, -   540, 
   +   558, -  1628,    +   558, -  1626,    +   560, -  1626,    +   560, -  1626, 
   +   562, -   538,    +   558, -  1630,    +   560, -  1628,    +   558, -  1634, 
   +   560, -   540,    +   558, -   540,    +   556, -   540,    +   556, -   540, 
   +   558, -  1628,    +   558, -   540,    +   556, -   546,    +   552, -  1634, 
   +   558, -  1632,    +   558, -  1628,    +   558, -   540,    +   558, -   538, 
   +   558, -   540,    +   558, -   540,    +   558, -   540,    +   560, -   540, 
   +   560, -   538,    +   560, -   538,    +   560, -  1630,    +   562, -  1626, 
   +   558, -  1626,    +   560, -  1626,    +   564, -  1626,    +   582

from my understanding this would be the data in binary, just reading everything in sequence.
101100100100110101111011100001001110000000011111

And this would be the info in HEX, b24d7b84e01f, right?
So data that I would care about could be B2 7B E0, because the other info is same but inverse, and all that code is repeated in this IR protocol, if the AC don-t receive it, it doesn't work.

I don't know how to make the decoder to read b24d7b84e01f, for that same information I get Decoded packet (size = 96):
b24d21def807a500a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5
a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5a5 using code

static ir_generic_config_t generic_config = {
    .header_mark = 4400,
    .header_space = -4400,

    .bit1_mark = 565,
    .bit1_space = -1625,

    .bit0_mark = 565,
    .bit0_space = -565,

    .footer_mark = 565,
    .footer_space = -5250,

    .tolerance = 45,
};

void ir_dump_task(void *arg) {
    ir_rx_init(IR_RX_GPIO, 1024);
    ir_decoder_t *generic_decoder = ir_generic_make_decoder(&generic_config);

    uint16_t buffer[48];
    while (1) {
        uint8_t size = sizeof(buffer);
        if (ir_recv(generic_decoder, 0, buffer, &size) <= 0)
            continue;

        printf("Decoded packet (size = %d):\n", size);
        for (int i=0; i < 24; i++) {
            printf("%lx", buffer[i]);
            if (i % 12 == 11)
                printf("\n");
        }

        if ((size + 7) % 128)
            printf("\n");
    }
}

void user_init(void) {
    uart_set_baud(0, 115200);

    xTaskCreate(ir_dump_task, "IR dump", 2048, NULL, tskIDLE_PRIORITY, NULL);
}

So I'm sure I'm doing something wrong there.
Sorry, I try to give as much details I can, one of them is that I'm not a very skilled programmer, I need to learn a lot, but I'm stuck here.
I would really appreciate anyones help/

@maximkulkin
Copy link
Owner

maximkulkin commented Aug 4, 2019

OMG, every time I get unformatted code, my eyes bleed.

OK, regarding your code:

    uint16_t buffer[48];
    while (1) {
        uint8_t size = sizeof(buffer);
        if (ir_recv(generic_decoder, 0, buffer, &size) <= 0)
            continue;
        // skip
    }

buffer should be and array of uint8_t (it's your command bytes), not uint16_t. Second and more important, in ir_recv() call you should pass size by value, not pointer, and get decoded size as result of the function. See original code.

Printing decoded data should take into account decoded size, not just do some fixed size packets:

for (int i=0; i < 24; i++) {
    printf("%lx", buffer[i]);
    if (i % 12 == 11)
        printf("\n");
}

And also this code is strange and useless: it prints newline unless size is 121

if ((size + 7) % 128)
    printf("\n");

Also, tolerance value of 45 (percent) is too high.

static ir_generic_config_t generic_config = {
    // skip

    .tolerance = 45,
};

@royfocker19
Copy link
Author

Ok, I tried, but with no luck, as I said, I don't understand how to modify the original code I'm using, the one one mention in the Readme.md @example receiving NEC-like command".

@maximkulkin
Copy link
Owner

Ok, that was my bad not updating all examples. Fixed. So, try to use the corrected example and see what happens.

@royfocker19
Copy link
Author

royfocker19 commented Aug 8, 2019

ok, so thesis what I get with the code example in the readme file.
Decoded packet (size = 6): 0x4d 0xb2 0xde 0x21 0x07 0xf8
using another library for Arduino the code that I have for the same command (off) is different and then if I send it works. I'll try to investigate it further.

@maximkulkin
Copy link
Owner

What code do you get on Arduino library? Have you tried sending this code (4d b2 de 21 07 f8) using this library?

@royfocker19
Copy link
Author

this is the info I get with IRremoteESP8266 library

Timestamp : 000284.884
Library : v2.6.3

Encoding : COOLIX
Code : B27BE0 (24 bits)
Mesg Desc.: Power: Off
Raw Timing[199]:

  • 4436, - 4386, + 568, - 1622, + 564, - 536, + 562, - 1628,
  • 564, - 1622, + 564, - 534, + 562, - 536, + 562, - 1624,
  • 564, - 536, + 564, - 536, + 564, - 1626, + 564, - 534,
  • 562, - 536, + 562, - 1624, + 564, - 1624, + 564, - 536,
  • 562, - 1630, + 564, - 538, + 562, - 1624, + 564, - 1624,
  • 562, - 1622, + 566, - 1622, + 566, - 534, + 562, - 1628,
  • 562, - 1626, + 566, - 1628, + 564, - 536, + 562, - 534,
  • 562, - 534, + 562, - 534, + 562, - 1622, + 564, - 534,
  • 562, - 538, + 564, - 1628, + 564, - 1624, + 564, - 1622,
  • 564, - 536, + 562, - 536, + 562, - 536, + 562, - 534,
  • 562, - 538, + 562, - 538, + 562, - 536, + 562, - 534,
  • 562, - 1626, + 566, - 1622, + 564, - 1622, + 564, - 1624,
  • 566, - 1624, + 580, - 5228, + 4434, - 4380, + 564, - 1626,
  • 562, - 534, + 564, - 1628, + 564, - 1622, + 566, - 534,
  • 562, - 534, + 562, - 1624, + 564, - 536, + 562, - 538,
  • 562, - 1626, + 566, - 534, + 564, - 536, + 562, - 1622,
  • 564, - 1624, + 564, - 534, + 562, - 1630, + 564, - 534,
  • 562, - 1624, + 562, - 1626, + 564, - 1622, + 564, - 1624,
  • 564, - 536, + 562, - 1628, + 564, - 1624, + 564, - 1628,
  • 566, - 534, + 562, - 536, + 564, - 534, + 562, - 534,
  • 564, - 1620, + 564, - 536, + 562, - 536, + 562, - 1630,
  • 566, - 1620, + 564, - 1622, + 566, - 534, + 562, - 536,
  • 562, - 534, + 562, - 536, + 560, - 538, + 562, - 536,
  • 562, - 534, + 564, - 534, + 564, - 1626, + 566, - 1622,
  • 564, - 1622, + 564, - 1622, + 566, - 1626, + 578

uint16_t rawData[199] = {4436, 4386, 568, 1622, 564, 536, 562, 1628, 564, 1622, 564, 534, 562, 536, 562, 1624, 564, 536, 564, 536, 564, 1626, 564, 534, 562, 536, 562, 1624, 564, 1624, 564, 536, 562, 1630, 564, 538, 562, 1624, 564, 1624, 562, 1622, 566, 1622, 566, 534, 562, 1628, 562, 1626, 566, 1628, 564, 536, 562, 534, 562, 534, 562, 534, 562, 1622, 564, 534, 562, 538, 564, 1628, 564, 1624, 564, 1622, 564, 536, 562, 536, 562, 536, 562, 534, 562, 538, 562, 538, 562, 536, 562, 534, 562, 1626, 566, 1622, 564, 1622, 564, 1624, 566, 1624, 580, 5228, 4434, 4380, 564, 1626, 562, 534, 564, 1628, 564, 1622, 566, 534, 562, 534, 562, 1624, 564, 536, 562, 538, 562, 1626, 566, 534, 564, 536, 562, 1622, 564, 1624, 564, 534, 562, 1630, 564, 534, 562, 1624, 562, 1626, 564, 1622, 564, 1624, 564, 536, 562, 1628, 564, 1624, 564, 1628, 566, 534, 562, 536, 564, 534, 562, 534, 564, 1620, 564, 536, 562, 536, 562, 1630, 566, 1620, 564, 1622, 566, 534, 562, 536, 562, 534, 562, 536, 560, 538, 562, 536, 562, 534, 564, 534, 564, 1626, 566, 1622, 564, 1622, 564, 1622, 566, 1626, 578}; // COOLIX B27BE0
uint64_t data = 0xB27BE0;

I was not able to make the code to send the info I decoded.

@royfocker19
Copy link
Author

I wasn't able to make my own decoder based on your IR library :(
I'm using this.
I'll keep trying to make it work with your IR library but I think we can close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants