I’m trying to assign a json array value to a led of CRGB type. I have struggled with this for days. Clearly, there is something that I don’t understand. Any assistance would be greatly appreciated.
I’m using the web ide compiling to a core with firmware 0.6.0 using these libraries: SparkJson (0.0.2), FastLED (3.1.5) and MQTT (0.4.17)
Incoming Json:
{
"state" : "on",
"html" : [ "CRGB::Blue" ]
}
gLED and gLEDcount are both defined at the top of my program.
CRGB gLED[3]; // storage for saving leds
int gLEDcount;
Here is the function that decodes my Json:
bool decodePayload(char* json) {
const size_t bufferSize = 4*JSON_ARRAY_SIZE(3) + JSON_OBJECT_SIZE(2) + 60; // 60 is additional space for strings
StaticJsonBuffer jsonBuffer;
JsonObject& root = jsonBuffer.parseObject(json);
gEffect[0] = 0;if (root.containsKey("state")) { gStateOn = (strcmp(root["state"], "on") == 0); strcpy(gState, root["state"].asString()); client.publish(DEBUG,"in state"); delay(100); } if (root.containsKey("effect")) { strcpy(gEffect, root["effect"].asString()); client.publish(DEBUG,"in effect"); delay(100); } if (root.containsKey("rgb")) { client.publish(DEBUG,"in rgb"); delay(100); JsonArray& rgb = root["rgb"]; gLEDcount = root["rgb"].size(); // try sizeof(gLED); for global led array for(int i = 0; i<(gLEDcount + 1); i++){ gLED[i].r = rgb[i][0]; gLED[i].g = rgb[i][1]; gLED[i].b = rgb[i][2]; } } if (root.containsKey("html")) { client.publish(DEBUG,"in html"); delay(100); JsonArray& html = root["html"]; gLEDcount = root["html"].size(); for(int i = 0; i < gLEDcount; i++){ gLED[i] = html[i]; } client.publish(DEBUG,html[0]); delay(100); } return root.success();
}
I am getting what I would expect in my debug statements. First this client.publish(DEBUG,"in html");
then this client.publish(DEBUG,html[0]);
which sends CRGB::Blue
to my MQTT broker. The problem is that I have been unable to figure out how to assign that value to the CRGB led. This gLED[i] = html[i];
isn’t working.