Here's the code for a PicoC block (Program Block), that extracts a particular value from a file stored on the Miniserver SD card. This can be triggered to retrieve values at an exact time of your choosing. You will need to adapt the code to recognise the field returned in your json.
1. Trigger a Virtual Output to poll the external resource at the desired time. "Save HTTP Response" to the Miniserver SD card.
2. Use a delayed pulse triggered from the above process to run the Program block to retrieve the desired values.
I don't know how to code, but I've used ChatGPT extensively to modify Program block code -
ChatGPT doesn't know the limitations of the Loxone Program Block. When is comes up with code that doesn't work in the Program Block (the Program Block has an Error Text output), tell it to program the same thing without using 'XYZ' function. After a few iterations, you'll hopefully get code that suits the limitations of the Miniserver. ie. Tell ChatGPT to modify the code to find 'ABC' field associated with 'XYZ' value. The following code finds and outputs an OAuth token after the field "IdToken":"xyz..........................."
// PicoC code developed by @Jan W.
// Link refers -
//
https://www.loxforum.com/forum/german/software-konfiguration-programm-und-visualisierung/403543-vti-aus-programm-picoc-beschreiben?p=405574#post405574FILE *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 characters 'IDtoken' in string
if (tokenStart != NULL) {
//tokenStart += strlen(IdToken); // if found then add length of token itself
tokenStart = tokenStart + strlen(IdToken) -1; // 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
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,"No text found");
// clear output if no token is found
setoutput(0,0);
}
}
fclose(fp1);
}
sleep(500); // sleep for half a second
}