
I needed to make a change to strl length to 7200 on account of the file size. The program also complained about a couple of things -
const char IdToken[20] = "\"IdToken\":\"";
[len] = 0; // add trailing 0 to token string
The token generated is correct except that it is missing the first letter e. The beginning should be -
eyJraWQiQiJsM3....
The program is now -
FILE *fp1; char str1[7200]; char *tokenStart; char *tokenEnd; char token[4095]; char IdToken[20] = "\"IdToken\":\""; int len; int nEvents; while(TRUE) { nEvents = getinputevent(); if (nEvents & 0x08) // check for change on analogue input 1 (Bit 4) - this is only used as a trigger to run following code { fp1 = fopen("/user/common/zodiac_token.json", "r"); // open file with token read fgets(str1, 7200 , fp1); // copy content of file to string, max. 4094 bytes plus trailing 0 tokenStart = strstr(str1,"IdToken"); // search for IDtoken in string if (tokenStart != NULL) { tokenStart += strlen(IdToken); // if found then add length of token itself tokenEnd = strstr(tokenStart, "\""); // search for final quotation symbol if (tokenEnd != NULL) { len = tokenEnd - tokenStart; // if found then calculate length of token strncpy(token, tokenStart, len); // copy n bytes from string to token starting from begin of token //[len] = 0; // add trailing 0 to token string setoutput(0,len); // set analogue output 1 to length of token setoutputtext(0,token); // set text output 1 to token } } else { setoutputtext(0,""); // clear output if no token is found setoutput(0,0); } } fclose(fp1); } sleep(500); // sleep for half a second }
Kommentar