element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Forget Me Not Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Forget Me Not Design Challenge
  • More
  • Cancel
Forget Me Not Design Challenge
Blog Forget Me Knot Week 3/4 - Socket to 'em
  • Blog
  • Forum
  • Documents
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: crosseyejack
  • Date Created: 1 Sep 2014 8:09 PM Date Created
  • Views 1014 views
  • Likes 0 likes
  • Comments 5 comments
  • forget_me_not
  • internet_of_things
  • enocean
  • raspberrypi
  • enoceanpi
Related
Recommended

Forget Me Knot Week 3/4 - Socket to 'em

crosseyejack
crosseyejack
1 Sep 2014

Thank to the very nice Tracy over at CPC and doctorcdf I was able to get my hands on a couple of sets of RF Sockets to use in my design. Thank you very much Tracy, it was very much appreciated.

image

So what did I do with them? Well I did what one of my favorite YouTuber's always says. "Don't turn it, take it apart..." :-)

 

First I attacked the remote, upon opening it we were presented with a fairly simple PCB and a single though hole IC and a bank of DIP Switches.

image

Taking a closer look at the IC shows that it is labeled HX2262. A quick Google later shows that it is basically a PT2262 encoder, another Google later and we have the data sheet. But even without the Datasheet we can reverse this remote. While having the Datasheet will help with reversing this remote there is no fun in that. Lets break out the the scope.

 

First thing I did was solder a couple of short wires onto pins 17 and 16 to get a better connection to the IC, pin 17 is the data out pin and 16 is the oscillator pin. This allowed me to capture the waveforms created by the encoder chip and replicate them.

image

If you read the manual (Blah) the set up for the sockets and remote is fairly simple, The DIP sets the "System Code" and this needs to be matched with the sockets. So lets have a look at the sockets too. On the back of the sock there is a cover that also allows access to some DIP switches.

imageimage

But we have 10 switches instead of the 5 in the remote. It turns out that the last 5 are the "Remote Channel" So if you wanted this socked to answer to the A Channel buttons you would set the A DIP switch to ON. So with a bit of maths we can figure out that this remote offers 128 channels ((2^5)*4). Not that great but I guess its enough for most people. But lets have a look at at the waveforms.

 

With all the DIP Switches on the remote set to ON a press of the Channel A ON button gives us the following waveform.image

Multiple presses of the ON button doesn't indicate that the wave form changes so we don't have to worry about any rolling codes. While this does make the sockets less secure it does remove headaches in reversing the remote. If we didn't have access to the datasheet (For Example: If the remote used a chip on board so was a pain to find out the chip used.) we could use these waveforms to basically preform a replay attack. As I found the datasheet lets "cheat" and have a look what is happening here. (I'll attach the Datasheet if anyone else is interested)
image

It turns out that this encoder offers Tri-State bits but looking at the waveform the remote only uses low and floating state which makes sense as the DIP switches are single throw and because they use low bits we can presume that the switch is either tied to GND or are left floating. Armed with this lets try and decode the waveform we captured.

 

image

(Forgive the sloppy text) Turns out its easy to decode the data. So with the System Code on the remote set to "ON-ON-ON-ON-ON" (or GND-GND-GND-GND-GND) It turns out that the code for turning on Channel A is 000000FFFF0F. So what about the other channels? Well I won't bore you with the waveforms for the other channels (Unless people ask for them in the comments, then I will upload them) but leaving the System Code to "ON-ON-ON-ON-ON" Channel B ON = 00000F0FFF0F, Channel C ON = 00000FF0FF0F, Channel D ON = 00000FFF0F0F. Hmmm there is a pattern forming here. Lets format this data a bit better.

Channel A ON00000 0FFFF0F
Channel B ON00000 F0FFF0F
Channel C ON00000 FF0FF0F
Channel D ON00000 FFF0F0F

The Low Bit is shifting along data along with the channel change. As we have already figured out the low bit and I know the remote system code is set to "ON-ON-ON-ON-ON" The first 5 bits must be the System Code. Capturing the waveform while pressing the OFF Button shows that the power state is the last 2 bits of the data.

image

So we now know that the first 10 bits are the address bits. Its was at this point I had a facepalm moment. Of Course it is, Its only the remote that is limited by its lack of button on its interface, the socket gives us access to all these address bits (I later confirmed this which my "custom remote"). With these 10 address bits we have access to 1024 addresses (2^10) which is a much nicer address space to use than the 128 addresses the remote included in the packs offer.

 

So lets get cracking on creating our own remote for these sockets. I decided to code my own, There are libraries out there to recreate these remotes but again, where is in the fun in that :-p

 

As at the time all my Raspberry Pi's pins were being hijacked by the Enocean Pi I decided to first build a simple remote using an Arduino as its fast to code for. Using a cheap 433Mhz transmitter off eBay (When I say cheap these can be picked up for as little as £1 delivered, although they come via the slow boat from China so I ordered from a seller in the UK, while it increased the price by a whooping 100% it did mean I got the transmitter much quicker and £2 isn't the end of the world) and armed with the datasheet I set out writing a sketch to bitbang the signal.

 

Reading the datasheet the signal comprised of a "Code Word" which is 10 Address Bits, 2 Data Bits and a Sync bit, This "Code Word" is repeated 4 times and these 4 Codewords make up the Code Frame, This is what we need to replicate. The datasheet breaks down completely how to create the bits, word and frame. The Bits are just counts of high and low of the data pin depending on the clock of the encoder. Using the scope I was quickly and easily able to figure out that each clock cycle of the IC is 100 microseconds. With all this information I was quickly able to produce a sketch that replicated the signal.




This just toggles the power state of a socket with the address of 0F0F00FFFF but it was enough to prove that the remote could be replicated.

 

Now to add this to the Raspberry Pi. As I said above the Enocean Pi hogs all the pins on the Raspberry Pi A/B and even with the Raspberry Pi B+ extended GPIO there are no power pins on those extra pins. I'm going to hack my way in to get access to the pins. Now a word of warning, the following Pics are gory, anyone who has wielded a soldering iron might be disturbed. My only defence is that I soldered this up at 4 in the morning in a badly lit room. My soldering is not normally this shoddy. We good? Got the kids out of the room? Ok lets carry on.

image

image

image

What I did was grab some protoboard. Soldered in 2 header rows, used my dremel to break the tracks between the 2 rows, bend the though hole pins on a 2x13 socket and soldered them to pins on the underside of the protoboard. This protoboard will now allow me a passthrough for the GPIO Pins allowing me to access the IO pins not in use by the EnOcean Pi.

 

I did consider hacking the EnOcean Pi into having a USB to Serial Convertor but in the end I decided to keep the EnOcean Pi intact. So with this Passthrough board I can easily gain access to 3v3, GND and a I/O pin need to drive the 433Mhz transmitter. The Transmitter is currently powered by the 3v3 rail but it could easily be converted to using the 5v rail and potentially increase the transmitter range, but during my bread board tests the range given by the 3.3 rail covers my home so for now I'm sticking with the 3v3 rail.

 

Now I have the EnOcean and the Transmitter connected to the Pi at the same time I can work on porting the code I wrote for the Arduino to the Pi. For quickness I created a C based command line program to bitbang out the signal.

So now I have a command line program I can call using:

./program <ADDRESS> <POWER> <REPEAT>

Address being the 10 Bit Address of the Socket, Power being either a 1 or a 0 to send either On or Off and Repeat being how many times the Code Frame is transmitted.

 

I need still need to work on this program as it needs root (Well as it access the memory map it will always need root, but I could give the program the right permissions so it can be called by normal users), the GPIO Pin is hardcoded and all the arguments are needed where I could use a default repeat count. But its good enough to take it to the next step of integrating it into OpenHab.

 

In my items file I added some basic switches:

gfdgf
Switch RF_SOCKET_1 "Plug 1"
Switch RF_SOCKET_2 "Plug 2"
Switch RF_SOCKET_3 "Plug 3"
Switch RF_SOCKET_4 "Plug 4"
Switch RF_SOCKET_5 "Plug 5"

In my sitemap file I added some entries of I can access them via the web site:

Switch item=RF_SOCKET_1 label="Plug 1"
Switch item=RF_SOCKET_2 label="Plug 2"
Switch item=RF_SOCKET_3 label="Plug 3"
Switch item=RF_SOCKET_4 label="Plug 4"
Switch item=RF_SOCKET_5 label="Plug 5"

And in my Rules file I added the following:

rule "Plug1On"
when
  Item RF_SOCKET_1 changed from OFF to ON
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0FF0F00F00 1 5")
end

rule "Plug1Off"
when
  Item RF_SOCKET_1 changed from ON to OFF
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0FF0F00F00 0 5")
end

rule "Plug2On"
when
  Item RF_SOCKET_2 changed from OFF to ON
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0F00000FFF 1 5")
end

rule "Plug2Off"
when
  Item RF_SOCKET_2 changed from ON to OFF
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0F00000FFF 0 5")
end

rule "Plug3On"
when
  Item RF_SOCKET_3 changed from OFF to ON
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 000FF0F0F0 1 5")
end

rule "Plug3Off"
when
  Item RF_SOCKET_3 changed from ON to OFF
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 000FF0F0F0 0 5")
end

rule "Plug4On"
when
  Item RF_SOCKET_4 changed from OFF to ON
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 00FFF0FFF0 1 5")
end

rule "Plug4Off"
when
  Item RF_SOCKET_4 changed from ON to OFF
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 00FFF0FFF0 0 5")
end

rule "Plug5On"
when
  Item RF_SOCKET_5 changed from OFF to ON
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0FF0FFF0FF 1 5")
end

rule "Plug5Off"
when
  Item RF_SOCKET_5 changed from ON to OFF
then
  // Issue Command
  executeCommandLine("/opt/openhab/remotetest 0FF0FFF0FF 0 5")
end

And saved all 3 files

These rule's look for the item to change and then fire's off my remotetest command line program to send out the command for the sockets. Time to give it a test. (At the last minute my better quality camera decided to it wasn't going to write anything to the SD Card, shacky low quality phone footage it is then)

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

So as you can see I've managed to get these off the shelf RF Sockets integrated with OpenHAB so they can be controlled though the web interface or through its REST API.

 

So what else have I been up to?

Programming: I've been working on an Android Application to be able to control and monitor the house from my phone. I've got most of the presence detection system working, just a couple small bugs left to iron out of that and I can crack on with the reporting side of the app.

I've also been working on creating my own PHP based interface with the OpenHAB API to be able to give more finer control. For example allowing users to pull data from the system but restricting the data they can push into the system. I might not mind people getting a 12 hour average temperature of my house but more detailed info about my house temperature and the option to control items in my house needs to be restricted. These are coming on nicely but its all under the hood stuff so nothing to show off just yet.

 

Hardware: I've been experimenting with creating some wireless modules to put around my house, these are currently based on an Atmel ATMega328 so I have plenty of both digital and analog I/O and I'm using Microchip MRF24J40MA Wireless Modules to communicate with each other and back to the Pi.

image

These are very much still in the breadboard prototyping stage as I'm still playing with the code to power them and I'm unsure if I want the wireless modules to be always powered ready to receive commands or have them sleep most of the time to converse power and receive the commands I which them to perform when they check in with the Pi. As I also created a passthrough board for the Pi I can also start work on writing the code to get the MRF24J40MA talking to the Raspberry Pi and inturn talking to OpenHab.

 

So plenty has been going on in the background, just sadly not much "Eye Candy".

 

As always drop any questions in the comments and I will happily answer them.

 

Dan :-)

Attachments:
imagept2262_1.pdf
  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 11 years ago in reply to crosseyejack +1
    I have attached the codes to the blog on Outlets http://www.element14.com/community/community/design-challenges/forget-me-not/blog/2014/08/14/forget-me-not-eldermon-outlets The chip doing all the work…
  • mcb1
    mcb1 over 11 years ago in reply to crosseyejack

    Daniel

    There isn't much room spare in the sockets.

    I also found that with one of the brands.


    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • crosseyejack
    crosseyejack over 11 years ago in reply to mcb1

    Thanks for the codes but they will be of no use to me for these sockets. The only logic in these sockets is the decoder IC, The IC itself seems to be a matching latching decoder IC for the encoder, so really the power state only needs to be sent on bit 12 (Confirmed by changing my program to only change the 12th bit for power state).

     

    Reading the datasheet for the decoder chip, it will only take action if the address it receives matches the address selected by the DIP switches. So no single "ALL ON/OFF" for me. But I can always for loop though the all the addresses.

     

    But now I know this, I could hack my way into this plugs. Cut the data line and stick a micro controller and one of the mrf24j40ma modules I have in between. That way the old remotes will still work and I can get 2 way communication out of them. The only issue, space. There isn't much room spare in the sockets.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago in reply to crosseyejack

    I have attached the codes to the blog on Outlets

    http://www.element14.com/community/community/design-challenges/forget-me-not/blog/2014/08/14/forget-me-not-eldermon-outlets

     

    The chip doing all the work is unmarked (as stated) but seems to be a PIC.

    You program the code by holding the button in for xx secs, then press the remote to set the code.

     

    There may be some info on the RCSwitch site ...

     

     

    Thanks for the GPIO info .. I'm still very much learning the inner workings.

     

    Mark

    BTW Nice note to future board makers .... also use the longer socket so they clear the pins and can be used on A, B and B+ versions.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • crosseyejack
    crosseyejack over 11 years ago in reply to mcb1

    There are a few RPi add-ons which hog all the GPIO despite only using one or two.

    Dear future Hat creators, use bloody Extended Tail Through-Hole sockets, or at least replicate the header on the top of your board. Thanks...

    I think you'll find that accessing the GPIO requires root, so you might be able to do it within the rule when you call it.

     

    Well it depends on how fast you want to access the GPIO. We could export the GPIO pins we need at start up as root and then use sysfs to access the GPIO pins we need (http://elinux.org/RPi_Low-level_peripherals#C_.2B_sysfs) Once the pins have been exported any user with the right permission can read/write that that pin. IMO this is the more secure method of doing it as you can could say "User 1 has access to A B C pins and User 2 Has X Y Z pins", but this method requires basically writing to a file every time we want to change the GPIO state.

     

    So I decided to stay away from it as it sounds like too much of a headache for something that could of very easily turned out to be too slow for what I needed and went down the path of direct GPIO register manipulation instead. This does require root but I decided to use a trick I've seen used before in the spincl tool, create a command line tool for the job, give it root permission, place it in an accessible place and chmod 4755 it. This way the user running openhab doesn't need to be root and can access the tool via executeCommandLine()

     

    But for security we need to be careful, the 4755 permission allows all users on the system to execute it. My plan is to give OpenHab its own user and group, once I have done this I can change the group of the tool to the openhab group and change the permission to 4750 which should prevent any other users on the Pi from accessing it. I also tried to secure the tool by checking user inputs, this still isn't perfect and is something I am going to work on but this is something of a "work in progress" tool.

     

    The "Watts Clever" versions of these RF Outlets have a code for ALL ON or ALL OFF, which these may also have as well.

    I'll have to look into the "Watts Clever" version and see if I can pull any information about it. These may have an "All ON/OFF" command as another version from the provider also has the "All ON/OFF" function http://cpc.farnell.com/brennenstuhl/1507473/socket-set-remote-control/dp/PL11275. I've still got to reverse the socket itself, I've taken the cover off one of the plugs and had a quick look but yet to have a close look at the circuity. I doubt there is much in the way of logic in the sockets I have, probably the corresponding decoder IC and a flip-flop attached to the relay which would explain why 2 data bits are used to send the desired power state. Its something I will be digging into. But if they don't its shouldn't be anything a simple for loop won't solve ;-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 11 years ago

    I was embarking on a similar exercise tonight to document the capture ....you bet me to it....image

     

     

    Nice work to integrate the EnOcean Pi and the RF unit....

    There are a few RPi add-ons which hog all the GPIO despite only using one or two.

     

    I think you'll find that accessing the GPIO requires root, so you might be able to do it within the rule when you call it.

     

     

    The "Watts Clever" versions of these RF Outlets have a code for ALL ON or ALL OFF, which these may also have as well.

    They are certainly a much safer alternative than hacking together a relay and the associated wiring.

     

     

    Mark

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube