Hello,
Is there a way I can read the actual names of the parameters in the req.query string? I would like to be able to read the number of parameters in the query ( got this - req.query.len() ), and then read the names of the parameters. That way I can use url: https://agent.electricimp.com/myimpid/1234?ch1=0&ch12=0&ch35=0, and find that the first parameter name is “ch1”, the second is “ch12”, and the third is “ch35”. Here is the code I have now:
`outBlob <- blob(12);
http.onrequest(function(req, res) {
res.send(200, “DMX Has been Sent”);
if (req.path == “/1234”) {
server.log(“good pw”);
local y = req.query.len();
server.log(y);
for (local i=0; i<y; i++) {
local val = req.query[“ch”+(i+1)];
local v = val.tofloat();
outBlob[i] = v;
}
}
else {
server.log(“wrong pw”);
}
device.send(“newDMX”, outBlob);
})`
I would like to do something like this:
`outBlob <- blob(12);
http.onrequest(function(req, res) {
res.send(200, “DMX Has been Sent”);
if (req.path == “/1234”) {
server.log(“good pw”);
local y = req.query.len();
server.log(y);
for (local i=0; i<y; i++) {
local h = req.query.parametername[i+1];
local val = req.query.h;
local v = val.tofloat();
local g = [h-“ch”];
outBlob[g] = v;
}
}
else {
server.log(“wrong pw”);
}
device.send(“newDMX”, outBlob);
})`
This way I can only send the channels I want changed, instead of all of them, every request. I know that " local g = [h-“ch”];" makes no sense, I eventually need to strip away the “ch” and get the actual channel number so I know where to write in the blob. I can’t find anything online relating to reading the names of the parameters…
Thanks!!