0

I've got an ESP8266 (NodeMCU) and I am trying to understand the ESP8266WebServer library, as how to use the results across functions.

In my setup function, I have the following:

   server.on("/marquee", []() {
      varOne = server.arg("baseColor");
      varTwo = server.arg("marqueeColor");
      server.send(200, "text/html", webPage);
      Serial.println("Marquee  activated");
      state = true;
      ledMode = "marquee";  
    });

In my loop, I detect the ledMode and if it is set to marquee then it runs the following FastLED function, amongst others:

fill_solid(leds, NUM_LEDS, 0xFF0000);

What I am trying to figure out is how I go from taking a hex color code of say FF0000 from the URL parameter, and use that in my fill_solid function.

server.arg stores get the parameter as a string, so I am not sure what needs to be done. Also, using a variable name in place of the Hex code in the fill_solid function results in an error due to not expecting the variable

  • What argument types does fill_solid() take, please? – Mark Smith Jan 7 '17 at 11:25
1

server.arg stores get the parameter as a string, so I am not sure what needs to be done.

The parameter needs to be converted to an uint32_t (and then to a CRGB or CHSV struct). The simplest way is to use the C library function strtoul

uint32_t color = strtoul(arg, NULL, 16);

This can be improved so that it checks that a number was scanned, etc.

Cheers!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.