Hello,
It is necessary to download the data from the Internet using an API key. The data is available in JSON format. How is it possible to send a query using an API key and then use received JSON response as data in the PLC? Something similar to the OpenWeather block.
AXC F 2152
One option might be to use the Shell function block in the PLCnextBase library to send curl commands to the API, and then decode the response using a JSON library from the PLCnext Store, perhaps the JSON_Library.
I tried but result from SysLinuxShell FB is “OK”, not a JSON respone.
Is that a response from the SysLinuxShell FB, or from curl ?
What result do you get if you execute the same curl command on the command-line of the PLC?
Are you using the curl -s option?
String “OK” is a response from SysLinuxShell FB.
This is a response from cli if I execute same command:
[1] 4563
[2] 4564
[3] 4565
[4] 4566
[5] 4567
[6] 4568
[7] 4569
[8] 4570
[9] 4571
[10] 4572
[2] Done longitude=20.375066
[3] Done capacity=54.72
[4] Done tilt=15
[5] Done azimuth=180
[6] Done tracking_type=fixed
[7] Done loss_factor=0.95
But a real JSON response is completely different from this.
Is this a public API?
If so, are you able to give an example of a curl command that gives that response you’ve shown?
This one is not a public API but you can try with the following:
https://api.solcast.com.au/data/forecast/radiation_and_weather?latitude=-33.856784&longitude=151.215297&output_parameters=air_temp,dni,ghi&format=json
That looks like something to do with the API, not with the PLCnext Control device.
For example, this command:
curl https://jsonplaceholder.typicode.com/todos/1
... returns this JSON string:
{
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
If you can get a curl command to return a JSON string from your API on a desktop system, then the same curl command should work on a PLCnext Control device.