long color = 0;
void loop()
{
// listen for incoming clients
WiFiClient client = server.available();
if (client) {
String clientMsg ="";
String colorString = "";
String positionString = "";
while (client.connected()) {
if (client.available()) {
client.println("Hi there!");
char c = client.read();
clientMsg+=c;//store the recieved chracters in a string
//if the character is an "\" the whole message is recieved
if (c == '\\') {
colorString = colorString + clientMsg.charAt(1) + clientMsg.charAt(2) + clientMsg.charAt(3) + clientMsg.charAt(4) + clientMsg.charAt(5) + clientMsg.charAt(6); // create the hex color String
color = stringToNumber(colorString);
....
int stringToNumber(String thisString) {
int i, value = 0, length;
length = thisString.length();
for(i=0; i<length; i++) {
value = (10*value) + thisString.charAt(i)-(int) '0';;
}
return value;
}
the stringToNumber doesnt work, i found it on another forum. I need a replacement for this function. I tried some other solutions but i also didnt work. I also tried the strtol, but the long is still 0.
char str[6] = { clientMsg.charAt(1) , clientMsg.charAt(2) , clientMsg.charAt(3) , clientMsg.charAt(4) , clientMsg.charAt(5) , clientMsg.charAt(6) };
color = strtol(str, NULL, 6);