C#, Hardware, IoT

RCSwitch for Windows 10 IoT

RCSwitch is a library for controlling remote power sockets from Arduino. The original source code by Suat Özgür can be found on GitHub.

In combination with the MX-FS-03V sender MX-05V receiver, I wanted to do the same thing on Windows 10 IoT on my Raspberry Pi. To use RCSwitch in a Windows Universal app, I ported the library into a C++ Windows Runtime Component.

The RCSwitch port to the Windows Universal Platform is now available on NuGet.

To use it in your IoT project, just install the NuGet package and then copy these code samples:

Create an instance of the RCSwitchIO class:

// connect sender to GPIO6 and receiver to GPIO5
RCSwitchIO rcSwitch = new RCSwitchIO(6, 5);

Turning remote power sockets on/off:

// turn device 11011 10000 ON
rcSwitch.Switch("11011", "10000", true);
// ...
// turn device 11011 10000 OFF
rcSwitch.Switch("11011", "10000", false);

In good .NET fashion, you can also subscribe to an event to listen for incoming signals:

//attach the event handler for receiving signals
rcSwitch.OnSignalReceived += RcSwitch_OnSignalReceived;

private void RcSwitch_OnSignalReceived(object sender, Signal signal)
   Debug.WriteLine($"received: {signal.Code} via protocol {signal.Protocol} with bitlength {signal.BitLength}");

However I found that receiving does not work very reliably. Initially I was able to sometimes receive signals, but a few weeks later (with a different remote) it didn’t work at all. Any help in debugging the receiveProtocol methods that handle the interpretation of interrupt timings is appreciated. You can find all source code including a test and example project on GitHub.


Leave a Reply

Your email address will not be published. Required fields are marked *