user24157: I'm building web based remote control system for esp8266. In arduino IDE, using the ESP libraries. To, send data to the server, I'm using http post.
For some settings, I need to transfer 30 or so, different values over a single post request.  And assign it to different type of variables.
so, from this:
192.168.1.101/testpost?lenght=10&1=100&2=true&3=1800&4=125

i need this:

uint8_t brightness = 100;
bool randomOrder = true;
uint16_t Delay = 1800;
uint8_t Position = 125;

This is the relevant code. Basically, my idea is, to send the lenght of the array (will be different each time.) in the first argument.
Than create a for loop that put every value in a array into variable pointers. But, since lots of different type variables going on, i'm not sure how to do that.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>

//values i need to set in a single post.
uint8_t settings0;
bool brightness; 
uint16_t randomOrder; 
uint8_t Delay;

void setup {
//relevant code that handels post request.
server.on("/testpost", HTTP_POST, []() {

String ZeroValue = server.arg("lenght");

int lenght = ZeroValue.toInt();

//this doesnt really work, but its a starting idea.
int* SettingsArray[4] = {&settings0, &brightness, &randomOrder, &Delay};

for( int i = 0; i < lenght; i++) {

     String PresetSettings = server.arg(i);
     SettingsArray[i] = PresetSettings.toInt();
    }
});
}

Ultimately, I can just do that, but I'm wondering if there is a more elegant solution.
brightness = SettingsArray[1];
randomOrder = SettingsArray[2];
Delay = SettingsArray[3];
Position = SettingsArray[4];


user13432: The WebServer class supports argument lookup by name. This should allow HTTP argument parsing that does not require length and/or specific order:
192.168.1.101/testpost?brightness=100&randomOrder=true&delay=1800&position=125

And parse with:
brightness = server.arg("brightness").toInt();
randomOrder = server.arg("randomOrder").toInt();
Delay = server.arg("delay").toInt();
Position = server.arg("position").toInt();

Please note that some value will require cast (and there might be a need for special handling of "true" and "false"). For further robustness each argument name needs to be checked that it is available. 
String arg = server.arg("argName");
val = (arg.length() == 0 ? defaultVal : arg.toInt());

Or simply:
String arg = server.arg("argName");
if (arg.length() != 0) val = arg.toInt();

Cheers!

24157: <p>I'm building web based remote control system for esp8266. In arduino IDE, using the ESP libraries. To, send data to the server, I'm using http post.
For some settings, I need to transfer 30 or so, different values over a single post request.  And assign it to different type of variables.</p>

<pre><code>so, from this:
192.168.1.101/testpost?lenght=10&amp;1=100&amp;2=true&amp;3=1800&amp;4=125

i need this:

uint8_t brightness = 100;
bool randomOrder = true;
uint16_t Delay = 1800;
uint8_t Position = 125;
</code></pre>

<p>This is the relevant code. Basically, my idea is, to send the lenght of the array (will be different each time.) in the first argument.
Than create a for loop that put every value in a array into variable pointers. But, since lots of different type variables going on, i'm not sure how to do that.</p>

<pre><code>#include &lt;ESP8266WiFi.h&gt;
#include &lt;WiFiClient.h&gt;
#include &lt;ESP8266WebServer.h&gt;
#include &lt;ESP8266mDNS.h&gt;

//values i need to set in a single post.
uint8_t settings0;
bool brightness; 
uint16_t randomOrder; 
uint8_t Delay;

void setup {
//relevant code that handels post request.
server.on("/testpost", HTTP_POST, []() {

String ZeroValue = server.arg("lenght");

int lenght = ZeroValue.toInt();

//this doesnt really work, but its a starting idea.
int* SettingsArray[4] = {&amp;settings0, &amp;brightness, &amp;randomOrder, &amp;Delay};

for( int i = 0; i &lt; lenght; i++) {

     String PresetSettings = server.arg(i);
     SettingsArray[i] = PresetSettings.toInt();
    }
});
}
</code></pre>

<p>Ultimately, I can just do that, but I'm wondering if there is a more elegant solution.</p>

<pre><code>brightness = SettingsArray[1];
randomOrder = SettingsArray[2];
Delay = SettingsArray[3];
Position = SettingsArray[4];
</code></pre>
 13432: <p>The WebServer class supports <a href="https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WebServer/src/ESP8266WebServer.h#L93" rel="nofollow">argument lookup by name</a>. This should allow HTTP argument parsing that does not require length and/or specific order:</p>

<pre><code>192.168.1.101/testpost?brightness=100&amp;randomOrder=true&amp;delay=1800&amp;position=125
</code></pre>

<p>And parse with:</p>

<pre><code>brightness = server.arg("brightness").toInt();
randomOrder = server.arg("randomOrder").toInt();
Delay = server.arg("delay").toInt();
Position = server.arg("position").toInt();
</code></pre>

<p>Please note that some value will require cast (and there might be a need for special handling of "true" and "false"). For further robustness each argument name needs to be checked that it is available. </p>

<pre><code>String arg = server.arg("argName");
val = (arg.length() == 0 ? defaultVal : arg.toInt());
</code></pre>

<p>Or simply:</p>

<pre><code>String arg = server.arg("argName");
if (arg.length() != 0) val = arg.toInt();
</code></pre>

<p>Cheers!</p>
