Hello. I’m trying and retrieve information from a JSON file. I manage to pick up the json string. But I can’t sort the data with WagoAppJSON.FbWrite_ToIEC_ByRule.
The data I try and retrieve is electricity prices in Norway during 24 hours.
VAR
FbWrite_ToIEC_ByRuleStrom : WagoAppJSON.FbWrite_ToIEC_ByRule; // Function block to sort the info from the JSON file
stringPath : STRING(20):='/'; // Path the JSON file uses
My1 : FbWrite_ToIEC_ByRule;
xHttpsGetTrigger2 : BOOL;
xWriteToIEC_Error : BOOL;
iWriteToIEC_ActualArrayRow : INT;
MyJsonData : ARRAY[0..23] OF typEnergyPrice; // JSON data to sort the data inn
bTestRule : ARRAY[0..MAX_ARRAY_ELEMENTS_CUSTOM] OF typRuleBase:=[
(sPath:='NOK_per_kWh',iConvertType:=eReal), // 1
(sPath:='EUR_per_kWh',iConvertType:=eReal), // 2
(sPath:='EXR',iConvertType:=eReal), // 3
(sPath:='time_start',iConvertType:=eString), // 4 Tride to use eTime but got error
(sPath:='time_end',iConvertType:=eString) // 5
];
END_VAR
FbWrite_ToIEC_ByRuleStrom( // Function block to sort the info from the JSON file
sPathBase:= stringPath,
pDataIn:= ADR(unHttpsGetRxBuffer.sVar),
udiSizeDataIn:= SIZEOF(unHttpsGetRxBuffer.abVar),
aRule:= bTestRule,
pIecVariable:= ADR(MyJsonData),
iArraySizeIecVariable:= 24,
udiSizeIecVariable:= SIZEOF(MyJsonData),
xError=> xWriteToIEC_Error,
iActualArrayRow=> iWriteToIEC_ActualArrayRow,
xTrigger:= xHttpsGetTrigger2 ); // xHttpsGetTrigger2 = TRUE to run
Hi @espenbo ,
For this purpose, the SAX parser of the WagoAppJSON is perfect.
You just need to define the token, and the associated rule to process the string data.
You’ll find attached the way to implement it in your example. eCockpit_Json.txt (139.7 KB)
(This is an export file change the extension file to .export)
Set xTriggerJSONParser to start the parsing process.
I see that you created some big function for formatting time, take a look at WagoAppString.TimeComponents_To_String where you can easy format time/date:
I am continuing to work on this project and have added HMI tables. I also added extra information in typEnergyPrice.
There I added iArrayPlace to have an overview of where in the array the info is located when I sort from cheap to most expensive. But when I added iArrayPlace then I get weird values in HMI tables
I’am working in a project similar to you. I have to decode a LoraWan Signal to the wago parcel. For that i’am using IoT Sensors. Those sensors will send the information into the LoraWan.
Hello,
Yes this library will suit your requirement.
We also have a LoRaWAN solution based on Multitech gateways in France
We have already decoded Watteco, Adeunis, and Nexelec sensors.