Remotely turning on and off an output

Does anyone have example code to simply turn on and off an output pin on an April board that can be controlled remotely from my smart phone or computer? It seems the blink o matic only responds to the tick-tock and the GPIO example requires two impees.

Tick tock is just sending 1’s and 0’s. If you hook up an HTTP IN block instead, then copy the HTTP IN URL and append the string:

?value=0

…to send a zero, or:

?value=1

…to send a 1. When you access that URL from anywhere, 0 or 1 will be sent to the april.

Hi this will work from your PC or Mac others have used it too.
Save the code from pastebin to a .html file on pc/mac and run from file http://pastebin.com/LV7iGVey
I send the value 10 for ‘off’ & 11 ‘on’ etc but you can send a string to the imp.
Add the details from your HTTP IN to the code.

Ruining a web page to do the same from your smart phone is a bit more trickier do cross site security etc. If you have access to a PHP server I can send you some code that has allowed me get things working.

Thanks. I am looking for something even more simple. The tick tock node keeps sending 1’s and 0’s to another node. Is there a node that can just send a 1 or 0 to another node when a button is pressed in the Planner? I am basically just trying to control a light from my smart phone in the most simple way possible.

The planner is intended to set things up, not control them, hence no switch icon.

As I said above, use HTTP in. You can then save bookmarks on the phone for both on and off URLs, and just load them on the phone to control the device. I do this myself :slight_smile:

That should work for me. How do I edit the HTTP in node so I can enter the URL which sets the output to 1 and 0?

Can I set it so that, for example, when I go to google.com, it sets output to 1 and when I go to bing.com it sets to 0?

No, you have to go to the URL listed in the HTTP IN node (see above) - click the tool icon on the HTTP IN block and you will see the URL.

The imp has no idea what websites you visit around the web, you need to visit the imp “api.electricimp.com” site to tell it something.

OK I think I might be in over my head with this as a hobbyist. The only experience I have is with basic digital I/O on the arduino. I thought I would be able to apply that to the electric imp to control I/O remotely but it seems like it will be much more complicated.

Don’t give up yet, I am in the same boat as you are, but I have been able to figure out how to toggle a pin on and off from a web page that I made on google sites, but it will only let me control outputs and not see any inputs, so I am making a web server at my house to let me get a little better control and really work with the imp!

@diggitydug: It’s not really that complicated, but maybe we need a tutorial with more pictures up on the wiki.

Like I said, you just click add node, HTTP IN, the new block appears, you connect it to your imp, then you click the tools icon on the HTTP IN block and you will see a URL that is a direct reference to your HTTP IN - when you access this from anywhere in the world, you can send data to your imp.

So, you take that URL and add “&value=x” to the end of it to send the value “x” to your imp. Pretty straightforward!

If you want to use the planner to send a value, you can use the imp.configparams table and a callback function. Here is an example from the devwiki:

`function configParamsChanged()
{
server.log(“config parameters have changed”);
}

imp.configure(“My Impee”, [], [], {period = 30.0}, configParamsChanged);`

So I add “&value=0” to the URL? The URL should be: https://api.electricimp.com/…&value=0 ? When I do that, it says “node not found”. When I don’t add anything, it just says “OK” on the screen. So now I have the HTTP in node and the Light Controller example from the wiki on the planner and not sure what to do next.

Yep, just adding that (or value=1, etc). Sure there’s no digits changed before the &?

“node not found” means the second set of digits in the URL (which refer to the node) isn’t right in some way. Note that if you delete and re-create an HTTP IN node, it’ll be a different node number.

In a previous post you state I should use “?” not “&”. Which is correct?

Sorry, ? is correct as the separator between the HTTP IN URL and the value= bit. If you have multiple things to send, you append them after the ?, and separate them with &.

Does this output to a specific channel? Do I need a channel parameter? If so, how? You have been a great help so far. I really appreciate it.

It goes to channel 1. If you don’t specify a channel then it goes there.

You can hook up a “show input” block to the HTTP IN if you want to see what’s being sent without involving an actual imp at first.

Do you have a basic code example that takes this input and changes the state of one of the output pins accordingly?

Actually I figured it out. Thanks for all your help, Hugo. I think many users would want to just remotely turn on an output so you may want to add a tutorial for this to the wiki.