It’s been over a month since I received my spark core. Since then, I have been playing with examples and tutorials around here while keeping a lookout for an ideal project to start with. Recently, I came across these RF remote controlled outlet switches. I paid $20 for 5 outlets and 1 remote which I figured is a good deal. Now, I am planning to hack the remote and hook it up to core. This way I can control 5 devices over the internet for only 60 bucks!
The idea is simple and dirty. Spark is gonna simulate the button pressing on the remote. I understand this is not the best way to hack a remote but I don’t have a logic analyzer handy to monitor the signal being sent to the RF transmitter. It would have been nice to be able to reverse engineer the remote and let the core send the signal to transmitter instead. It would have allowed me to add more outlets in future without any hardware change. However, I figured the quick and easy fix is good for now since I don’t have many devices to control over the internet anyway. Also, I am growing impatient. It’s time I could turn on the window fans at home before leaving work so as to come to a much cooler house .
Now having justified the hacking method, lets get to the task at hand. The remote has 10 buttons for 5 outlets. On and Off are separate push buttons (normally open). All I have to do is short the corresponding switch electrically to simulate the button press. I figured optocouplers would be perfect here. Spark would issue a high on one side and on the other side the transistor turning-on will short the pushbutton. Isolating the two sides is probably a good idea. I ordered these optocouplers from sharp(?) at amazon because they got delivered very fast and free. The datasheet is not too accurate. I did some tests to find out that 2.0 V at 10 mA forward current is needed to turn-on the transistor on the other side. It felt this should be a good operating point well within core’s abilities. I did some tests with core and things worked out fine. Nice and simple so far.
I am planning to charlieplex the inputs to the optocouplers. This way I will be using only 4 pins for 10 optocouplers and saving plenty for future extensions. Over the weekend, I will finalize the schematic and send the board for fabrication. I haven’t thought much about the firmware and web side of things as I imagine it to be fairly simple. Functionally all I need is a web interface with buttons for each outlets. In the firmware, I will have a spark function taking the outlet number and state as inputs. I will have all the pins tri-stated in the setup. In the function, first the two corresponding pins will be set to OUTPUT and LOW and then one of them will be set to HIGH for 100 ms. I will set them to INPUT and return.
I understand there is a similar project already done with spark and shared in the community. Unfortunately, a lot of my design was already done before I found this resource. It’s a helpful read, nonetheless. Thanks @Carsten4207
This is my first project with spark and I hope to add more functionality and hardware as my understanding evolves. I will share pictures, schematics and code as soon as everything is ready. My idea here is to share the project while it’s still in preliminary stage so that I can iterate the design with other member’s input. Please let me know your thoughts/concerns about design, feasibility and additional features that I can incorporate at this time.
Thanks for pointing out the faulty link. I have fixed it.
I don’t have a question so far. I just wanted to share my project early in the process so as to get valuable suggestions from the community.
Sorry, I did not recognized that you postet in ‘Project Share’.
The optos looks nice, I never tried to control a remote with them.Please update your experience here,
The other way to achieve this is to use cheap little TX modules to bypass the remote and talk direct to the switches.
Check out tx control which describes it based on arduino but pretty easy to port to Spark and get Wifi control. RC Switch is already available as Spark library
Thanks @bobtidey. This looks interesting. It’s not difficult as I imagined after all. This way I will not be limited to 5 outlets, which would be nice.
RF remote outlets you mentioned probably run on 433MHz. You can check out my tutorial from Make Things Berlin which uses RC-Switch library (available in Community Libraries in Build) to emulate the remote so you won’t need optocouplers.
Thanks @suda. The tutorial is very well written. I am now in half mind to switch over from my shady technique. Too bad I have already send the PCB out to fab.
PCBs came back from fab and everything looked in place for assembly. However, I have run into trouble with core firmware. I didn’t see this problem posted so am sharing here.
I have 5 spark functions corresponding to five outlets I want to control. However, only the first 4 functions declared are being exposed. I checked this by changing the order of declaration querying for exposed functions. The results are below: Result#1 (function declaration out 1 through 5) https://api.spark.io/v1/devices/Device_ID/?access_token=My_AccessToken
{
“id”: “Device_ID”,
“name”: “Device_Name”,
“connected”: true,
“variables”: {},
“functions”: [
“out1”,
“out2”,
“out3”,
“out4”
],
“cc3000_patch_version”: “1.29”
} Result#2 (Out 5 is declared first and out 4 last) https://api.spark.io/v1/devices/Device_ID/?access_token=My_AccessToken
{
“id”: “Device_ID”,
“name”: “Device_Name”,
“connected”: true,
“variables”: {},
“functions”: [
“out5”,
“out1”,
“out2”,
“out3”
],
“cc3000_patch_version”: “1.29”
So, I am not sure why only 4 out of 5 functions are being exposed. Is this a RAM issue? Is there a limit of number of functions? I can share my firmware if anyone wants to replicate. On web side, I have forked the Remote Spark app by @BDub. Any insights would be very helpful. Thanks!
Another interesting thing happened earlier today. I thought I should share since i am here. My core started breathing blue. I did a factory reset. The app failed to find the core. I decided to do a USB transfer of credentials. Connected the core to the computer instead of battery pack and after few seconds the core was online! I was of idea that a factory reset erases wifi credentials. Is that not the case?
You can consider using 1 function that takes in the string and run the code for it.
Example from docs:
// EXAMPLE USAGE
int brewCoffee(String command);
void setup()
{
// register the Spark function
Spark.function("brew", brewCoffee);
}
void loop()
{
// this loops forever
}
// this function automagically gets called upon a matching POST request
int brewCoffee(String command)
{
// look for the matching argument "coffee" <-- max of 64 characters long
if(command == "coffee")
{
// do something here
activateWaterHeater();
activateWaterPump();
return 1;
}
else return -1;
}
Thanks ken for such a prompt reply. I remember reading the limitation on number of functions at some point but totally forgot about it until now. Thanks for the tip. Its a better way to do it.
Sorry I was not clear earlier. I didn’t have to perform a USB transfer of credentials. The core just magically came online when plugged through the computer’s USB port. I suspect it’s the power reset that got it to connect. What I still can’t seem to figure out is how it remembered my credentials. I also want to add that I restarted my router at some point in the troubleshooting process. Thanks again!
Hello everyone,
I ended by making two versions of the project. The first design used optocouplers to simulate button press on remote. The second one uses @suda’s RCSwitch library. I also ended by making an android app with the help of MIT app inventor 2. Pictures below:
PCB Top copper
PCB Bottom copper
Optocoupler design (v1) closeup
Optocoupler design (v1) mounted with ‘spark wall socket’
If anyone is interested, I used this nokia wall charger AC-16U to power spark core. It’s fairly small, results in a compact form factor and not very expensive.
Switching on the Raspberry Pi running XBMC through spark is really fun as it boots up my TV and AV receiver.
I also wrote a python script and scheduled it’s execution through windows task scheduler. The patio lights now turn on at dusk and turns off before morning. Pretty sweet.
Thanks everyone for your help. It’s been a fun project.