Premium HMI

 

It is possible to transmit signals to Databoom using platforms to supervise and industrial control making use of HMI/Scada software technology, like Premium HMI.

Data forwarding is implemented through the writing of a Visual Basic script.

References

Before proceeding with writing code, you need to add some references to your script (from the menu Edit -> References):

  • Microsoft WinHTTP Services (5.1)
  • Microsoft Scripting Runtime (1.0)

WARNING!

It's not possible to add references to external DLLs in Windows CE, therefore you can't add the references needed to run the VB script.  In this case you can connect to Databoom using Premium HMI via UNIQLOUD.

VB Scrit

The following script shows a possible approach to the forwarding of Premium HMI variables to Databoom.

Sub Main()
 Dim http As WinHttp.WinHttpRequest
 Dim UrlToPostTo As String
 Dim UrlClockGet As String
 Dim sDate As String
 Dim lngTimeout As Long
 Dim JSONString As String
 Dim canConn As Boolean
 Dim oAuthToken As String
 Dim FSO As FileSystemObject
 Dim TS As TextStream
 Set FSO = New FileSystemObject
 Dim logs<SIGNAL 1>, logs<SIGNAL 2> As String
 logs<SIGNAL 1> = "LOGS\<SIGNAL 1>.txt"
 logs<SIGNAL 2> = "LOGS\<SIGNAL 2>.txt"

 oAuthToken = "Bearer <OAUTH TOKEN DATABOOM>"
 UrlClockGet = "https://api.databoom.com/v1/auth/gmtclock/plain"
 UrlToPostTo = "https://api.databoom.com/v1/signals/push"

 Set TS = FSO.OpenTextFile(logs<SIGNAL 1>, ForAppending, True)
 TS.Close
 Set TS = FSO.OpenTextFile(logs<SIGNAL 2>, ForAppending, True)
 TS.Close

 lngTimeout = 30000
 canConn = True

 Set http = New WinHttp.WinHttpRequest
 http.SetTimeouts lngTimeout, lngTimeout, lngTimeout, lngTimeout

 http.Open "GET", UrlClockGet, False
 http.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
 http.SetRequestHeader "Authorization", oAuthToken
 On Error GoTo HandleDateRequest
  http.Send
 sDate = http.ResponseText

 http.Open "POST", UrlToPostTo, False
 http.SetRequestHeader "Content-Type", "application/json"
 http.SetRequestHeader "Authorization", oAuthToken

 Dim <SIGNAL 1>, <SIGNAL 2>
 <SIGNAL 1> = GetVariableValue("<SIGNAL 1>")
 <SIGNAL 2> = GetVariableValue("<SIGNAL 2>")

 JSONString = "{""device"":""<TOKEN DEVICE>"",""date"":" + sDate + ", ""signals"":["
 JSONString = JSONString + "{""name"":""<TOKEN SIGNAL 1>"",""value"":"+ <SIGNAL 1> +"},"
 JSONString = JSONString + "{""name"":""<TOKEN SIGNAL 2>"",""value"":"+ <SIGNAL 2> +"}"
 JSONString = JSONString + "]}"
 On Error GoTo HandleFailedPost
  http.Send "" + JSONString

 If canConn = True Then
  Dim bulk As String
  Dim emptyBulk As Boolean
  emptyBulk = True
  bulk = "{""device"":""<TOKEN DEVICE>"",""date"":" + sDate + ", ""signals"":{"

  bulk = bulk + " ""<TOKEN SIGNAL 1>"" : {""description"":""<SIGNAL 1>"", ""history"":["
  addHistory logs<SIGNAL 1>, bulk
  If StrComp(Right(bulk, 1),",") = 0 Then

   bulk = Left(bulk, Len(bulk) - 1) + "]},"
   emptyBulk = False
  Else
   bulk = bulk + "]},"
  End If

  bulk = bulk + " ""<TOKEN SIGNAL 2>"" : {""description"":""<SIGNAL 2>"", ""history"":["
  addHistory logs<SIGNAL 2>, bulk
  If StrComp(Right(bulk, 1),",") = 0 Then
   bulk = Left(bulk, Len(bulk) - 1) + "]}}}"
   emptyBulk = False
  Else
   bulk = bulk + "]}}}"
  End If

  If emptyBulk = False Then
   http.Open "POST", UrlToPostTo, False
   http.SetRequestHeader "Content-Type", "application/json"
   http.SetRequestHeader "Authorization", oAuthToken
   On Error GoTo HandleFailedConn
    http.Send "" + bulk

   If canConn = True Then
    cleanHistory logs<SIGNAL 1>
    cleanHistory logs<SIGNAL 2>
   End If
  End If
 End If

 Set http = Nothing
 Set TS = Nothing
 Set FSO = Nothing

 Exit Sub

 HandleFailedConn:
  canConn = False
  Resume Next

 HandleDateRequest:
  canConn = False
  sDate = Format(Now, "YYYY-MM-DDTHH:NN:SS")
  Resume Next

 HandleFailedPost:
  canConn = False
  Set TS = FSO.OpenTextFile(logs<SIGNAL 1>, ForAppending, True)
  TS.Write "{""date"":"+ sDate +",""value"":"+ <SIGNAL 1> +"}" + vbCrLf
  TS.Close
  Set TS = FSO.OpenTextFile(logs<SIGNAL 2>, ForAppending, True)
  TS.Write "{""date"":"+ sDate +",""value"":"+ <SIGNAL 2> +"}" + vbCrLf
  TS.Close
  JSONString = ""
  Resume Next
End Sub

Sub addHistory(ByVal logFile, ByRef bulk)
 Dim FSO As FileSystemObject
 Dim TS As TextStream
 Set FSO = New FileSystemObject

 Set TS = FSO.OpenTextFile(logFile, ForReading)
 Do Until TS.AtEndOfStream
  bulk = bulk + TS.ReadLine + ","
 Loop
 TS.Close
End Sub

Sub cleanHistory(ByVal logFile)
 Dim FSO As FileSystemObject
 Dim TS As TextStream
 Set FSO = New FileSystemObject
 Set TS = FSO.OpenTextFile(logFile, ForWriting, True)
 TS.Write ""
 TS.Close
End Sub

You need to set the following parameters in the script to make it work correctly:

  • <OAUTH TOKEN DATABOOM> is a token generated in Databoom,  in Settings -> Credentials.
  • <SIGNAL 1> and <SIGNAL 2> are the Premium HMI variables you want to forward to Databoom. The same values are used to name the logs file too. The example has two variables, you can add more by following the same procedure.
  • <TOKEN DEVICE> is the device token in Databoom.
  • <TOKEN SIGNAL 1> and <TOKEN SIGNAL 2> are the signals token in Databoom. If the signals have already been created on Databoom, <SIGNAL TOKEN #> should be replaced with the corresponding token. On the contrary the token inserted in the script will be used for the creation of the signal on the platform.

The script forwards the data at regular intervals, every time it is called by the scheduler. In case the communication is not possible, the recorded data is stored locally in log files, and will be forwarded as soon as the connection is restored in a single request (bulk).

Scheduler

To allow the permanent execution of the script, it is required to create a new scheduler. In the properties window of the scheduler finally select "every minute" in type and the script in commands.

Configuration completed!

Once the procedure has been completed, Databoom starts to record data sent from Premium HMI. To examine your data and have a correct representation, follow the instructions in Edit/validation of a signal.

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.