ok so im trying to set up a wifi bulb communicating using MQTT. So the bulb will subscribe to five topics. One for white leds brightness, one for brightness of R,G and B channels and one for the bulb being on or off. Now using this library i have managed to get the bulb to subscribe to a topic and display the received data in the serial terminal but the data is received into a byte array. In order for me to use this data to control the light i would like it in an integer. Also the data needs to be stored as soon as its received or its over written when something is next sent or received as the same buffer is used for both directions of communication. Note i am running this code on an ESP8266-03 specifically this bulb
ok but from my understanding from the library if the data "255" was sent then payload[0] = 2 , payload[1] = 5 , payload[2] = 3 In which case your solution wont work?
Here is the code from the example with the library that runs everytime data is recieved from a subscribed topic:
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload*);*
}*
Serial.println();*
// Switch on the LED if an 1 was received as first character*
if ((char)payload[0] == '1') {*
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level*
// but actually the LED is on; this is because*
// it is acive low on the ESP-01)*
} else {*
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH*
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived [");
Serial.print(topic);
Serial.print("] ");
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
// Switch on the LED if an 1 was received as first character
if ((char)payload[0] == '1') {
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
// but actually the LED is on; this is because
// it is acive low on the ESP-01)
} else {
digitalWrite(BUILTIN_LED, HIGH); // Turn the LED off by making the voltage HIGH
}
}