Looking for simple example of agent/device code

Hey everyone,

I’m trying to find a very simple example of agent code that contains a single button on the agent webpage. When you push the button, it fires a function within the device code.

That’s it. This should be super simple but for some reason I’m pulling my hair out over it. Really wish there was more sample code out there to review.



Sorry all. Just figured it out after I realized how bad the search engine is here and started to use Google with site: to search the forums.

This thread tipped me off: https://discourse.electricimp.com/discussion/2595/html-button-to-start-a-function

The SnackBot code is exactly what I needed.

Yes, we should just turn the search box off really. Or make it redirect to Google…


For me the simple examples often have extra complexity (I’m still learning classes and constructors). Below is a very simple example of a URL -> pin. Security is by obscurity. Look for the URL to use in the device logs.

server.log("Turn the pin on by browsing to " + http.agenturl() + “?power=on”)
server.log("Turn the pin off by browsing to " + http.agenturl() + “?power=off”)
function requestHandler(request, response)
if (“power” in request.query)
device.send(“power”, request.query[“power”])
response.send(200, “OK”)


hardware.pin1.configure(DIGITAL_OUT); agent.on("power", function (value) { if (value == "off") { hardware.pin1.write(0) } if (value == "on") { hardware.pin1.write(1) } });