Started developing home assistant custom stuff some weeks ago and cannot get thread synchronization to work. Hoping for some ideas from other developers out there…
My case is:
I have one common class handling Rx and Tx of 433Mhz traffic via a cheapish Tx /Rx module I have connected to pins 17/27. Pretty basic stuff as seen in many threads. Both Tx and Rx work flawlessly when used independently.
When I activate both Rx (which is supposed to be run “in the background”, just collecting 433MHz traffic such as my temp/hum sensors and Tx (flicking light switches via Nexa outlets), I get poor Nexa outlet switch response. Since it works flawlessly when disabling the Rx module, I have concluded that it is due to my Rx handler. It makes perfect sense, as my transmitting antenna is just some 50cm from my receiver. Of course the Rx module picks up everything that is Transmitted. Each pulse being detected will cause an edge detect callback via GPIO and this will inevitably take some time to handle.
The tx pulses needed are in the range of about 100us up to about 10ms, thus an interrupt of maybe 100us would obviously mess my transmission up. 50us probably would too. Hard to tell.
So, my solution to the problem (coming from the embedded world) would be to just disable interrupts (not so easy on a Raspberry pi I guess) or at least create some kind of critical region where the Rx module cannot pick up any GPIO edges.
So far I have tried the following without success:
- Set the GPIO Rx pin as output during the transmission.
- Do the whole transmission with RLock():
- Use a class static variable which acts as a semaphore, Tx starts when it is released and grabs it so that the rx_callback is not allowed to act on its input pulse.
The code I have is based on the rpi_rf component which some changes to make my sensors detected and my Nexa outlets react correctly.
The rpi_rf component does have logic saying that it is not possible to enable rx if tx is enabled and vice versa, so I guess the problem is not trivial at least.
Any help appreciated.