Post topics, source code that relate to the Arduino Platform

User avatar
By anil8anil
#81657 Hi, i have been working on an iot project that i toggle 220v ac with a relay by internet connection and also 433 mhz rf connection. I send rf signals with a cheap wall transmitter. I use rfswitch (https://github.com/sui77/rc-switch) library in my iot project for rf connection. I use ESP-01 as mcu.

Problem:
When i short press (<0,5sec approx.) transmitter's button, usually i cannot receive the signal (i receive 1 of 5 maybe) but if i long press transmitter's button, i receive the signal everytime.

What have i tried:
- Same problem occures when i try that with a nodemcu (same library, same rf receiver and same sketch)
- Problem doesn't occure if i try the same on an arduino uno board (same library, same rf receiver and example receive sketches of the library)
- If i erase esp-01 and upload my sketch but dont set wifi credentials, there is no problem.

My researches:
- i am not an expert. But i think the problem is about interrupts of 433 mhz library. There is a github issue (https://github.com/sui77/rc-switch/issues/46) about adding ICACHE_RAM_ATTR to interrupt fuctions. And according to that issue, there is new lines of codes in the library in the new releases. But my problem continues.
- Then i realized that the problem is not only about rcswitch library. In an issue at arduino forum (https://forum.arduino.cc/index.php?topic=583166.0) i saw interrupts fail while wifi is enabled. I saw some discussions that if i disable interrupts before wifi connection fuctions and then enable them after those functions in the esp8266 wifi library, the problem may be solved. But i dont know how to... I know i call some wifi functions in my sketch an dalso some wifi fuctions are called during delays and after loop() is completed.

Do you have any idea what to do about my issue? Thanks in advance.
User avatar
By Spackstor
#82069 As you have verified, Code dependent, the ESP spends some time in wifi mode and can miss some incoming rf. I have limited expertise also, but assuming you need a wifi module you may also need to dedicate a nano or similar device if a single button push is mandatory.
User avatar
By swe-dude
#88183 if you are using rc switch, have you tried increasing int RCSwitch::nReceiveTolerance = 60; in RCSwitch.cpp

If not do so, depending on the signal you are trying to receive you can increase this quite a bit, try maybe 90 to 150, you might end up with some random signals if you increase it too much thou.

in the same file you can also try changing this:
if ((repeatCount==0) || (diff(duration, RCSwitch::timings[0]) < 200)) {

increase from 200 too to 400 maybe.

changing these helped me receive signals i missed before, might be worth a try, Good luck.