I want to read a binary body datas from an HTTP POST request.

The context is that I'm making a LED strip controller and I'm currently using this code :

#include <WebServer.h>
#include <Adafruit_NeoPixel.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, STRIP_PIN, NEO_GRB | NEO_KHZ800);
WebServer server(80);

void handleSimpleWrite()
    int r = 0, g = 0, b = 0;
    if (server.hasArg("red"))
        r = server.arg("red").toInt();
    if (server.hasArg("green"))
        g = server.arg("green").toInt();
    if (server.hasArg("blue"))
        b = server.arg("blue").toInt();
    strip.setPixelColor(id, r, g, b);

It works, but it's clearly innefficient. I want to make an API endpoint that get a binary buffer with RGB states along the request body and I can't figure out how to read this body.

Any ideas ?

  • this may help ... startingelectronics.org/tutorials/arduino/… – jsotola Jan 25 '20 at 18:48
  • esp8266 has arg("plain"). esp32 doesn't have it. can't you use plain WiFiServer? – Juraj Jan 25 '20 at 18:54
  • @jsotola this library seem to be for AVR based Arduino, the header is unknow for my board @Juraj I think that arg("plain") is stay working when looking in the source code. I will edit libraries/WebServer/src/Parsing.cpp to fit my needs. – Devilish Spirits Jan 25 '20 at 19:58
  • 1
    i send a long string of hex pairs, and it works well. use websockets instead of http to get more bandwidth. – dandavis Jan 25 '20 at 20:58
  • What does efficiency mean here? -- Did you do any calculations about efficiency, if you mean speed? I mean, how fast will you change the RGB values? And how fast is the network connection? And how fast is the code you show? -- I'd leave it as is, because it is a clear and simple interface, and I assume that network and CPU are much faster than needed for this simple task. – the busybee Jan 27 '20 at 8:06

Your Answer

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

Browse other questions tagged or ask your own question.