-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Comments
Not implemented in esphome yet. You could try changing #ifdef ESP32 to LIBRETUYA and there's a slight chance it will work. |
I honestly didn't have to work too hard to get the |
#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 |
@catalin2402 is there specific instruction to do that? How do I modify the remote_transmitter & receiver .cpp files? |
where you see #define ESP8266, change it with |
thanks! @catalin2402 , modified the line in remote_receiver_esp8266.cpp
|
@ferbulous try to set
|
@catalin2402 thank you! Compiled successfully. Now trying to find pin with transmitter connected (without opening device).
|
I've been running a 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. |
@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. |
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. |
@RoganDawes no, i do not have it =( |
If anyone of you got the receiver/transmitter to work, feel free to open a PR! |
@RoganDawes is it possible to analyse transmitted signal by recording raw data by the device's receiver?
|
Thanks, but now I'm getting this error
Any other changes I need to make to the yaml or LT files?
|
If not, you need to change *.h file too: |
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. |
Thanks! that fixed it, on both the receiver.h & transmitter.h |
@i2r hi, not much success yet with transmitting (i keep pressing the button repeatedly)
|
@RoganDawes I added some logging and seems that computed signal is correct:
But received signal is not:
|
You may find this tool useful for visualizing, comparing and debugging raw patterns |
Example:
But for tests i use
|
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 I think the first two numbers in the code |
Anyway it sends random numbers:
|
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 |
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:
Using @dbuezas's excellent tool, this looks like this: With a different made-up sequence: I'll see to add some additional logging to see if this reveals more. |
I'm confused, is that remote transmitter/receiver for IR remotes, or 433 MHz remotes? |
😃 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. |
@i2r
For my raw codes, i should just output all the codes to a single line?
|
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. |
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. |
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? |
With esp32s2 signal is correct every time, I tested. So transmitting at bk7231 is broken. Looks like there are interrupts at transmission time. |
I see. Is reception also affected? |
Seems reception is not effected. But I will check with transmitting by esp32s2 and receipting with bk7231. |
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 |
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. |
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. |
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 :) |
Oh, I think you'll also need to replace the delayMicroseconds with a busy loop: } else while (this->target_time_ > micros()){ /*busy loop that ensures micros is constantly called*/}; |
👏 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? |
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 ... |
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. |
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. |
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 |
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 |
@dbuezas the signal is correct with your tweaks! Receiver is disabled. Re-added the feed_wdt calls. |
Oh, interesting, the receiver is affected too? |
Yes. Right. Transmitter works when the wdt is fed as long as interrupts are disabled. |
Created a PR @ libretiny-eu/libretiny-esphome#6, so at least it doesn't just live on one of our machines. |
This got closed along with the PR that I merged... thanks to @samneirinck the remote transmitter/receiver should work now 😄 |
Confirm, tested both receiver/transmitter |
Hi. Thank you for great work.
Trying to compile firmware for bk7231.
Adding component:
Causes compiling error:
The text was updated successfully, but these errors were encountered: