HTML control of agent - error message

Want to control an RGB LED via my IMP via an URL like this:

      https://agent.electricimp.com/xxxxxxxxxxxx?rgb=#F49E17

Agent code:

        if ("rgb" in request.query) {
            local color = request.query.rgb;
            if (color[0] == '#') {                               // line 228
                local returnTable = {
                    argR = ASCIItoHex(color[1])*16 + ASCIItoHex(color[2])
                    argG = ASCIItoHex(color[3])*16 + ASCIItoHex(color[4])
                    argB = ASCIItoHex(color[5])*16 + ASCIItoHex(color[6])
                };
                device.send("rgb", returnTable); // send our color table to the imp
            }
        }

I keep getting this error in my browser:

     Internal Server Error: the index '0' does not exist (line 228)

Have no clue what is wrong here :frowning: , anyone got a suggestion?

“#” is a special character in URLs, it separates the fragment from the path. Try doing it without the “#”, or with a different character, or with the “#” URL-escaped (i.e., as %23).

Peter

What you’re giving it is already HEX. Not sure if you should be doing ASCIItoHEX.

In fact, the HEX value F49E17 breaks down like this:
R= F4
G= 9E
B= 17

00 to FF is 0 to 255 (decimal).

R=0, G=0, B=0 would be BLACK
R=255, G=255, B=255 would be WHITE

You may want to convert each pair to a decimal value:
https://electricimp.com/docs/troubleshooting/tips/hex/

Or, send the HEX value to the device “as-is” and let the device do the parsing.
I’ve never messed around with an RGB LED.

@peter, mlseim: thanks for your feedback. The ‘#’ I used as this is also the return value of some html color pickers like Firefox.