Skip to main content
. 2022 Mar 2;22(5):1952. doi: 10.3390/s22051952
Algorithm 3. REST-Aware-Based Web Service and ThingsSentralTM Cloud Platform Development Algorithm.
Input: Web request from the middleware. Sensor ID, Command Type (Statistics/Chart/View/Download), Query Type (Historical/N/csv/txt), From Date, To Date, Number to Query. NodeID & Value to Write.
Output: Present OPC UA server node credentials and store in the MariaDB database. Command to write value in the OPC UA server node. Present all/historical database records graphically and statistically based on sensor id.
01:  function HandleURL()
02:    Start the application in a standalone mannner and listen for the middleware URL request.
03:    while (Request.available) do
04:       Split request on ‘?’ and store in URLRequest array. Split the first index point of URLRequest on the ‘/’ and store
in PathType variable. Store the last index point of the URLRequest in Data.
05:       if (PathType == “OPC”) then
06:          Split data on the ‘$’delimiter and store in ObjectNodeTags array.
07:          for (i = 0 to length.ObjectNodeTags, i++) do
08:            Split ObjectNodeTags[i] on the ‘*’ delimeter & store Ist index in Object & 2nd index in Tags.
09:            if (Object in ObjectList) then
10:               Split Tags on the ‘|’ delimiter & store in TagCredentials array.
11:               for (j = 0 to length.TagCredentials, j++) do
12:                  Split TagCredentials[j] on the ‘=’ delimiter.
13:                  Store first index point of TagCredentials in Name and 2nd index in Values array.
14:                  Update GUI, List Box, and Data Logger File taking these credentials.
15:               end for
16:           else break
17:         end for
18:      elif (PathType == “postlong”) then
19:         Split Data on the ‘@’delimiter & store in SensorData array.
20:         for (i = 0 to length.SensorData, i++) do
21:            Split SensorData[i] on the ‘|’ delimeter & store 1st index in SensorID, 2nd in Value Array.
22:            Make query as sql = “SELECT SensorID, SensorValue, DateTime FROM DatabaseTable”
23:            rs = mdb.SQLSelect(sql)
24:            if (rs not empty) then
25:               while (rs not reached to the last field) do
26:                  row.column(SensorID, SensorValue, DateTime) = SensorID, Value, Time
27:                  mdb.InsertRecord(DatabaseTableName, row); rs.MoveNext
28:               end while
29:            end if
30:         end for
31:      else pass
32:    end while
33:  function WriteServerTag(Value, id as Arguments)
34:     Collect middleware URL, id, value from the GUI and store in MiddlewareURL, NodeID, and Value.
35:     Payload = {‘Nodeid’:id, ‘value’:Value}; response = HTTP.POST(MiddlewareURL, data=Payload)
36:  function ExecuteCommand(Command, QueryType, Sensorid as Arguments)
37:     Get Start Date, End Date, Limit from the GUI and store in From, To, Num. Connect with the MySQl Server.
38:     if (QueryType == Historical) then
39:         Collect historic data from the database for the given sensor id within the specified time and store in sql.
40:     elif (QueryType == N) then
41:         Collect N number of data from the database for the given sensor id and store in sql.
42:      rs = mdb.SQLSelect(sql)
43:    if (rs is not nil) then
44:        while (rs not reached last field) do
45:           Value = rs.Field(SensorValue); Time = rs.Field(DateTimeAcquired)
46:           Join Time and Value on the ‘,’ and store in Concatenate Variable; Builder += Concatenate + EndOfLine
47:           if (Command == “Statistics”) then Listbox.AddRow(Value, Time)
48:           elif (Command == “Chart”) then PlotGraph(Time, value)
49:           else pass
50:        end while
51:     end if
52:  function UserRequest(Command, QueryType, SensorID as Arguments)
53:     if (Command == “Write”) then
54:        Call WriteServerTag(QureyType, SensorID)
55:     elif (Command == “Statistics”) then
56:        Call ExecuteCommand(Statistics, QueryType, SensorID)
57:     elif (Command == “Chart”) then
58:        Call ExecuteCommand(Chart, QueryType, SensorID)
Begin
59:  Start a thread calling HandleURL() to collect data from the middleware request.
60:  Call UserRequest(Write,Value,sensorid) function to Write Data in the OPC UA Server address space.
61:  Call UserRequest(Statistics,Historical,sensorid) to monitor sensor data historically in the application GUI.
62:  Call UserRequest(Statistics,N,sensorid) to monitor latest N number of data in the application GUI.
63:  Call UserRequest(Chart,Historical,sensorid) to monitor sensor data graphically in a historical manner.
64:  Call UserRequest(Chart,N,sensorid) to monitor N number of selected sensor data graphically.
Finish