Mapping Codes for RF Sockets - Efficiently and Consistently
I had requests to explain how to setup the 433Mhz scanner and map out controls. First lets review the code for the scanner.
/*
Example for receiving
https://github.com/sui77/rc-switch/
If you want to visualize a telegram copy the raw data and
paste it into http://test.sui.li/oszi/
*/
#include
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
}
void loop() {
if (mySwitch.available()) {
output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());
mySwitch.resetAvailable();
}
}
With this running we need to capture each button on the remote.
Remote 1 Grey Status Brand Remote and Sockets
In my case if we take a STATUS brand, grey remote it has 9 buttons: 4 on, 4 off and one ALL OFF button
If we note down only some of the buttons now it will we will have to set up the scanner again later which takes time. Its better to map all the buttons of all your remotes in one go.
This is what the scanner recorded for my STATUS brand, grey remote with 9 buttons: 4 on ,4 off and one ALL OFF button
1) ALL OFF,
Decimal: 2727768 (24Bit) Binary: 001010011001111101011000 Tri-State: not applicable PulseLength: 308 microseconds Protocol: 1
Raw data: 9548,296,908,300,904,900,304,316,888,908,300,296,888,308,896,908,332,860,292,308,920,288,916,888,316,888,312,892,316,892,308,892,316,276,920,940,268,292,916,896,304,900,304,304,900,304,896,296,960,
Decimal: 2727775 (24Bit) Binary: 001010011001111101011111 Tri-State: not applicable PulseLength: 305 microseconds Protocol: 1
Raw data: 9552,264,944,264,940,864,316,284,932,872,312,296,944,264,924,880,320,888,308,292,932,276,924,876,308,888,316,888,320,884,324,876,328,268,952,852,340,260,960,844,348,864,312,888,344,856,352,856,396,
Raw data: 9544,288,924,280,920,884,316,284,920,888,320,284,900,304,916,896,296,900,308,292,912,292,912,896,308,888,312,896,312,964,232,888,324,276,928,872,336,272,932,876,320,280,928,880,320,880,320,884,360,
4) 2 ON
Decimal: 2727771 (24Bit) Binary: 001010011001111101011011 Tri-State: not applicable PulseLength: 306 microseconds Protocol: 1
Raw data: 9552,276,932,276,904,892,308,300,904,904,296,304,900,304,900,900,300,900,320,280,920,280,920,884,316,888,324,872,328,880,324,880,316,284,940,864,320,280,940,872,308,888,312,296,924,876,312,892,344,
Raw data: 9536,292,912,296,900,904,300,292,908,900,304,304,900,296,908,900,300,896,308,300,900,300,904,896,312,892,312,888,316,884,316,884,316,292,924,880,316,292,908,892,328,268,916,292,912,888,316,884,344,
Raw data: 9532,296,904,300,904,896,308,292,912,896,340,256,932,272,932,868,332,868,324,284,944,260,948,860,320,880,320,880,320,888,316,884,316,268,956,852,316,280,952,856,316,888,312,888,320,284,936,864,400,
Decimal: 2727765 (24Bit) Binary: 001010011001111101010101 Tri-State: not applicable PulseLength: 306 microseconds Protocol: 1
Raw data: 9528,280,904,300,908,896,304,292,916,888,296,304,912,288,928,872,296,904,316,280,944,260,936,884,328,876,328,872,328,880,312,892,316,276,944,864,316,284,940,868,316,280,940,860,324,280,944,860,360,
Raw data: 9532,288,908,296,900,912,292,308,892,908,296,308,896,304,896,908,292,932,268,316,888,312,900,900,296,904,304,892,316,888,316,884,312,292,936,864,316,284,936,876,300,896,312,892,312,888,308,296,956,
9) 4 OFF Decimal: 2727766 (24Bit) Binary: 001010011001111101010110 Tri-State: not applicable PulseLength: 306 microseconds Protocol: 1
Raw data: 9492,268,920,284,912,888,312,292,912,892,308,296,908,300,900,900,300,904,300,304,896,296,904,900,304,896,312,888,312,888,320,884,316,280,948,856,328,276,952,848,328,272,948,856,320,884,320,280,960,
When I did this I noticed that some of the buttons did not work. I was not using these dead buttons so had not noticed they we dead. I took the circuit board out of the unit added the battery and shorted out the pins of the defective button. By doing this I was able to grab the codes even for buttons that had failed. If you have duplicate remotes use another remote to grab missing buttons.
For these grey Status brand sockets and remotes there is only one type of remote with 4 codes. The sockets are all the same and have to be linked to a button when powered up.
Doing this now means you have all the data for the remote sockets, even if the remote dies or you loose it,
Remote 2 Pro Elec hard coded sockets
Unlike the STATUS brand socket that had to be programmed with a button on the remote when powered on, these Pro-Elec sockets were factory programmed. 3 sockets and a remote with 3 pairs of on / off buttons 1 through 3
1) 1 ON Decimal: 333107 (24Bit) Binary: 000001010001010100110011 Tri-State: 00FF0FFF0101 PulseLength: 173 microseconds Protocol: 1
Raw data: 5448,152,544,156,544,160,540,156,544,164,540,508,180,164,540,516,180,164,552,144,552,144,556,508,180,164,552,504,184,156,556,504,184,156,560,136,564,140,552,148,560,136,564,136,560,144,564,132,556,
2) 1 Off Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 175 microseconds Protocol: 1
Raw data: 5448,152,552,148,548,148,548,156,552,144,548,516,188,148,556,504,192,156,544,156,544,160,540,508,192,148,552,504,216,120,564,500,200,144,556,144,556,140,560,148,552,140,556,148,556,144,560,140,556,
3) 2 On Decimal: 333251 (24Bit) Binary: 000001010001010111000011 Tri-State: 00FF0FFF1001 PulseLength: 174 microseconds Protocol: 1
Raw data: 5440,160,540,160,548,148,552,144,556,152,548,508,196,148,552,548,144,156,552,152,544,156,544,516,184,156,544,516,184,156,548,516,184,156,548,152,552,148,552,148,556,140,548,160,556,140,556,140,568
4) 2 Off Decimal: 333260 (24Bit) Binary: 000001010001010111001100 Tri-State: 00FF0FFF1010 PulseLength: 174 microseconds Protocol: 1
Raw data: 5440,152,552,148,548,156,548,164,532,156,548,512,188,156,548,516,192,144,548,152,544,160,540,520,180,168,536,520,180,160,544,516,180,524,188,512,184,152,544,160,548,512,184,516,184,140,564,156,552,
5) 3 On Decimal: 333571 (24Bit) Binary: 000001010001011100000011 Tri-State: 00FF0FF10001 PulseLength: 174 microseconds Protocol: 1
Raw data: 5452,156,540,156,540,156,544,156,544,160,540,516,184,160,544,516,180,160,548,152,540,168,540,516,188,152,536,524,188,148,552,508,192,148,556,152,548,148,552,148,552,152,552,156,544,148,552,152,544,
6) 3 Off Decimal: 333580 (24Bit) Binary: 000001010001011100001100 Tri-State: 00FF0FF10010 PulseLength: 175 microseconds Protocol: 1
Raw data: 5452,156,544,160,540,156,544,156,536,168,536,520,180,168,532,516,188,140,564,152,548,156,544,508,192,152,548,520,184,148,552,508,196,148,552,144,556,148,552,152,548,156,544,156,548,152,552,152,540,
I'd recommend you press each button at least twice and check the data received looks consistent. This is radio so interference when you record the signal can corrupt the data. Look at this raw dump for button 2 = Socket 1 On for the Pro-Elec sockets, notice how the decimal values are the SAME but the raw data is different each time? The codes in the remote has error correction to remove corrupt data and noise.
Sample data showing noise / variations on the raw data and how the error correction outputs the same number even with different data.
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 175 microseconds Protocol: 1
Raw data: 5448,152,552,148,548,148,548,156,552,144,548,516,188,148,556,504,192,156,544,156,544,160,540,508,192,148,552,504,216,120,564,500,200,144,556,144,556,140,560,148,552,140,556,148,556,144,560,140,556,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 174 microseconds Protocol: 1
Raw data: 5444,168,540,152,548,156,548,152,540,156,548,508,192,152,544,516,192,152,548,144,556,152,552,496,200,148,556,500,200,140,564,492,204,144,560,136,564,144,552,144,560,140,564,136,552,148,552,160,544,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 175 microseconds Protocol: 1
Raw data: 5456,148,552,152,536,160,552,148,552,144,556,500,200,152,548,508,200,136,564,140,552,152,548,508,192,152,560,500,192,160,540,508,192,156,532,172,544,508,188,516,188,508,200,320,376,148,552,148,552,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 174 microseconds Protocol: 1
Raw data: 5444,164,536,156,540,148,556,140,556,160,540,504,196,156,544,512,188,156,548,224,476,152,548,512,204,136,548,516,184,152,552,512,184,156,544,156,544,512,196,504,196,144,556,140,560,148,16,532,148,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 169 microseconds Protocol: 1
Raw data: 5420,176,540,160,540,144,556,144,552,160,536,512,192,148,552,508,196,152,548,148,552,156,544,504,196,160,540,508,192,160,540,524,180,152,548,152,544,520,180,516,188,512,188,512,192,152,552,148,548,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 175 microseconds Protocol: 1
Raw data: 5448,156,544,160,540,160,544,160,536,160,544,508,188,160,544,512,188,156,548,148,556,140,560,492,204,188,516,500,200,148,552,504,192,156,548,156,548,504,192,508,204,496,196,500,200,144,556,160,540,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 175 microseconds Protocol: 1
Raw data: 5460,148,556,144,556,148,548,148,548,156,540,524,184,156,544,500,200,156,544,160,540,156,544,508,192,152,552,504,204,140,556,504,196,152,552,136,564,136,556,152,552,140,560,152,564,128,560,144,552,
Decimal: 333116 (24Bit) Binary: 000001010001010100111100 Tri-State: 00FF0FFF0110 PulseLength: 174 microseconds Protocol: 1
Raw data: 5448,156,544,160,540,152,552,148,548,152,536,500,200,144,556,504,192,152,556,148,548,148,552,508,196,148,552,508,188,152,556,508,184,156,544,160,544,512,188,508,192,156,548,148,556,144,552,148,556,
Remote 3 Second Set of Pro-Elec RF Sockets
I had another set of new RF sockets from Pro-Elec purchased at the same time as the first set. While this second set could be used with the controller from the first set if programmed, out of the box the controller for this second set used different codes. These are the default codes programmed into the sockets at the factory.
So I mapped out this second controller for the Pro-Elec RF sockets.
So I mapped out this second controller for the Pro-Elec RF sockets.
1) 1 ON Decimal: 5575987 (24Bit) Binary: 010101010001010100110011 Tri-State: FFFF0FFF0101 PulseLength: 174 microseconds Protocol: 1
Raw data: 5404,140,552,496,192,148,552,492,192,148,552,492,200,144,552,492,200,140,560,132,556,140,552,492,200,140,560,488,196,144,556,488,200,144,556,132,560,488,200,492,204,136,560,132,560,48,604,20,172,
Raw data: 5404,140,552,496,192,148,552,492,192,148,552,492,200,144,552,492,200,140,560,132,556,140,552,492,200,140,560,488,196,144,556,488,200,144,556,132,560,488,200,492,204,136,560,132,560,48,604,20,172,
2) 1 Off Decimal: 5575996 (24Bit) Binary: 010101010001010100111100 Tri-State: FFFF0FFF0110 PulseLength: 172 microseconds Protocol: 1
Raw data: 5380,156,536,504,188,160,540,500,184,160,540,500,188,160,544,492,192,156,544,148,544,148,540,500,192,152,544,496,196,148,548,492,196,152,544,148,544,496,196,496,200,496,200,492,196,148,548,144,548,
Raw data: 5380,156,536,504,188,160,540,500,184,160,540,500,188,160,544,492,192,156,544,148,544,148,540,500,192,152,544,496,196,148,548,492,196,152,544,148,544,496,196,496,200,496,200,492,196,148,548,144,548,
3) 2 On Decimal: 5576131 (24Bit) Binary: 010101010001010111000011 Tri-State: FFFF0FFF1001 PulseLength: 172 microseconds Protocol: 1
Raw data: 5380,160,532,508,184,160,536,504,188,160,536,504,188,156,540,500,192,156,540,152,540,152,540,500,192,152,544,496,192,156,540,496,196,500,192,500,196,152,544,148,544,152,544,144,544,152,540,152,540,
Raw data: 5380,160,532,508,184,160,536,504,188,160,536,504,188,156,540,500,192,156,540,152,540,152,540,500,192,152,544,496,192,156,540,496,196,500,192,500,196,152,544,148,544,152,544,144,544,152,540,152,540,
4) 2 Off Decimal: 5576140 (24Bit) Binary: 010101010001010111001100 Tri-State: FFFF0FFF1010 PulseLength: 172 microseconds Protocol: 1
Raw data: 5376,160,540,500,188,156,540,500,192,156,540,500,188,156,540,500,192,156,536,156,544,144,544,496,196,152,544,492,192,156,544,496,192,152,540,156,544,148,540,156,540,148,548,144,540,156,536,152,540,
Raw data: 5376,160,540,500,188,156,540,500,192,156,540,500,188,156,540,500,192,156,536,156,544,144,544,496,196,152,544,492,192,156,544,496,192,152,540,156,544,148,540,156,540,148,548,144,540,156,536,152,540,
5) 3 On Decimal: 5576451 (24Bit) Binary: 010101010001011100000011 Tri-State: FFFF0FF10001 PulseLength: 172 microseconds Protocol: 1
Raw data: 5388,152,536,504,188,156,544,496,192,156,536,504,188,156,536,504,192,156,540,152,540,152,540,500,196,148,540,496,200,148,540,500,196,148,544,152,544,148,544,148,540,152,540,152,540,152,540,152,540,
Raw data: 5388,152,536,504,188,156,544,496,192,156,536,504,188,156,536,504,192,156,540,152,540,152,540,500,196,148,540,496,200,148,540,500,196,148,544,152,544,148,544,148,540,152,540,152,540,152,540,152,540,
6) 3 Off Decimal: 5576460 (24Bit) Binary: 010101010001011100001100 Tri-State: FFFF0FF10010 PulseLength: 172 microseconds Protocol: 1
Raw data: 5376,160,528,516,168,176,532,504,176,172,532,508,172,172,532,508,176,172,532,156,532,164,532,508,176,168,532,508,180,512,180,512,184,164,532,160,540,152,532,160,536,504,180,512,192,156,532,24,676
Raw data: 5376,160,528,516,168,176,532,504,176,172,532,508,172,172,532,508,176,172,532,156,532,164,532,508,176,168,532,508,180,512,180,512,184,164,532,160,540,152,532,160,536,504,180,512,192,156,532,24,676
Remote 4 Old Set of 418 mHz RF sockets
I had a last set of sockets that would not be recognised by the receiver. This was a very old set with DIP switches. I noticed inside the remote is said 418mHz so that would explain why the 433mHz receiver would not detect them!
Conclusion
Now I have these codes the first thing to do is to store the data safely somewhere where I can get to it later so I do not have to run the receiver program again. Also I need to include them in a test sketch with the transmitter to see that they actually work when used with the socket.
I do this with a web server, and wget calls from Kodi for my AV room setup see my last post.
Its worth pointing out I had a number of issues setting up the receiver both the first time I ran the code a week ago and the second time today! Lessons worth remembering...
- Use the advanced demo receiver in the RC-Switch library sample as simple demo receiver never works for me!
- Keep the pin for the recived data as PIN2 as with some of the Unu boards I had other stuff was using other pins and Pin2 worked fine. The software is interrupt based so you need a pin with interrupt support.
- The receiver for 433mHz only works with a 5V supply to VCC/GND so you CANNOT use an ESP8266 based unit for the receiver.
- 8266 based units connected to 433mHz transmitters work fine on 3.3.V but will also work fine on 5V.
Pros
- No mains wiring just plug the consumer grade sockets in and you are done
- These units are cheap, really cheap to purchase
- The 433 mHz transmitter / receiver circuit boards are super cheap. I got 5 pairs of transmitters and receivers for around £1 delivered from Ali-Express.
- Code for arduino to handle RF sockets is robust and mature
- If you link the 433mHz transmitter to an 8266 based board you can control the relays over Wifi using a web page.
- The web page can be called from a phone widget or a shell script in Linux / Windows / Mac e.g. I use the wget command in a shell script that runs when a specific button on my TV remote is pressed. This fires up the Amp, Powered Sub, and 9 powered speakers and the TV. Another button turns this all off!
Cons
- The codes used by the remotes need to be scanned in (just once) and documented for later use. This can be tedious and error prone.
- The 8266 based units have the WiFi SSID and password hard coded - far from ideal both from a setup point of view and a security standpoint
- The NTP services on the 8266 boards work well but for sun rise / set calculation its a lot of work, so I think I'll opt for a server based cron job running on an Orange Pi Server running Armbian.