Http request

I have some problem understanding the http request, I don’t know how to turn on or off a led from a web page. I found some examples on the Internet but are not working.

Have you followed the entire Getting Started Guide?

It goes through the process of hooking up an LED, making it blink (to ensure it’s hooked up properly) - than adding agent code to control it with HTTP.

Yes, I followed that guide. I want to make a web page with 2 buttons one to turn on the led and the other to turn off the led. I don’t know how to do this.

For example this is the device code
`led <- hardware.pin1;


agent.on(“led”, function(value)
if(value == “Off”)

This is the agent code

`function requestHandler(request, response) {

if (“led” in request.query) {

device.send("led", request.query["led"]);


response.send(200, “OK”);


and at html
form action=“…” method="post"
input type=“submit” name=“led” value="On"
input type=“submit” name=“led” value=“off”

and it’s not working

Can you elaborate on your hardware setup? Also, were you able to initially able to get your LED to blink locally per @bi’s previous suggestion?

If you really want to make a nice web interface with buttons, the SnackBot example code is a good place to start.

This allows the agent to respond with HTML when you browse to your agent’s URL. You can modify the HTML to look like what you want, and change the buttons to send your ON and OFF commands.

I would remove your agent URL from the forum though, a mischievous person might be tempted to mess with you imp.

I used a 330 ohm resistor and a led connected at pin1 from the april board. I want to understand this example because I have to do someting more complex.

I have a html interface, for my complex project, but I want to understant how electric imp and the web page communicate. and I’ve done this simple example for a better understanding

Do you want the agent to simply respond to a query made to it, or do you want it to respond with an actual web interface that will display in your browser?

to an actual interface that will display in my browser

Just to be clear… “to an interface” and “with an interface” are very different. Either your web interface is running on an external web server, or it is running on the imp’s agent. Which one do you want?

the web interface is running on an external web server.

It is often helpful to log things to find out what is going on. You could add…
…to see what you are getting

Actually, that will just print a pointer to a table… you would want to do this:

foreach(k, v in request.query) { server.log(k +" = " + v); }

Also - I edited your posts to wrap the code / html in code tags (the c above the text editor)… that let’s formatting come through.