The previous article described how to convert the TB REST interface outgoing parameter format to the most appropriate format by using the Kettle platform. This article will continue with the kettle platform to deal with THE TB WebSocket interface.

Ask questions:

How to unify the webSocket interface format?

The telemetry data for the device in TB looks like this.

{
  "EA": [
    {
      "ts": 1479735870786,
      "value": "0"
    },
    {
      "ts": 1479735871857,
      "value": "0"
    }
  ],
  "ER": [
    {
      "ts": 1479735870786,
      "value": "0"
    },
    {
      "ts": 1479735871857,
      "value": "0"
    }
  ]
}
Copy the code

And we normally need data input, should be like this:

{ "success":true, "resultCode":"0", "resultMsg":null, "result":{ "id":"53884a40-8554-11eb-bccd-c11a74ecd150", _g01 "name" : "1", "state" : false, "cmdId" : 10, "nickName" : "the power into the line", "note" : "the power into the line", "data" : [{" key ":" EA ", "val" : "0", KWh of "dw" : ""," Max ", null, "min", null, "danger" : false, "note" : "unknown"}, {" key ":" ER ", "val" : "0" and "dw" : "kVarh", "Max", null, "Min ":null, "danger":false, "note":" unknown"}}Copy the code

How do we convert TB from the original format to the format that we need?

Solution:

  • Solve the problem by modifying TB source code

If TB source code is modified, the websocket in the management background is unavailable and data cannot be viewed in real time. If you modify the source code, you must modify the back-end Java code and the front-end AngularJS code. Lack of familiarity with the platform may lead to system unavailability.

  • Resolve the problem using the Kettle data platform

The Kettle platform implements transparent transmission of Websocket data and customizes each returned data. And finally convert to the websocket format we need.

Presentation:

Create a kettle file and convert websocket data format in the kettle file.

Upload the kettle platform conversion file and configure the service.

Websocket online test.

View logs.

Conclusion:

This article uses THE WEBsocket interface of TB to convert formats to meet service requirements and prove the power of the Kettle platform. These features have been used in production environments and are very stable and reliable. The next article will show how TB interfaces can be aggregated to suit different business scenarios.