Created
April 10, 2018 01:22
-
-
Save bevchou/c6ac6773cfb8e38885b534e0de8b0bf5 to your computer and use it in GitHub Desktop.
ESP8266 project - just the code that gets the data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Just a section from the websocket code | |
//Here we are getting the data from the client (browser) | |
// if new text data is received | |
case WStype_TEXT: | |
Serial.printf("[%u] get Text: %s\n", num, payload); | |
//my data value starts with a '#' | |
if (payload[0] == '#') { | |
// decode dropdown data (base 16, 8 bits) | |
uint32_t combinedData = (uint32_t) strtol((const char *) &payload[1], NULL, 16); | |
//4 bits per value, first 4 bits are neopixel position from 0-15 | |
int pixelPos = ((combinedData >> 4) & 0XF); | |
//last 4 bits are the color from 0-5 | |
int colorVal = combinedData & 0XF; | |
//activatePixel() is a function I wrote that sets the color based on colorVal and turns the neopixel on | |
activatePixel(pixelPos, colorVal); | |
} | |
break; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment