If you need to get some data from the Internet into a program running on a PLC. Typically spot energy prices or weather forecast. You can use the new Text Parser function. This function requires a PLC with .NET driver support, from the current offer these are the markMXL, mark520, w751-9301 and windows runtime models. We will show it with the windows runtime, it is installed automatically with Domat IDE, it is an unlicensed free version that runs for 20 minutes. So let's start the runtime and the IDE. We assign the plc and download the configuration. We will add a channel with the Text Parser protocol and two devices to it. The first will be on the weather and the second on the spot price of electricity.
I found a weather resource on the server api.met.no, it is filled in as the address of the device, and the parameter with a specific location is filled in the path field, in my case /weatherapi/locationforecast/2.0/compact?lat=50.01&lon=15.68.
For a test, I can put the entire address in the browser and I should get to the page where all the data is, here I have to find the necessary value, for example, we are interested in the current temperature, we can find it embedded in properties.timeseries[0].data.instant. details.air_temperature so we copy it as group parameter, http method is GET and type is Jpath, other supported ones are Xpath and regex.
We will add a data point to this group and call it temperature, the data type is real.
For spot prices, I found an api at the address spotovaelektrina.cz, when we click on the api at the bottom, we get to the path for the json api, so, similar to the temperature, we put the address spotovaelektrina.cz from the device field and into the path /api/v1/price/get-actual -price-json,
we create a group again and the jpath is now simply $.priceCZK,
we add a data point and done, we can upload to the plc, turn on debug and we should see the correct values.
Please keep in mind that you are using third-party services, so if the provider changes something or cancels it completely, it will stop working in the PLC program as well.
If the PLC has two Ethernet ports, the internet must be connected to the primary port X1 (marked as ETH0 somewhere)
You can use the File (.NET) function to load data from a file.
In the device properties, select the path to the file, here for example http://192.168.0.101/topeni/topeni.dat. This file is plain text in the format of room number, tab and occupancy mode (1 - reservation, 2 - occupied, 3 - unoccupied).
We will add a reading group to the device, we will use RegEx for reading.
Click on the RegEx box and enter the formula here 101\t(\d+)
We can enter sample data in the field below the formula and click refresh. We can see the result on the right. The formula looks for the text 101 and the tab (101\t) and returns the number that follows this text (\d if it is multi-character, then \d+). We are interested in the two, so we create a data point with the name 101 which has index 0 and subindex 1 (see the result from the previous step)
The next room will have a new group, now the formula is 102\t(\d)
And the data point in this group will be named 102 and again have index 0 and subindex 1
We can continue like this for other rooms. Supported regular expressions can be found in the Domat IDE help under the topic Communication protocol Text Parser (.NET), or you can consult, for example, Chatgpt.com or Regexr.com.
To test it out, we can start the runtime (Domat RT icon on the desktop) in the PLC properties, enable .Net drivers, upload the configuration to the PLC, then upload the project to the PLC and place the sample file somewhere on the disk, see the image. After starting debugging, the program should return the occupancy of the rooms.