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

Connecting the two receivers #25

Closed
MeJIyA opened this issue Jan 17, 2016 · 13 comments
Closed

Connecting the two receivers #25

MeJIyA opened this issue Jan 17, 2016 · 13 comments

Comments

@MeJIyA
Copy link

MeJIyA commented Jan 17, 2016

The problem is when you connect the two receivers(315MHz and 433MHz). In consequence of using a variable of type static, it overwrites data in a single memory controller.

@fingolfin
Copy link
Collaborator

It's very hard to understand what you are saying.

But I am guessing you are requesting support for using two receivers simultaneously, which is currently not possible.

Unfortunately, there seems to be no "elegant" way to fix this. The problem is that RCSwitch::handleInterrupt has no way to know for which pin respectively interrupt it was invoked.

Since RCSwitch::handleInterrupt does not know the source of the interrupt, we cannot use it to pass data to multiple RCSwitch instances.

This is a limitation of the Arduino interrupt handling system, it seems :-/.

@fingolfin
Copy link
Collaborator

One hackish workaround: If we arbitrarily limit ourselves to e.g. 6 interrupts, we could provie six "outer" interrupt handlers; then modify attachInterrupt to use the correct handler for each interrupt. Next, we'd use a small global array to lookup which RCSwitch instance is assigned to which interrupt, and dispatch to that.

But that is still limited in flexibility and somewhat ugly. Hrm.

@MeJIyA
Copy link
Author

MeJIyA commented Jan 18, 2016

Sorry for my English. Thanks for the answer.

@sui77
Copy link
Owner

sui77 commented Jan 18, 2016

Another dirty hack that might work would be switching between both receivers once every second. Of course with the risk of missing some signals, depends on your needs.

void loop() {
mySwitch.enableReceive(0);
delay(1000);
mySwitch.enableReceive(1);
delay(1000);
}

@MeJIyA
Copy link
Author

MeJIyA commented Jan 19, 2016

sui77 Thank you. But I do not fit this option, you must monitor two frequencies at once. I implemented without interruption. But the accuracy lutshe wants to be, although operational.

@MeJIyA
Copy link
Author

MeJIyA commented Jan 19, 2016

Still managed to use the hack . delay ( 200 ) and set the tolerable results obtained .
Hedgehog Thanks again sui77.

@sui77 sui77 closed this as completed Feb 10, 2016
@bilogic
Copy link

bilogic commented May 22, 2016

Is there a reason why the class uses static definition? as in RCSwitch::?
I had the same need for 2 receivers and added code for a 2nd detection buffer. I can share the code if it helps, but I thought the best way was to use a non static approach.

@MeJIyA
Copy link
Author

MeJIyA commented May 23, 2016

Thank you , I have long been solved the problem of writing separate code to the second receiver .

22 травня 2016, 12:53:35, від "bilogic" < notifications@github.com >:

Is there a reason why the class uses static definition? as in RCSwitch::?
I had the same need for 2 receivers and added code for an 2nd detection buffer. I can share the code if it helps, but I thought the best way was to use a non static approach. —
You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@fingolfin
Copy link
Collaborator

@bilogic The class uses static definitions because Arduino interrupt handler callbacks sadly only can access static / global data; and interrupt handlers cannot easily be shared for different users. In particular, they have no void *refCon parameter, which many other callback based APIs offer.

So I am really curious to learn how you bypassed that problem. But please let's not put it onto this old, closed issue; instead, submit a pull request, and/or a new issue where you explain your changes.

@MeJIyA
Copy link
Author

MeJIyA commented May 23, 2016

My level of English is low and I did not understand everything. But answer me more . I used the library on the same frequency , but dorabatival library. I added Oregon and Lacrose. I also added support for long codes for other sensor types. In the future, when I will modify the code I'll post the code . At the time of Danian though workable but not beautiful .
Another receiver potsepil I just interrupt and organized another function but to recognize only one protocol .
I just I measure the duration and analyze the code and decodes it . Though excessively but it works.
23 травня 2016, 10:17:45, від "Max Horn" < notifications@github.com >:

@bilogic The class uses static definitions because Arduino interrupt handler callbacks sadly only can access static / global data; and interrupt handlers cannot easily be shared for different users. In particular, they have no void *refCon parameter, which many other callback based APIs offer.

So I am really curious to learn how you bypassed that problem. But please let's not put it onto this old, closed issue; instead, submit a pull request, and/or a new issue where you explain your changes.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub

@bilogic
Copy link

bilogic commented May 23, 2016

@fingolfin, @MeJIyA my codes and suggestions are on #63

@Mshad0w
Copy link

Mshad0w commented Oct 26, 2019

hi,
great job...
as another hack ,if you include <PinChangeInt.h> library to RCSwitch.c,
and replace this line in RCSwitch::enableReceive() functon:
attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);
with :
attachPinChangeInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);
receive function can be attached to every other pins of board,by adding pin number in enableReceive(pin_number) routin...
useful for nodemcu , esp8266 and etc...

@AKTanara
Copy link

AKTanara commented Jul 20, 2021

I solved this problem by simply duplicating the library with new name "RCSwitch2" and created the second receiver instance with that library. It worked perfectly. So if you are interested in this solution it is just enough to copy the library to another folder with name "RCSwitch2" and replace all "RCSwitch" phrases in the files with "RCSwitch2". This is most easily done by Notepad++ in few clicks.
2021-07-20_190125
2021-07-20_190520
ATTENTION: Just be careful not to have main library files open in Notepad++ otherwise it would replace instances of the word in those files too.
PS: If this issue is solved by just duplicating the library for the second instance of receiver, it has nothing to do with hardware limitations of handling interrupt pins and it is all about misuse of STATIC variables and definitions:
2021-07-20_191724
PS2: Probably the culprits are these three static variables defined in handleInterrupt() method:
2021-08-12_180229

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

6 participants