Need Better Examples

I am wondering if you can link me to some good examples of something similar to what I want to make. I want to make a web page with 4 Buttons (3rd party hosted). When you press one, something is sent to the agent, the agent sends it to the board, and an LED comes on. I yet to find ANY documentation how to do this.

@eviltwinzzz try this tutorial I did two button mobile web app/agent/device http://industrialinternet.co.uk/eimp/t2_digital_out/index.html

I’ve hosted the web app so you can use to test just need click the gear icon in menu and enter your agent url. Your free to copy all code and extend no buttons etc. http://industrialinternet.co.uk/eimp/t2_digital_out/app.html

Your question doesn’t have enough information. You say “web page”. Is it a page where 100 people could be viewing it, and anyone can turn on and off the LED’s at the same time? Is the page ‘static’ HTML, or continuously updated using JQuery/javascripting? Are you able to use PHP?

It’s important to know that information because it’s really easy for a simple HTML static form to turn on or off an LED. The hard part comes where you need a PHP script to query the Imp before displaying the form. The web page has no way of knowing which LED’s are already on or off unless it can query the Imp.

PHP will need to be used so that you can hide the Imp’s URL from the users. PHP is also necessary if users must log-in to enable control.

So you’ll have to be more specific about your requirements.

I am not too concerned about multiple users or one user, whatever leads to me remotely turning things on and off, my upgraded Cable internet has web hosting, so I have access to php, java etc. Mlseim, I would love to see working examples of what I am trying to do, I appreciate your response. I realize now this is something sold as fun and LEGO simple, but is more like building a pyramid.I am not concerned about the page knowing which LEDs are on or off, I know it will fight me for every inch for every second to not give any feedback from imp-agent-page-user. I appreciate any help I can get on this.

Below are 4 scripts that demonstrate the most basic example of all.

You have these scripts:
agent: this is the Imp agent
device: this is for the Imp itself
test.html : this is for your website, so you can send values to the imp
send.php : this is for your website, actually sends the value to the imp using your secret Imp URL ID.

This example has no buttons. It just demonstrates how to send a value from the webpage to the Imp. The Imp Device can decide what to do with the value.

`

AGENT

http.onrequest(function(req, resp){
if (req.method == “POST”){
local body = http.urldecode(req.body);
server.log(body.data);
device.send(“data”, body.data);
}
resp.send(200, “OK”);
});

DEVICE

// Define your Imp output pins
hardware.pin9.configure(DIGITAL_OUT);
hardware.pin8.configure(DIGITAL_OUT);
hardware.pin7.configure(DIGITAL_OUT);
hardware.pin5.configure(DIGITAL_OUT);

// If the agent has sent a value, display it in log
agent.on(“data”, function(value) {

// The value received should show up in your server log.
server.log(value);

// Just do one pin for now
//
// A value of 9 Turns On Pin 9
if(value==9){
hardware.pin9.write(1);
}
// A value of 90 Turns Off Pin 9
if(value==90){
hardware.pin9.write(0);
}
});

PHP SCRIPT … call this “send.php”

<?php //set POST variables $v=0; if($_POST['data']){ $v = $_POST['data']; } // Put your Agent URL Code on this line ... $url = 'https://agent.electricimp.com/g4NegFub5Y2w/'; $fields = array( 'data'=>$v ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, false); //execute post $result = curl_exec($ch); //close connection curl_close($ch); ?>

HTML PAGE … call this “test.html”

Imp Test Value to Send: `

Thanks a million for this info. You have saved me so much time, I hereby promote you to “Darth Mlseim”! That is nail on the head what I asked for, to the point I have to ask, are you an educator by profession?

And here’s an Instructable for 8 (or more) digital outputs (to solid state relays):

That uses JQuery for real buttons, and it’s one-way communication. Web -> Imp

I don’t even come close to the other people on here (jwehr for example). Those guys are practically eating these Imps for every meal. I just experiment with it … old school electronics is my forte.

I wish I had the time, tools, and knowledge to build my own boards and put together some crazy projects.