Last active
July 27, 2016 05:26
-
-
Save bkrajendra/26c132d5ded3f5dbd4bc87c1ae739a10 to your computer and use it in GitHub Desktop.
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
#include <ArduinoJson.h> | |
int my_code[75]; | |
void setup() { | |
delay(2000); | |
// put your setup code here, to run once: | |
Serial.begin(115200); | |
//Assign HttpServer return string to this json | |
char json[] = "{\"data\":[38000,1,69,340,169,20,20,20,20,20,64,20,20,20,20,20,20,20,20,20,20,20,64,20,64,20,20,20,64,20,64,20,64,20,64,20,64,20,20,20,64,20,20,20,20,20,20,20,20,20,20,20,20,20,64,20,20,20,64,20,64,20,64,20,64,20,64,20,64,20,1544,340,85,20,3663]}"; | |
StaticJsonBuffer<1000> jsonBuffer; //make sure to change it and keep it max as per your json length | |
JsonObject& root = jsonBuffer.parseObject(json); | |
for (int i = 0; i < 10; i++)//only done up to 10 you can go up to 75 based on length , change accordingly | |
{ | |
my_code[i] = atoi(root["data"][i]); | |
} | |
Serial.println("Result"); | |
Serial.println(my_code[3]); | |
//root.printTo(Serial); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
Author
bkrajendra
commented
Jul 27, 2016
void parseString(String str) {
int nextIndex;
int codeLength = 1;
int currentIndex = 0;
nextIndex = str.indexOf(',');
// change to do/until and remove superfluous repetition below...
while (nextIndex != -1) {
if (codeLength > 1) {
codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int));
} else {
codeArray = (unsigned int*) malloc(codeLength * sizeof(unsigned int));
}
codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt());
codeLength++;
currentIndex = nextIndex + 1;
nextIndex = str.indexOf(',', currentIndex);
}
codeArray = (unsigned int*) realloc(codeArray, codeLength * sizeof(unsigned int));
codeArray[codeLength-1] = (unsigned int) (str.substring(currentIndex, nextIndex).toInt());
irsend.sendGC(codeArray,codeLength);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment