Convert payload data from a websocket
Posted: Fri May 12, 2017 3:02 pm
i am using Links2004/arduinoWebSockets https://github.com/Links2004/arduinoWebSockets
all works fine but i have problems to convert the payload data. I try this example: https://github.com/Links2004/arduinoWebSockets/blob/master/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino
i will try to get something like this:
but this does not work. how can i get the payload value without the first char - into an integer?
thanks a lot....
all works fine but i have problems to convert the payload data. I try this example: https://github.com/Links2004/arduinoWebSockets/blob/master/examples/WebSocketServer_LEDcontrol/WebSocketServer_LEDcontrol.ino
Code: Select all
void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) {
switch(type) {
case WStype_DISCONNECTED:
USE_SERIAL.printf("[%u] Disconnected!\n", num);
break;
case WStype_CONNECTED: {
IPAddress ip = webSocket.remoteIP(num);
USE_SERIAL.printf("[%u] Connected from %d.%d.%d.%d url: %s\n", num, ip[0], ip[1], ip[2], ip[3], payload);
// send message to client
webSocket.sendTXT(num, "Connected");
}
break;
case WStype_TEXT:
USE_SERIAL.printf("[%u] get Text: %s\n", num, payload);
if(payload[0] == '#') {
// we get RGB data
// decode rgb data
uint32_t rgb = (uint32_t) strtol((const char *) &payload[1], NULL, 16);
analogWrite(LED_RED, ((rgb >> 16) & 0xFF));
analogWrite(LED_GREEN, ((rgb >> 8) & 0xFF));
analogWrite(LED_BLUE, ((rgb >> 0) & 0xFF));
}
break;
}
}
i will try to get something like this:
Code: Select all
if (payload[0] == '-') { // we get brightness back
int brightness = payload +1
}
but this does not work. how can i get the payload value without the first char - into an integer?
thanks a lot....