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

Remote transmitter/receiver component support #69

Closed
i2r opened this issue Jan 30, 2023 · 61 comments · Fixed by libretiny-eu/libretiny-esphome#6
Closed

Remote transmitter/receiver component support #69

i2r opened this issue Jan 30, 2023 · 61 comments · Fixed by libretiny-eu/libretiny-esphome#6
Labels
bug Something isn't working

Comments

@i2r
Copy link

i2r commented Jan 30, 2023

Hi. Thank you for great work.

Trying to compile firmware for bk7231.

Adding component:

remote_transmitter:
  pin: D7
  carrier_duty_percent: 50%

Causes compiling error:

undefined reference to 'vtable for esphome::remote_transmitter::RemoteTransmitterComponent'
@kuba2k2
Copy link
Member

kuba2k2 commented Jan 31, 2023

Not implemented in esphome yet. You could try changing #ifdef ESP32 to LIBRETUYA and there's a slight chance it will work.

@RoganDawes
Copy link

I honestly didn't have to work too hard to get the remote_receiver: integration working when I did the STM32 port. If the GPIO's are working for input and output, then the remote* integrations should also work, albeit less efficiently than when using the ESP32 RMT peripheral. So you might want to aim at the ESP8266 implementation rather than the ESP32 version, as the ESP8266 was purely using the GPIOs.

@catalin2402
Copy link
Collaborator

#33 it seems someone did the same, modified the remote_transmitter and remote_receiver and it works. And i think it targeted the esp8266 too

@ferbulous
Copy link

@catalin2402 is there specific instruction to do that? How do I modify the remote_transmitter & receiver .cpp files?

@catalin2402
Copy link
Collaborator

where you see #define ESP8266, change it with #if defined(USE_ESP8266) || defined(USE_LIBRETUYA)

@ferbulous
Copy link

thanks! @catalin2402 , modified the line in remote_receiver_esp8266.cpp
just that I'm getting this error when compiling

←[32mINFO Reading configuration smatrul_remote.yml...←[0m
←[32mINFO Generating C++ source...←[0m
Traceback (most recent call last):
  File "C:\Users\theba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\theba\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 975, in <module>
    sys.exit(main())
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 966, in main
    return run_esphome(sys.argv)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 953, in run_esphome
    rc = POST_CONFIG_ACTIONS[args.command](args, config)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 361, in command_compile
    exit_code = write_cpp(config)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 177, in write_cpp
    generate_cpp_contents(config)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 189, in generate_cpp_contents
    CORE.flush_tasks()
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\core\__init__.py", line 625, in flush_tasks
    self.event_loop.flush_tasks()
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\coroutine.py", line 246, in flush_tasks
    next(task.iterator)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\__main__.py", line 169, in wrapped
    await coro(conf)
  File "C:\Users\theba\Desktop\esp\libretuya-esphome\esphome\components\remote_receiver\__init__.py", line 63, in to_code
    cg.add(var.set_buffer_size(config[CONF_BUFFER_SIZE]))
KeyError: 'buffer_size'
sys:1: RuntimeWarning: coroutine 'add_arduino_global_workaround' was never awaited

@i2r
Copy link
Author

i2r commented Jan 31, 2023

@ferbulous try to set buffer_size: 1kB in your device config, like so:

remote_receiver:
  ...
  buffer_size: 1kB

@i2r
Copy link
Author

i2r commented Jan 31, 2023

@catalin2402 thank you! Compiled successfully. Now trying to find pin with transmitter connected (without opening device).

diff --git a/esphome/components/remote_transmitter/remote_transmitter.h b/esphome/components/remote_transmitter/remote_transmitter.h
index 560d8380..91cfb2af 100644
--- a/esphome/components/remote_transmitter/remote_transmitter.h
+++ b/esphome/components/remote_transmitter/remote_transmitter.h
@@ -28,7 +28,8 @@ class RemoteTransmitterComponent : public remote_base::RemoteTransmitterBase,

  protected:
   void send_internal(uint32_t send_times, uint32_t send_wait) override;
-#ifdef USE_ESP8266
+/* #ifdef USE_ESP8266 */
+#if defined(USE_ESP8266) || defined(USE_LIBRETUYA)
   void calculate_on_off_time_(uint32_t carrier_frequency, uint32_t *on_time_period, uint32_t *off_time_period);

   void mark_(uint32_t on_time, uint32_t off_time, uint32_t usec);
diff --git a/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp b/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp
index 1c0eb94e..1aed7977 100644
--- a/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp
+++ b/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp
@@ -2,7 +2,7 @@
 #include "esphome/core/log.h"
 #include "esphome/core/application.h"

-#ifdef USE_ESP8266
+#if defined(USE_ESP8266) || defined(USE_LIBRETUYA)

 namespace esphome {
 namespace remote_transmitter {

@samneirinck
Copy link

I've been running a remote_receiver and remote_transmitter for a while, based on the esp8266 code. (using a Moes Tuya Remote Control IR Controller)

The receiver seems to work flawlessly: the IR commands get recognized in the correct format. Transmitting however I couldn't get to work yet reliably, I can see the receiver receive some signals when I transmit them, but the timing is off, and the actual devices don't recognize them.

If I retry a couple of times (e.g. via setting repeat on the remote transmitter action), then it works in about 1 out of 10 attempts.

I'm still planning to dive in a bit deeper, but would be interesting to know if you're facing similar issues once you get it running.

@i2r
Copy link
Author

i2r commented Jan 31, 2023

@samneirinck i got it! Found pinout for my device at https://www.elektroda.com/rtvforum/topic3940249.html

And i have exactly the same problem now. Transmitter works in about 1 out of 6—7 attempts.

@RoganDawes
Copy link

Do you perhaps have a logic analyser or oscilloscope? I know you were trying to avoid opening the device, but if you could tap that pin to get some debugging information (timing of the waveform, really), that would be very helpful to figure out what is actually going wrong.

@i2r
Copy link
Author

i2r commented Jan 31, 2023

@RoganDawes no, i do not have it =(

@kuba2k2
Copy link
Member

kuba2k2 commented Jan 31, 2023

If anyone of you got the receiver/transmitter to work, feel free to open a PR!

@i2r
Copy link
Author

i2r commented Jan 31, 2023

@RoganDawes is it possible to analyse transmitted signal by recording raw data by the device's receiver?

// Signal by Original remote
[23:15:03][D][remote.raw:028]: Received Raw: 8937, -4463, 628, -493, 625, -500, 625, -1663, 556, -531, 625, -469, 625, -500, 628, -497, 625, -500, 625, -1663, 556, -1687, 594, -1660, 590, -1656, 594, -510, 615, -469, 625, -500, 593, -532, 635, -490, 625, -1656, 594, -500, 631, -494,
[23:15:03][D][remote.raw:041]:   625, -500, 625, -500, 625, -503, 622, -500, 625, -1625, 601, -493, 625, -1656, 594, -1663, 588, -1655, 601, -1649, 594, -1633, 585, -1657, 594
[23:15:03][D][remote.raw:041]: Received Raw: 9015, -2164, 600


[23:15:09][D][remote.raw:028]: Received Raw: 8954, -2469, 2625, -494, 625, -500, 593, -1695, 555, -532, 593, -532, 593, -500, 597, -528, 594, -531, 594, -1694, 587, -1657, 593, -1660, 590, -1657, 593, -507, 587, -500, 625, -500, 594, -531, 597, -528, 594, -1687, 594, -510, 615, -500,
[23:15:09][D][remote.raw:041]:   625, -500, 625, -500, 635, -490, 594, -531, 625, -1625, 601, -493, 625, -1656, 594, -1663, 587, -1656, 601, -1650, 594, -1664, 588, -1626, 594
[23:15:09][D][remote.raw:041]: Received Raw: 8994, -2226, 533


[23:15:15][D][remote.raw:028]: Received Raw: 8925, -4462, 622, -506, 619, -500, 625, -1657, 598, -495, 594, -531, 625, -500, 625, -501, 628, -497, 625, -1625, 625, -1628, 591, -1656, 600, -1650, 594, -500, 625, -516, 609, -500, 625, -500, 625, -500, 633, -1617, 625, -469, 625, -501,
[23:15:15][D][remote.raw:041]:   631, -493, 625, -500, 625, -500, 663, -462, 656, -1626, 594, -500, 672, -1609, 594, -1632, 586, -1657, 594, -1663, 587, -1656, 594, -1663, 587
[23:15:15][D][remote.raw:041]: Received Raw: 9010, -2198, 619


// Remote Transmitter reproducing original signal
[23:16:19][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:19][D][remote_transmitter:075]: Sending remote code...
[23:16:19][D][remote.raw:028]: Received Raw: 2817, -1371, 3624, -3906, 718, -469, 688, -469, 687, -1500, 724, -495, 625, -469, 687, -468, 687, -469, 655, -469, 687, -1532, 687, -1501, 687, -1531, 656, -1531, 625, -531, 687, -470, 656, -468, 687, -469, 687, -468, 687, -1500, 687, -469,
[23:16:19][D][remote.raw:041]:   688, -469, 687, -469, 687, -468, 3188, -1312, 2812
[23:16:19][D][remote.raw:041]: Received Raw: 249, -1875, 594, -1468, 2939, -1499, 2844


[23:16:26][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:26][D][remote_transmitter:075]: Sending remote code...
[23:16:26][D][remote.raw:041]: Received Raw: 3058, -343, 2813, -1397, 883, -3344, 656, -468, 688, -470, 656, -1531, 718, -468, 687, -468, 3187, -188
[23:16:26][D][remote.raw:041]: Received Raw: -3499, 312, -1876, 687, -1531, 687, -1530, 657, -501, 687, -438, 656, -501, 624, -532, 686, -469, 625, -1562, 655, -500, 626, -2085, 194, -532, 625, -531, 626, -531, 593, -1594, 625, -562, 2281


[23:16:34][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:34][D][remote_transmitter:075]: Sending remote code...
[23:16:34][D][remote.raw:028]: Received Raw: 2199, -1100, 4620, -3908, 687, -469, 688, -469, 688, -1501, 687, -468, 689, -469, 688, -468, 687, -469, 657, -469, 688, -1532, 751, -1907, 219, -1501, 687, -1533, 687, -469, 657, -632, 524, -470, 688, -469, 687, -469, 657, -1532, 687, -469,
[23:16:34][D][remote.raw:041]:   688, -470, 657, -469, 781, -377, 688, -469, 687, -1149, 352, -1126, 718, -469, 687, -1501, 687, -1533, 657, -1532, 688, -1502, 687, -1532, 844


[23:16:42][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:42][D][remote_transmitter:075]: Sending remote code...
[23:16:43][D][remote.raw:028]: Received Raw: 3263, -1377, 3214, -3912, 184, -663, 958, -500, 687, -1531, 594, -563, 657, -469, 687, -469, 688, -468, 656, -500, 656, -1532, 655, -1656, 563, -1531, 656, -1532, 688, -469, 687, -468, 656, -500, 593, -562, 656, -469, 687, -1531, 688, -468,
[23:16:43][D][remote.raw:041]:   656, -469, 687, -469, 687, -469, 688, -467, 658, -500, 657, -1531, 688, -469, 688, -1501, 688, -1532, 657, -1532, 657, -1532, 688, -1531, 657, -1532, 688


[23:16:46][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:46][D][remote_transmitter:075]: Sending remote code...
[23:16:46][D][remote.raw:041]: Received Raw: 138, -2125, 1250, -1435, 2937, -3907, 718, -469, 905, -2438, 625, -532, 687, -687, 469, -469, 687, -469, 657, -469, 687, -1531, 2843, -1532, 2906
[23:16:46][D][remote.raw:041]: Received Raw: 219, -3875, 1031, -314, 719, -468, 687, -1500, 688, -469, 3218, -126
[23:16:46][D][remote.raw:041]: Received Raw: -2469, 625, -532, 688, -1499, 689, -468, 688, -1532, 656, -1531, 688, -1499, 688, -1530, 687, -1500, 688, -1530, 2565


[23:16:50][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:50][D][remote_transmitter:075]: Sending remote code...
[23:16:50][D][remote.raw:028]: Received Raw: 2617, -1344, 3965, -3914, 708, -438, 687, -469, 687, -1532, 657, -468, 688, -468, 688, -468, 687, -470, 657, -499, 657, -1530, 688, -1500, 686, -1532, 688, -1500, 687, -469, 688, -468, 657, -500, 656, -469, 687, -469, 687, -1531, 656, -469,
[23:16:50][D][remote.raw:041]:   687, -469, 688, -468, 688, -468, 687, -468, 2813
[23:16:50][D][remote.raw:041]: Received Raw: 125, -1188, 1375, -469, 876, -3500, 718, -1468, 718, -1500, 688, -1531, 687, -1500, 2594


[23:16:54][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:54][D][remote_transmitter:075]: Sending remote code...
[23:16:54][D][remote.raw:041]: Received Raw: 5932, -1367, 1029, -3504, 690, -469, 3064, -282
[23:16:54][D][remote.raw:041]: Received Raw: -2472, 688, -470, 688, -437, 689, -470, 688, -469, 688, -1502, 688, -1533, 689, -1501, 689, -1501, 688, -470, 688, -470, 3187, -158
[23:16:54][D][remote.raw:041]: Received Raw: -1940, 188, -1502, 688, -469, 688, -470, 689, -469, 657, -470, 689, -469, 657, -501, 688, -1502, 2844, -503, 688, -1534, 657, -1534, 688, -1502, 2845, -1567, 563


[23:16:57][D][button:013]: 'PH450 Volume Up' Pressed.
[23:16:57][D][remote_transmitter:075]: Sending remote code...
[23:16:57][D][remote.raw:041]: Received Raw: 3366, -1361, 3138, -3908, 689, -500, 658, -469, 844, -1376, 657, -469, 658, -500, 687, -469, 687, -469, 845, -1407, 157, -938, 594, -1563, 719, -1531, 658, -1531, 688, -468, 3188, -157
[23:16:57][D][remote.raw:041]: Received Raw: -907, 375, -595, 218, -470, 720, -1501, 1220, -970, 1907, -500, 625, -531, 688, -563, 2813, -407
[23:16:57][D][remote.raw:041]: Received Raw: -3943, 2248, -1501, 375, -156, 438, -1250, 688, -1532, 688, -1502, 687


[23:17:02][D][button:013]: 'PH450 Volume Up' Pressed.
[23:17:02][D][remote_transmitter:075]: Sending remote code...
[23:17:02][D][remote.raw:028]: Received Raw: 3165, -687, 2795, -3966, 718, -468, 656, -469, 687, -1531, 687, -469, 656, -468, 687, -469, 687, -468, 781, -843, 218, -1499, 687, -1529, 688, -1499, 687, -1531, 686, -468, 657, -468, 688, -468, 687, -468, 687, -468, 686, -1500, 687, -469,
[23:17:02][D][remote.raw:041]:   3218, -125
[23:17:02][D][remote.raw:041]: Received Raw: -968, 1437, -500, 687, -468, 687, -1499, 687, -500, 687, -1499, 687, -1500, 687, -1532, 688, -1499, 688, -1531, 656, -1531, 695

@ferbulous
Copy link

@ferbulous try to set buffer_size: 1kB in your device config, like so:

remote_receiver:
  ...
  buffer_size: 1kB

Thanks, but now I'm getting this error

Compiling .pioenvs\remote\src\esphome\core\entity_base.cpp.o
Compiling .pioenvs\remote\src\esphome\core\helpers.cpp.o
Compiling .pioenvs\remote\src\esphome\core\log.cpp.o
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:13:20: error: 'RemoteReceiverComponentStore' has not been declared
 void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverComponentStore *arg) {
                    ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:13:60: error: variable or field 'gpio_intr' declared void
 void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverComponentStore *arg) {
                                                            ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:13:60: error: 'RemoteReceiverComponentStore' was not declared in this scope
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:13:90: error: 'arg' was not declared in this scope
 void IRAM_ATTR HOT RemoteReceiverComponentStore::gpio_intr(RemoteReceiverComponentStore *arg) {
                                                                                          ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp: In member function 'virtual void esphome::remote_receiver::RemoteReceiverComponent::setup()':
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:36:19: error: 'class esphome::remote_receiver::RemoteReceiverComponent' has no member named 'store_'
   auto &s = this->store_;
                   ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:41:9: error: 'class esphome::remote_receiver::RemoteReceiverComponent' has no member named 'high_freq_'
   this->high_freq_.start();
         ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:57:32: error: 'RemoteReceiverComponentStore' has not been declared
   this->pin_->attach_interrupt(RemoteReceiverComponentStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);
                                ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:57:80: error: 'class esphome::remote_receiver::RemoteReceiverComponent' has no member named 'store_'
   this->pin_->attach_interrupt(RemoteReceiverComponentStore::gpio_intr, &this->store_, gpio::INTERRUPT_ANY_EDGE);
                                                                                ^
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp: In member function 'virtual void esphome::remote_receiver::RemoteReceiverComponent::loop()':
src/esphome/components/remote_receiver/remote_receiver_esp8266.cpp:73:19: error: 'class esphome::remote_receiver::RemoteReceiverComponent' has no member named 'store_'
   auto &s = this->store_;
                   ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:24:82: error: no 'void esphome::remote_transmitter::RemoteTransmitterComponent::calculate_on_off_time_(uint32_t, uint32_t*, uint32_t*)' member function declared in class 'esphome::remote_transmitter::RemoteTransmitterComponent'
                                                         uint32_t *off_time_period) {
                                                                                  ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:36:53: error: no 'void esphome::remote_transmitter::RemoteTransmitterComponent::await_target_time_()' member function declared in class 'esphome::remote_transmitter::RemoteTransmitterComponent'
 void RemoteTransmitterComponent::await_target_time_() {
                                                     ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:45:90: error: no 'void esphome::remote_transmitter::RemoteTransmitterComponent::mark_(uint32_t, uint32_t, uint32_t)' member function declared in class 'esphome::remote_transmitter::RemoteTransmitterComponent'
 void RemoteTransmitterComponent::mark_(uint32_t on_time, uint32_t off_time, uint32_t usec) {
                                                                                          ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:68:54: error: no 'void esphome::remote_transmitter::RemoteTransmitterComponent::space_(uint32_t)' member function declared in class 'esphome::remote_transmitter::RemoteTransmitterComponent'
 void RemoteTransmitterComponent::space_(uint32_t usec) {
                                                      ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp: In member function 'virtual void esphome::remote_transmitter::RemoteTransmitterComponent::send_internal(uint32_t, uint32_t)':
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:77:9: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'calculate_on_off_time_'
   this->calculate_on_off_time_(this->temp_.get_carrier_frequency(), &on_time, &off_time);
         ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:78:9: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'target_time_'
   this->target_time_ = 0;
         ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:83:15: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'mark_'
         this->mark_(on_time, off_time, length);
               ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:86:15: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'space_'
         this->space_(length);
               ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:90:11: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'await_target_time_'
     this->await_target_time_();  // wait for duration of last pulse
           ^
src/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp:94:13: error: 'class esphome::remote_transmitter::RemoteTransmitterComponent' has no member named 'target_time_'
       this->target_time_ += send_wait;
             ^
*** [.pioenvs\remote\src\esphome\components\remote_receiver\remote_receiver_esp8266.cpp.o] Error 1
*** [.pioenvs\remote\src\esphome\components\remote_transmitter\remote_transmitter_esp8266.cpp.o] Error 1

Any other changes I need to make to the yaml or LT files?

esphome:
  name: remote

libretuya:
  board: generic-bk7231n-qfn32-tuya
  framework:
    version: dev

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: ""

ota:
  password: ""

wifi:
  ssid: ''''
  password: '''

  # Enable fallback hotspot in case wifi connection fails
  ap:
    ssid: "Remote Fallback Hotspot"
    password: "lF3TNuAkT83a"

web_server:
  port: 80
  
# GPIO	Component	Description
#7	IRSend
#8	IRRecv
#24	LED_n

  
remote_transmitter:
  pin: D3
  carrier_duty_percent: 30%
  
remote_receiver:
  id: rcvr
  pin:
    number: D4
    inverted: True
  tolerance: 55%
  buffer_size: 1kB
  dump: all

@ferbulous
Copy link

If I retry a couple of times (e.g. via setting repeat on the remote transmitter action), then it works in about 1 out of 10 attempts.

I noticed the same bug on openbk (for the console command)

@i2r
Copy link
Author

i2r commented Feb 1, 2023

@i2r
Copy link
Author

i2r commented Feb 1, 2023

If you give me code fragment, I can use it to log generated signal. So we can understand where is a problem: (1) at signal generation or (2) transmittion.

@ferbulous
Copy link

If not, you need to change *.h file too:
https://github.com/esphome/esphome/blob/e847766514957f6ceb81de0b678399918ed532a2/esphome/components/remote_receiver/remote_receiver.h#L9
https://github.com/esphome/esphome/blob/e847766514957f6ceb81de0b678399918ed532a2/esphome/components/remote_receiver/remote_receiver.h#L58

Thanks! that fixed it, on both the receiver.h & transmitter.h
Will test it out later if I have the same issue with the repeated attempts

@ferbulous
Copy link

@i2r hi, not much success yet with transmitting (i keep pressing the button repeatedly)
tested with sony and pronto codes. I'll be testing the same codes on esp just to verify if the code does work
Do you mind sharing how you added the raw codes in the yaml

//sony vol down raw
22:56:08	[D]	[remote.raw:041]	
Received Raw: 2219, -667, 1125, -657, 1145, -636, 531, -688, 531, -688, 1114, -668, 531, -656, 532, -695, 544, -668, 500, -656, 531, -688, 536, -2695, 1082
22:56:08	[D]	[remote.raw:041]	
Received Raw: 4148, -681, 1094, -708, 1105, -687, 500, -688, 537, -695, 1081, -688, 531, -657, 551, -668, 500, -688, 531, -688, 500, -708, 479, -688, 1125
22:56:08	[D]	[remote.raw:041]	
Received Raw: 2212, -688, 1145, -668, 1094, -687, 532, -708, 480, -687, 1125, -688, 472, -2729, 487
22:56:08	[D]	[remote.raw:041]	
Received Raw: 498, -688, 500, -708, 511, -688, 499, -688, 1125

@i2r
Copy link
Author

i2r commented Feb 1, 2023

@RoganDawes
I think, something goes wrong after this call https://github.com/esphome/esphome/blob/dev/esphome/components/remote_transmitter/remote_transmitter_esp8266.cpp#L88

I added some logging and seems that computed signal is correct:

Sending remote code...
8000, -4000, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600

But received signal is not:

[remote.raw:028]: Received Raw: 490, -203, 193, -974, 3510, -1291, 1329, -4225, 441, -626, 2609, -2417, 670, -6938, 341, -755, 1735, -1916, 536, -556, 1104, -6584, 357, -688, 1997, -4797, 463, -460, 2564, -4427, 366, -655, 2000, -4737, 422, -653, 2042, -3430, 3941, -5942,
[remote.raw:041]:   437, -507, 2003, -3142, 448, -537, 3277, -5194, 2382, -1010
[remote.raw:041]: Received Raw: -1979, 207, -2686, 607, -7176, 421, -7078, 2427
[remote.raw:041]: Received Raw: 4659, -1325, 1919, -4014, 580, -1057, 689, -2109, 463, -414, 3224, -1707, 430, -517, 2740, -5519, 348, -689, 1682, -5487, 449, -498, 1518, -3491, 2463
[remote.raw:041]: Received Raw: 4453, -2580, 432, -462, 3487, -3726, 513, -8565, 429, -7944, 422, -7101, 367
[remote.raw:041]: Received Raw: 216, -1555, 6041, -4094, 478, -1169, 792, -5102, 342, -894, 1219, -1813, 430, -536, 2814, -3455, 571, -525, 2959, -4318, 481, -5758, 431, -246, 4954, -4396, 160
[remote.raw:041]: Received Raw: 3726, -4639, 372, -429, 278, -131, 1930, -4767, 434, -1008, 413, -237, 867, -4968, 391, -337, 278, -6968, 328, -7834, 2359, -4008, 404
[remote.raw:028]: Received Raw: 1603, -1046, 1575, -746, 2818, -3986, 753, -883, 1093, -1877, 413, -812, 2739, -3652, 455, -499, 1575, -3261, 449, -242, 3681, -3250, 163, -122, 251, -1281, 443, -2227, 5514, -577, 3130, -2393, 1804, -610, 1638, -3670, 4461, -4826, 433,
[remote.raw:041]:   -469, 2244, -5157, 2391
[remote.raw:041]: Received Raw: 1258, -4517, 215, -723, 4357, -4020, 351, -564, 965, -185, 1432, -2569, 246, -8025, 167, -7368, 326, -7522, 2416

@dbuezas
Copy link
Contributor

dbuezas commented Feb 1, 2023

You may find this tool useful for visualizing, comparing and debugging raw patterns
https://github.com/dbuezas/esphome-remote_receiver-oscilloscope

@i2r
Copy link
Author

i2r commented Feb 1, 2023

@ferbulous

Example:

button:
  - platform: template
    name: "PH450 Z Send Raw"
    on_press:
      remote_transmitter.transmit_raw:
        code: [ 8940, -4463, 628, -493, 625, -500, 625, -1663, 556, -531, 625, -469, 625, -500, 628, -497, 625, -500, 625, -1663, 556, -1687, 594, -1660, 590, -1656, 594, -510, 615, -469, 625, -500, 593, -532, 635, -490, 625, -1656, 594, -500, 631, -494, 625, -500, 625, -500, 625, -503, 622, -500, 625, -1625, 601, -493, 625, -1656, 594, -1663, 588, -1655, 601, -1649, 594, -1633, 585, -1657, 600 ]
        carrier_frequency: 38kHz

But for tests i use transmit_lg

button:
  - platform: template
    name: "PH450 Volume Up"
    on_press:
      remote_transmitter.transmit_lg:
        data: 0x20F040BF
        nbits: 32

@dbuezas
Copy link
Contributor

dbuezas commented Feb 1, 2023

When transmitting, it is generally better to repeat the signal a bunch of times to increase the chances of the receiver getting it. Most rc remotes do exactly that, and the receivers debounce the commands so they only pick them up once.

    - remote_transmitter.transmit_raw:
          code: [...]
          repeat:
              times: 10
              wait_time: 4.733ms 

You can find an appropriate wait_time by increasing the idle option in the remote_receiver to a very high number. This will make it pick up multiple repetitions as a signal stream, separated by spaces as long as the remote's idle spacing. The UI tool above is particularly useful for that.

I think the first two numbers in the code 8940, -4463 are just spacing between repetitions actually. It doesn't make much of a difference when transmitting, but it is worth removing for receiving, or if you will do repeated transmissions as I suggest.

@i2r
Copy link
Author

i2r commented Feb 1, 2023

Anyway it sends random numbers:

[22:27:15][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:15][D][remote_transmitter:075]: Sending remote code...
[22:27:16][D][remote.raw:041]: Received Raw: 2312
[22:27:16][D][remote.raw:041]: Received Raw: 1032, -1736, 324, -375, 187, -3499, 2314, -2187, 3126
[22:27:16][D][remote.raw:041]: Received Raw: 313, -1968, 437, -438, 562, -624, 594, -1562, 2874, -3718, 656, -593, 2312, -1126
[22:27:16][D][remote.raw:041]: Received Raw: -2906, 531, -1624, 1093, -2376, 562, -656, 250, -4155, 594, -562, 594, -1594, 625, -1593, 563, -1656, 562, -1625, 593, -1626, 563, -1655, 564


[22:27:19][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:19][D][remote_transmitter:075]: Sending remote code...
[22:27:19][D][remote.raw:041]: Received Raw: 177, -337, 1846, -1426, 3793, -3909, 688, -500, 657, -468, 658, -1563, 3188
[22:27:19][D][remote.raw:041]: Received Raw: 312, -2002, 500, -470, 626, -531, 563, -1594, 2906, -1534, 562, -1595, 625, -563, 595, -532, 594, -562, 594, -564, 624, -532, 624, -1562, 593, -563, 625, -532, 593, -562, 594, -562, 594, -532, 625, -563, 562, -1687, 2281, -1032
[22:27:19][D][remote.raw:041]: Received Raw: -8280, 281


[22:27:22][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:22][D][remote_transmitter:075]: Sending remote code...
[22:27:22][D][remote.raw:041]: Received Raw: 6087, -4662, 615, -562, 562, -563, 593, -1626, 562, -593, 531, -594, 625, -531, 593, -562, 562, -594, 2874, -1500, 2876, -1531, 626, -531, 2343, -313, 2281, -626
[22:27:22][D][remote.raw:041]: Received Raw: -7244, 625, -501, 625, -562, 656, -500, 593, -562, 657, -1531, 656, -500, 625, -1563, 687, -1531, 594, -1593, 657, -1538, 679, -1532, 656, -1530, 594


[22:27:25][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:25][D][remote_transmitter:075]: Sending remote code...
[22:27:25][D][remote.raw:028]: Received Raw: 178, -431, 815, -1807, 318, -812, 3216, -3939, 594, -594, 532, -593, 626, -1595, 563, -594, 594, -532, 594, -563, 594, -563, 594, -562, 626, -1563, 593, -1595, 594, -1626, 594, -1595, 563, -594, 625, -531, 594, -532, 626, -532, 624, -532,
[22:27:25][D][remote.raw:041]:   625, -1563, 625, -532, 593, -563, 595, -562, 626, -531, 625, -501, 625, -597, 216, -2125, 282, -657, 2343
[22:27:25][D][remote.raw:041]: Received Raw: 155, -5507, 591, -1595, 688, -1531, 2783, -1595, 626


[22:27:28][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:28][D][remote_transmitter:075]: Sending remote code...
[22:27:28][D][remote.raw:041]: Received Raw: 2208, -619
[22:27:28][D][remote.raw:041]: Received Raw: -1031, 4782, -3947, 333, -2312, 437, -1406, 3125
[22:27:28][D][remote.raw:041]: Received Raw: 343, -1938, 281, -531, 625, -531, 2344, -188, 312, -1531, 2875, -1531, 626, -531, 2406, -2250, 250, -563
[22:27:28][D][remote.raw:041]: Received Raw: -6344, 249, -625, 626, -500, 626, -562, 656, -500, 594, -562, 416, -2965, 555, -1594, 656, -1563, 593, -1593, 656, -1531, 687, -1532, 656, -1531, 595


[22:27:30][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:30][D][remote_transmitter:075]: Sending remote code...
[22:27:30][D][remote.raw:041]: Received Raw: 178, -368, 2841, -2249, 375, -2625
[22:27:30][D][remote.raw:041]: Received Raw: -4343, 656, -500, 562, -719, 531, -1500, 656, -532, 3188, -219
[22:27:30][D][remote.raw:028]: Received Raw: -2502, 656, -1533, 656, -1563, 625, -1563, 626, -1564, 687, -469, 656, -501, 625, -531, 656, -469, 656, -500, 688, -1532, 656, -469, 687, -469, 625, -533, 656, -500, 625, -532, 659, -467, 688, -1532, 625, -501, 537, -3872, 656, -1564, 657,
[22:27:30][D][remote.raw:041]:   -1532, 656, -1532, 687, -1532, 679


[22:27:35][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:35][D][remote_transmitter:075]: Sending remote code...
[22:27:35][D][remote.raw:041]: Received Raw: 169, -400, 1627, -1842, 3656, -3907, 594, -594, 2846, -500
[22:27:35][D][remote.raw:041]: Received Raw: -2595, 3126
[22:27:35][D][remote.raw:041]: Received Raw: 281, -1938, 469, -500, 813, -3564, 688, -1532, 657, -1532, 2313, -281, 344, -532
[22:27:35][D][remote.raw:041]: Received Raw: -2500, 656, -500, 625, -1594, 656, -469, 656, -500, 656, -500, 656, -501, 3188, -1312, 594, -531, 626, -2804, 289, -656, 657, -1593, 625, -1531, 624, -1624, 563, -1625, 695


[22:27:39][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:39][D][remote_transmitter:075]: Sending remote code...
[22:27:39][D][remote.raw:041]: Received Raw: 209, -2837
[22:27:39][D][remote.raw:028]: Received Raw: -875, 1658, -2050, 1480, -3907, 625, -563, 625, -531, 626, -1563, 625, -532, 626, -531, 656, -501, 595, -531, 564, -594, 655, -1533, 688, -1532, 594, -1594, 594, -1626, 625, -500, 595, -563, 594, -563, 594, -563, 594, -531, 688, -1720, 438,
[22:27:39][D][remote.raw:041]:   -719, 437, -502, 217, -875, 688, -532, 562, -594, 657, -500, 625, -1564, 635, -523, 624, -1564, 563, -1627, 687, -1532, 625, -1563, 625, -1595, 625, -1563, 661


[22:27:42][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:42][D][remote_transmitter:075]: Sending remote code...
[22:27:42][D][remote.raw:041]: Received Raw: 178, -274, 2346, -1406, 3406, -3907, 656, -500, 688, -470, 2376, -969
[22:27:42][D][remote.raw:028]: Received Raw: -2533, 657, -504, 653, -500, 656, -501, 656, -1501, 687, -1532, 2407, -2281, 531, -379, 562, -500, 939, -1595, 375, -595, 531, -1625, 625, -531, 625, -532, 594, -563, 563, -562, 594, -563, 625, -563, 594, -1563, 626, -563, 594, -1595, 594,
[22:27:42][D][remote.raw:041]:   -1626, 687, -1499, 593, -1593, 593, -1656, 562, -1594, 626


[22:27:45][D][button:013]: 'PH450 Volume Up' Pressed.
[22:27:45][D][remote_transmitter:075]: Sending remote code...
[22:27:45][D][remote.raw:041]: Received Raw: 987, -3744, 594, -594, 156, -374, 219, -407, 626, -1695, 2370, -500
[22:27:45][D][remote.raw:028]: Received Raw: -2533, 656, -532, 626, -1532, 688, -1562, 657, -1532, 625, -1564, 688, -468, 656, -501, 657, -500, 657, -469, 688, -468, 657, -1563, 625, -500, 657, -501, 625, -563, 594, -531, 875, -1626, 469, -1533, 656, -469, 689, -1500, 657, -1565, 656,
[22:27:45][D][remote.raw:041]:   -1532, 687, -1532, 657, -1511, 678, -1531, 735

@i2r
Copy link
Author

i2r commented Feb 1, 2023

Config:

remote_transmitter:
  pin:
    number: P7
    mode:
      output: true
  carrier_duty_percent: 50%

remote_receiver:
  pin:
    number: P8
    inverted: true
  buffer_size: 1kB
  idle: 200ms
  dump: raw

button:
  - platform: template
    name: "PH450 Z Send Raw"
    on_press:
      remote_transmitter.transmit_raw:
        code: [ 8000, -4000, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -550, 600, -1600, 600, -550, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600, -1600, 600 ]
        carrier_frequency: 38kHz
        repeat:
          times: 10
          wait_time: 4.733ms

Results:

[22:37:47][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:37:47][D][remote_transmitter:075]: Sending remote code...
[22:37:47][D][remote.raw:041]: Received Raw: 202, -399, 2567, -1769, 384, -937, 2625, -2158, 688, -469, 656, -500, 657, -1532, 2375, -2844
[22:37:47][D][remote.raw:041]: Received Raw: -3906, 624, -1563, 655, -1531, 625, -1593, 656, -1530, 656, -499, 3156, -282, 2343
[22:37:47][D][remote.raw:041]: Received Raw: 344, -1562, 687, -470, 2344, -437, 406, -250
[22:37:47][D][remote.raw:028]: Received Raw: -2468, 688, -468, 686, -1531, 657, -468, 657, -1562, 656, -1531, 625, -1561, 688, -1531, 656, -1530, 2875, -5108, 2043, -9494, 563, -625, 593, -563, 593, -1595, 594, -593, 573, -551, 562, -593, 531, -657, 531, -656, 500, -1781, 406, -1687,
[22:37:47][D][remote.raw:041]:   500, -1749, 469, -1780, 2281, -63522, 156, -11152, 156, -13274, 219, -2030, 187, -1999, 187, -9652, 231, -13942, 249, -6622, 125, -1000, 187, -1906, 187, -4248, 249, -1938, 250, -4435, 187, -3060, 281, -2064, 250, -2092, 219


[22:37:58][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:37:58][D][remote_transmitter:075]: Sending remote code...
[22:37:59][D][remote.raw:028]: Received Raw: 205, -463, 1064, -1803, 4163, -6222, 335, -1917, 583, -531, 657, -532, 594, -531, 656, -500, 657, -501, 656, -1530, 625, -1562, 687, -1499, 657, -1531, 655, -500, 624, -562, 625, -545, 579, -532, 624, -563, 593, -1593, 562, -594, 593, -531,
[22:37:59][D][remote.raw:028]:   625, -530, 626, -532, 593, -594, 532, -593, 601, -1617, 563, -625, 532, -1624, 563, -1655, 563, -1686, 500, -1687, 500, -1718, 468, -1781, 156, -5248, 2250, -83302, 250, -2123, 156, -2061, 250, -1938, 250, -6341, 281, -999, 125, -967, 188, -906, 250,
[22:37:59][D][remote.raw:028]:   -905, 250, -3154, 188, -906, 250, -875, 281, -937, 219, -905, 250, -843, 156, -1062, 219, -2000, 219, -937, 188, -1936, 281, -1905, 281, -1937, 281, -4156, 250, -1906, 249, -5154, 250, -18383, 198, -906, 250, -905, 219, -968, 281, -1875, 2250, -5687,
[22:37:59][D][remote.raw:041]:   218, -783, 375, -687, 468, -688, 468, -719, 438, -1687, 249, -968, 438, -749, 344, -750, 468, -656, 499, -656, 468, -719, 249, -1968, 2250
[22:37:59][D][remote.raw:041]: Received Raw: 204, -1031, 250, -813, 428, -2887, 2246, -1217, 468, -688, 188, -2031, 437, -1812, 2281, -2061, 219, -7685, 2283
[22:37:59][D][remote.raw:041]: Received Raw: 187, -2156, 156, -687, 500, -874, 281, -624, 500, -1686, 532, -656, 468, -1688, 530, -1688, 499, -1687, 500, -1717, 500, -1687, 249, -1969, 499


[22:38:07][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:38:07][D][remote_transmitter:075]: Sending remote code...
[22:38:08][D][remote.raw:028]: Received Raw: 209, -399, 1562, -1872, 310, -566, 343, -594, 1282, -3907, 621, -562, 657, -469, 593, -1626, 594, -562, 625, -500, 593, -562, 594, -562, 626, -532, 656, -1530, 624, -1594, 656, -1531, 656, -1531, 656, -500, 594, -562, 562, -594, 656, -500,
[22:38:08][D][remote.raw:041]:   593, -531, 688, -1532, 656, -499, 625, -500, 688, -469, 656, -501, 687, -469, 656, -500, 2312, -3219
[22:38:08][D][remote.raw:041]: Received Raw: -5593, 688, -1501, 687, -1534, 656, -1564, 594, -1594, 687, -4627, 8062, -3938, 626, -531, 595, -563, 2844, -501
[22:38:08][D][remote.raw:028]: Received Raw: -2564, 593, -531, 625, -562, 2314, -3252, 562, -1626, 562, -1594, 2344, -1159, 2282, -11400, 1636, -1658, 2281, -6597, 2250, -17222, 531, -878, 281, -594, 219, -3127, 530, -656, 500, -657, 500, -625, 532, -593, 563, -1657, 532, -1657, 532,
[22:38:08][D][remote.raw:041]:   -1688, 531, -1658, 531, -656, 469, -625, 563, -656, 469, -657, 500, -656, 2281, -1033
[22:38:08][D][remote.raw:041]: Received Raw: -9628, 563, -657, 500, -1656, 564, -1625, 563, -3985, 239, -1872, 2218, -5441, 218


[22:38:19][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:38:19][D][remote_transmitter:075]: Sending remote code...
[22:38:20][D][remote.raw:028]: Received Raw: 174, -431, 813, -436, 1064, -1368, 3378, -3936, 657, -500, 688, -468, 656, -1563, 656, -469, 687, -469, 656, -501, 625, -532, 656, -500, 625, -1564, 657, -1532, 2376, -2034, 657, -500, 656, -469, 688, -469, 689, -468, 656, -501, 656, -1501,
[22:38:20][D][remote.raw:028]:   687, -500, 625, -531, 470, -657, 625, -531, 688, -469, 626, -531, 656, -1532, 687, -469, 687, -1501, 687, -1532, 626, -1564, 2437, -157, 187, -1634, 650, -1531, 594, -4721, 8032, -3970, 656, -532, 563, -563, 626, -1595, 562, -563, 625, -531, 625, -532,
[22:38:20][D][remote.raw:041]:   594, -563, 594, -563, 593, -1595, 595, -1626, 2312, -2160, 250


[22:38:24][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:38:24][D][remote_transmitter:075]: Sending remote code...
[22:38:25][D][remote.raw:041]: Received Raw: 1814, -2080, 2825, -3905, 688, -499, 626, -531, 656, -1532, 3093
[22:38:25][D][remote.raw:028]: Received Raw: 156, -1937, 562, -469, 688, -469, 2343, -2281, 562, -1406, 594, -1593, 688, -500, 593, -531, 625, -531, 625, -531, 655, -500, 624, -1564, 625, -563, 593, -531, 594, -563, 531, -594, 626, -531, 594, -529, 626, -1595, 594, -531, 625, -1594,
[22:38:25][D][remote.raw:041]:   719, -1500, 625, -1562, 594, -1624, 594, -1593, 625, -1594, 594, -4719, 4214
[22:38:25][D][remote.raw:028]: Received Raw: 175, -901, 280, -938, 281, -1845, 187, -1094, 281, -814, 250, -844, 375, -782, 281, -813, 250, -1981, 238, -2220, 125, -1845, 281, -1939, 250, -875, 282, -844, 343, -814, 2187, -11366, 237, -906, 250, -1970, 437, -1751, 250, -1939, 438,
[22:38:25][D][remote.raw:041]:   -1812, 407, -1720, 468, -1751, 469, -4847, 2251
[22:38:25][D][remote.raw:028]: Received Raw: 2250, -8067, 1624, -688, 469, -1751, 281, -969, 251, -813, 250, -906, 250, -1033, 250, -751, 446, -1711, 469, -1749, 469, -1718, 219, -2186, 281, -688, 437, -719, 437, -719, 437, -689, 468, -688, 2656, -688, 469, -687, 437, -718, 261,
[22:38:25][D][remote.raw:041]:   -1113, 219, -718, 2250, -8783, 499, -1756, 244, -1906, 511, -1707, 469, -4843, 3216, -8874, 216


[22:38:31][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:38:31][D][remote_transmitter:075]: Sending remote code...
[22:38:31][D][remote.raw:028]: Received Raw: 209, -400, 2689, -1843, 470, -2719, 750, -2041, 650, -500, 657, -468, 688, -1532, 1814, -469, 688, -469, 593, -563, 656, -500, 656, -1532, 2344, -406, 157, -1502, 626, -1564, 1102, -2339, 594, -563, 594, -563, 594, -1563, 656, -534, 655,
[22:38:31][D][remote.raw:041]:   -500, 656, -500, 3189, -2125
[22:38:31][D][remote.raw:041]: Received Raw: -4159, 375, -531, 2406, -2282
[22:38:31][D][remote.raw:041]: Received Raw: -5284, 690, -1561, 625, -1564, 625, -1563, 657, -4659, 8035, -3974, 594, -563, 595, -532, 625, -1596, 626, -532, 625, -532, 594, -563, 563, -564, 626, -532, 595, -1596, 250, -2033, 532, -1596, 2282, -1095
[22:38:31][D][remote.raw:041]: Received Raw: -2848, 594, -594, 564, -563, 595, -563, 563, -1627, 595, -594, 532, -657, 500, -752, 375, -1857, 240, -1157, 187, -1971, 156, -126319, 250, -4410, 188, -4253, 219


[22:39:13][D][button:013]: 'PH450 Z Send Raw' Pressed.
[22:39:13][D][remote_transmitter:075]: Sending remote code...
[22:39:14][D][remote.raw:041]: Received Raw: 208, -369, 2404, -125, 406, -750, 1690, -372, 1563, -6275, 317, -2406, 2344
[22:39:14][D][remote.raw:028]: Received Raw: 219, -3938, 625, -562, 562, -562, 594, -1594, 687, -1532, 656, -1941, 2464, -500, 657, -500, 625, -531, 656, -469, 687, -469, 656, -1532, 657, -500, 656, -499, 656, -500, 658, -500, 657, -469, 656, -500, 656, -1562, 625, -500, 656, -1562,
[22:39:14][D][remote.raw:028]:   625, -1563, 656, -1563, 625, -1563, 624, -1562, 656, -1562, 657, -4655, 2280, -1906, 3905, -3907, 625, -531, 625, -531, 656, -1531, 657, -500, 563, -125, 156, -343, 626, -468, 624, -532, 624, -562, 562, -1594, 625, -1594, 626, -1593, 594, -1594, 625,
[22:39:14][D][remote.raw:028]:   -531, 593, -562, 607, -549, 2314, -2190, 2309, -1312, 376, -656, 531, -593, 563, -607, 549, -1657, 531, -2863, 480, -1718, 250, -2250, 124, -195443, 187, -5379, 156, -4255, 124, -10037, 187, -11377, 156, -1002, 125, -3126, 250, -7691, 250, -14289, 281,
[22:39:14][D][remote.raw:041]:   -969, 188, -908, 249, -2125, 156, -2095, 219, -1906, 282, -3066, 250, -4188, 250, -1908, 250, -1939, 250, -99645, 146, -20130, 208, -10843, 250, -31650, 250, -4187, 249, -2062, 188, -2001, 187, -3157, 218, -2093, 187, -937, 219, -3032, 250

@samneirinck
Copy link

I have a feeling it's mostly the beginning of the sequence that is causing problems. For testing purposes, I'm using the following:

      remote_transmitter.transmit_raw:
        code: [1000, -200, 500, -500, 750, -750, 1000]
        carrier_frequency: 38kHz

This was the output:

[20:27:25][D][remote.raw:041]: Received Raw: 194, -222, 278, -282, 406, -469, 782, -719, 1041
[20:27:50][D][remote.raw:041]: Received Raw: 174, -219, 250, -281, 469, -500, 781, -718, 1042
[20:28:01][D][remote.raw:041]: Received Raw: 205, -219, 219, -218, 469, -500, 781, -750, 981
[20:28:09][D][remote.raw:041]: Received Raw: 667, -219, 500, -469, 781, -718, 1041
[20:28:27][D][remote.raw:041]: Received Raw: 170, -222, 279, -218, 469, -469, 750, -753, 1070
[20:28:37][D][remote.raw:041]: Received Raw: 170, -218, 969, -500, 781, -719, 1009
[20:28:50][D][remote.raw:041]: Received Raw: 164, -250, 969, -469, 813, -688, 1041

Using @dbuezas's excellent tool, this looks like this:
(1st row is the reference)
image

With a different made-up sequence:
1000, -200, 500, -500, 750, -750, 1000, -200, 500, -500, 750, -750, 1000, -200, 500, -500, 750, -750, 1000, -200, 500, -500, 750, -750

(1st row is the reference)
image

I'll see to add some additional logging to see if this reveals more.

@kuba2k2
Copy link
Member

kuba2k2 commented Feb 1, 2023

I'm confused, is that remote transmitter/receiver for IR remotes, or 433 MHz remotes?

@dbuezas
Copy link
Contributor

dbuezas commented Feb 1, 2023

Using @dbuezas's excellent tool, this looks like this

😃 thanks!

I'm a bit confused too. Are you using two esphomes, one to send and the other to receive? If you are receiving while transmitting on the same esp, it can be that you get some rubbish out: transmitting is time critical so it is possible that esphome temporarily disables interrupts here and there. While the interrupts are disabled, the receiver may get the timings wrong or skip some flanks.

Anyway, those don't look random that random to me. They are just a bit offset from each other and have some trash at the start. For example green, pink and lime (or whatever color the bottom is) look mostly within a 50% tolerance.

@ferbulous
Copy link

@i2r
i'm using transmitter_sony
Do I just add to each line for this command with multiple data entry?

//vol up
20:25:09	[D]	[remote.sony:065]	
Received Sony: data=0x00000481, nbits=12
20:25:09	[D]	[remote.sony:065]	
Received Sony: data=0x00000681, nbits=12
20:25:10	[D]	[remote.sony:065]	
Received Sony: data=0x00000581, nbits=12
button:
  - platform: template
    name: "Sony Volume Up"
    on_press:
      remote_transmitter.transmit_sony:
        data: 0x00000481
        nbits: 12
      remote_transmitter.transmit_sony:
        data: 0x00000681
        nbits: 12
      remote_transmitter.transmit_sony:
        data: 0x00000581
        nbits: 12

For my raw codes, i should just output all the codes to a single line?
But I noticed the end of each & start of next line of codes are both positive values instead of positive & negative

//sony vol down raw
22:56:08	[D]	[remote.raw:041]	
Received Raw: 2219, -667, 1125, -657, 1145, -636, 531, -688, 531, -688, 1114, -668, 531, -656, 532, -695, 544, -668, 500, -656, 531, -688, 536, -2695, 1082
22:56:08	[D]	[remote.raw:041]	
Received Raw: 4148, -681, 1094, -708, 1105, -687, 500, -688, 537, -695, 1081, -688, 531, -657, 551, -668, 500, -688, 531, -688, 500, -708, 479, -688, 1125
22:56:08	[D]	[remote.raw:041]	
Received Raw: 2212, -688, 1145, -668, 1094, -687, 532, -708, 480, -687, 1125, -688, 472, -2729, 487
22:56:08	[D]	[remote.raw:041]	
Received Raw: 498, -688, 500, -708, 511, -688, 499, -688, 1125

@dbuezas
Copy link
Contributor

dbuezas commented Feb 2, 2023

It looks like you are almost there. How does the circuit look like? Maybe there's a pull up or pull down resistors, or something like like that could be tweaked a bit.
There is also a filter option in esphome that can discard pulses too short to be real. You could take something like 10 to 50% of the shortest pulse you want to receive and it should be more resilient. Or maybe some smoothing capacitor on the receiver

@i2r
Copy link
Author

i2r commented Feb 2, 2023

Source of device photos: https://www.elektroda.com/rtvforum/topic3940249.html

I can not modify receiver cause it is AC that I want to control with the bk7231n based remote with esphome firmware.

5891364100_1670580290_org
3227345400_1670580292_org
8919485700_1670580310_org
9736229700_1670580365_org

@kuba2k2 kuba2k2 added the bug Something isn't working label Feb 2, 2023
@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Oh, right, sorry I forgot it was a pre made one. And what is not working well is transmitting to the AC or receiving from the remote?

@i2r
Copy link
Author

i2r commented Feb 3, 2023

And what is not working well is transmitting to the AC or receiving from the remote?

With esp32s2 signal is correct every time, I tested.

So transmitting at bk7231 is broken. Looks like there are interrupts at transmission time.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

I see. Is reception also affected?
In esp32 and 8266, time is tracked using a cpu ticks counter which I believe is not present in libretuya chips, so a hardware timer is used for that instead. It is possible that the transmitter is disabling interrupts during time critical operations and that that results in the time keeping logic missing timer overflow events

@i2r
Copy link
Author

i2r commented Feb 3, 2023

Seems reception is not effected.

But I will check with transmitting by esp32s2 and receipting with bk7231.

@kuba2k2
Copy link
Member

kuba2k2 commented Feb 3, 2023

There's a feed_wdt() on line 88 of remote_transmitter_esp8266.cpp. It's possible that this function adds some delay to the process. Can you try with this line removed?

@i2r
Copy link
Author

i2r commented Feb 3, 2023

There's a feed_wdt() on line 88 of remote_transmitter_esp8266.cpp. It's possible that this function adds some delay to the process. Can you try with this line removed?

I already commented it out. All my tests are without App.feed_wdt(); call.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

The only thing I see that can go wrong is an interrupt taking very long and disrupting the carrier frequency. The issue is that if you were to disable interrupts while transmitting, the interrupts that keep track of time would also break down.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Now that I think about it, it may work. The carrier frequency is 38kHz, so micros() is called way more often than once every 2 ms (500hz). Therefore, micros should be able to stay on track. It will de-synchronize with millis, but the remote transmitter doesn't use millis anyway, so who cares.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Putting an interrupt lock here like this:

[...]
  for (uint32_t i = 0; i < send_times; i++) {
    InterruptLock lock;
    for (int32_t item : this->temp_.get_data()) {
[...]

Other things may get very unhappy about that, but I think it is worth the try :)

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Oh, I think you'll also need to replace the delayMicroseconds with a busy loop:
replace this
with:

  } else while (this->target_time_ > micros()){ /*busy loop that ensures micros is constantly called*/};

@samneirinck
Copy link

👏 Your assumptions are totally correct. With the above changes it works reliably!

Now the next question is, what interrupt handling is interfering here, because I guess putting in an interrupt lock for a couple of milliseconds is not the ideal way to fix this. Is there a way to log what interrupts are received?

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Oh wow I got lucky, that was a long shot 😁. I think I modified the micros() function for that uC specifically so it keeps working during long interrupts.

Unfortunately that's where my knowledge ends, I don't know what consequences that would have or which other interrupts may be interfering. Maybe with an oscilloscope one could check how much and how often the carrier is distorted. AFAIK, the wifi stack gets processing time when one calls delay or yield, but it may be doing something with interrupts too. I think only @kuba2k2 may know this. I also have no idea on how much overhead an interrupt in these chips has.

What you could do to reduce risks is to only disable interrupts while the pulse is high (or low if inverted). When the led's off, the carrier frequency doesn't matter, it's just off.

My guess is that it will work fine. It may lose some packets while transmitting, but I think the web sockets use TCP, so those will just be resent. And it's not like you'll be transmitting once a second all the time so ...

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

a couple of milliseconds

a couple of ms would be quite ok, but the signal you are sending is over 200ms... Anyway, as I said before, it should be able to recover from that just fine actually.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Can you share how the new screenshots look like? I'd like to see how much more accurate it becomes

@samneirinck
Copy link

Can you share how the new screenshots look like? I'd like to see how much more accurate it becomes

Unfortunately I only have a single device with both a receiver and a transmitter, maybe @i2r can test out the above and report back.

@dbuezas
Copy link
Contributor

dbuezas commented Feb 3, 2023

Oh, I think it would be wise to try re-adding the feed_wdt calls. Failling to feed the watchdog for too long will reboot the cpu, that's way worse than losing some packets

@i2r
Copy link
Author

i2r commented Feb 4, 2023

But I will check with transmitting by esp32s2 and receipting with bk7231.

Receiver is broken too. Sending signals with ESP32, receiving with bk7231. Re-added the feed_wdt calls.

remote_receiver:
  pin:
    number: P8
    inverted: true
  buffer_size: 1kB
  idle: 500ms
  dump: raw

Test signal with 10 repeats:
newplot-7

Real signal (projector volume up, short):
newplot-8

@i2r
Copy link
Author

i2r commented Feb 4, 2023

@dbuezas the signal is correct with your tweaks!

Receiver is disabled. Re-added the feed_wdt calls.

Test signal with 10 repeats
newplot-9

Real signal (projector volume up, short)
newplot-10

Real signal (AC, long)
newplot-11

@dbuezas
Copy link
Contributor

dbuezas commented Feb 4, 2023

Oh, interesting, the receiver is affected too?
I'm not sure I got you right: Does the transmitter also works when the wdt is fed (as long as interrupts are disabled)?

@i2r
Copy link
Author

i2r commented Feb 4, 2023

Does the transmitter also works when the wdt is fed (as long as interrupts are disabled)?

Yes. Right. Transmitter works when the wdt is fed as long as interrupts are disabled.

@samneirinck
Copy link

Created a PR @ libretiny-eu/libretiny-esphome#6, so at least it doesn't just live on one of our machines.

@kuba2k2
Copy link
Member

kuba2k2 commented Mar 13, 2023

This got closed along with the PR that I merged... thanks to @samneirinck the remote transmitter/receiver should work now 😄
If someone confirms that's the case, I'll close this issue.

@catalin2402
Copy link
Collaborator

Confirm, tested both receiver/transmitter

@kuba2k2 kuba2k2 closed this as completed Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants