Skip to main content
. 2022 Mar 2;22(5):1952. doi: 10.3390/s22051952
Algorithm 2. REST-based OPC UA Middleware Module Development Algorithm.
Input: OPC UA Binary Data, User Query Request, and Telegram Commands.
Output: Request URL to the web and cloud platforms. Notify for Telegram commands.
01:  function ConnectServer()
02:    try client = Client.Connect(ServerURL)
03:        if (client) then break;
04:    except pass
05:  function MakeReq (Platform, Address, Path as arguments)
06:    Get the root nodes as Query = client.get_root_node().get_children()
07:    for (i = 0; len(Query.get_children(i)); i++) do
08:        if (client.get_object_node().get_children(i) in Query) then
09:              Name =Query.get_children()[i].get_browser_name()
10:              Value =Query.get_children()[i].get_value(); Concatenate1= Name+Value;
11:              ClientBuilder += “$” + ServerObject(i) + “*” + Concatenate1
12:              CloudBuilder += Concatenate2; PCloudBuilder += Concatenate3
13:        end if
14:        if (Platform == ”web”) then
15:              ReqURL = Address + “Path?” + ClientBuilder
16:        elif (Platform == ”ThingsSentral”) then
17:              ReqURL = Address + “Path?” + CloudBuilder
18:        elif (Platform == ”PCloud”) then
19:              ReqURL = Address + “Path?” + PCloudBuilder
20:    end for
21:    try Req = Get(ReqURL) do
22:        if (Req.Status == 200) then break;
23:    except pass
24:  function StartTelegramWebHook()
25:    while (Message available in Telegram server) do
26:        Parse the message and store in chat_id, UserName, command variable.
27:    end while
28:    if (command is valid) then
29:        Call associated function for the corresponding command request.
30:        Bot.sendMessage(chat_id, Response)
31:    end if
Begin
32:  Start a thread calling ConnectServer() function to connect with OPC UA server.
33:  Call MakeReq (web, localhost, OPC) to send OPC UA credentials to the web.
34:  MakeReq(ThingsSentral, thingssentral.io, postlong) to send in ThingsSentralTM.
35:  Call MakeReq(Pcloud, Address, update) to send credentials to the cloud.
36:  Start a thread calling StartTelegramWebHook() to run Telegram Bot.
Finish