Agent url + ?led=1

I am trying to better understand the syntax ?led=1. I search the Forum and the web but didn’t find a description.

Is ? the “query” indicator? I get the led part but what if I want to submit a variable instead of a bool of 1 or 0? I also didn’t find a description of this in the Squirrel code; or did I overlook something?



Correct - the “?” indicates that the key/value pairs after a query parameters.

Here’s a quick example you can try:

Make a request to:{yourAgentUrl}?val1=1&val2=test&val3=true

You can pull out each individual value in your http.onrequest handler like so:

`http.onrequest(function(req, resp) {
local val1 = null;
local val2 = null;
local val3 = null;

// check if val1 is in the request's query
if ("val1" in req.query) {
    val1 = req.query["val1"];

// check if val1 is in the request's query
if ("val2" in req.query) {
    val2 = req.query["val2"];

// check if val3 is in the request's query
if ("val3" in req.query) {
    val3 = req.query["val3"];

// do stuff with the query parameters:
server.log("val1 = " + val1);
server.log("val2 = " + val2);
server.log("val3 = " + val3);

// send a response
resp.send(200, "OK");


Thank you.

So for val2=test, do you mean test can be a variable name and depends on the event handler the instantaneous value of test can be passed?

I sure appreciate your help.

When you see variables in a URL, example:
that is an example of “GET”, where the website “gets” the variable(s) contained in the URL.

The alternative is “POST”, where the server-side script or agent “posts” the variables to the website within the packet (header, whatever). You don’t see the variables in the URL.

There are valid uses for GET and POST, and which you choose depends on your application or personal preference.

If you ever get into website development (server-side, such as PHP, Perl, or ASP), you’ll be using these for everything, and to go a step further, the server can use .htaccess, which is able to do more stuff with variables. This forum you’re using now probably uses .htaccess rewrite rules to convert the /various items/ in the URL (within the forward slashes) into something the program understands.

Just about anything can be given to a server or agent in this case. You could tell the agent what your name is and the imp could do something with that …{yourAgentUrl}?username=Pui88

Maybe the imp will turn on a different output depending on what username it is given?

The possibilities are endless … which makes the imp so fun to use (as we all know).

Thanks, this is really helpful.

Yes, the imp is indeed fun to play with, must get better with the understanding though…:slight_smile: