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.
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.
Agent:
`
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”)
}
}
http.onrequest(requestHandler);
`
Device: hardware.pin1.configure(DIGITAL_OUT); agent.on("power", function (value) { if (value == "off") { hardware.pin1.write(0) } if (value == "on") { hardware.pin1.write(1) } });