Skip to content

Instantly share code, notes, and snippets.

@bkrajendra
Last active July 27, 2016 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bkrajendra/26c132d5ded3f5dbd4bc87c1ae739a10 to your computer and use it in GitHub Desktop.
Save bkrajendra/26c132d5ded3f5dbd4bc87c1ae739a10 to your computer and use it in GitHub Desktop.
#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:
}
@bkrajendra
Copy link
Author

float my_array[N]; // if you don't know how many there are, use the heap
int i = 0;

char *tok = strtok(my_string, ",");
while (tok != NULL) {
    my_array[i++] = atof(tok);
    tok = strtok(NULL, ",");
}  

@bkrajendra
Copy link
Author

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