Enviar e Receber dados MQTT com ScadaBR pelo Node-RED

Olá, vou demonstrar uma forma para enviar e receber dados MQTT com o ScadaBR pelo Node-Red.

Data source virtual apenas para simulação de valores
image

Publisher envia dados do data source virtual para o Node-RED
Não incluir timestamp

Node-RED configurado para receber e reenviar dados

Data source receptor HTTP para receber valores
image

Resultado Final

Com essa implementação fica demonstrada uma simples maneira de enviar dados do ScadaBR por MQTT como tambem receber.

Json ScadaBR

{
   "graphicalViews":[
   ],
   "dataSources":[
      {
         "xid":"DS_992547",
         "type":"VIRTUAL",
         "updatePeriodType":"SECONDS",
         "enabled":true,
         "name":"ENVIAR NODERED\/MQTT",
         "updatePeriods":10
      },
      {
         "xid":"DS_161663",
         "type":"HTTP_RECEIVER",
         "deviceIdWhiteList":[
            "*"
         ],
         "enabled":true,
         "ipWhiteList":[
            "*.*.*.*"
         ],
         "name":"RECEBER NODERED\/MQTT"
      }
   ],
   "dataPoints":[
      {
         "xid":"DP_114918",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"BINARY",
            "changeType":{
               "type":"NO_CHANGE",
               "startValue":"0"
            },
            "settable":true
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_992547",
         "defaultCacheSize":1,
         "deviceName":"ENVIAR NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"BIN",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      },
      {
         "xid":"DP_052981",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"NUMERIC",
            "changeType":{
               "type":"NO_CHANGE",
               "startValue":"0"
            },
            "settable":true
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_992547",
         "defaultCacheSize":1,
         "deviceName":"ENVIAR NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"INT",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      },
      {
         "xid":"DP_600541",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"NUMERIC",
            "changeType":{
               "type":"NO_CHANGE",
               "startValue":"0"
            },
            "settable":true
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_992547",
         "defaultCacheSize":1,
         "deviceName":"ENVIAR NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"FLOAT",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      },
      {
         "xid":"DP_058260",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"NUMERIC",
            "binary0Value":"",
            "parameterName":"INT"
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_161663",
         "defaultCacheSize":1,
         "deviceName":"RECEBER NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"INT",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      },
      {
         "xid":"DP_569236",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"BINARY",
            "binary0Value":"",
            "parameterName":"BIN"
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_161663",
         "defaultCacheSize":1,
         "deviceName":"RECEBER NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"BIN",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      },
      {
         "xid":"DP_722462",
         "loggingType":"ON_CHANGE",
         "intervalLoggingPeriodType":"MINUTES",
         "intervalLoggingType":"INSTANT",
         "purgeType":"YEARS",
         "pointLocator":{
            "dataType":"NUMERIC",
            "binary0Value":"",
            "parameterName":"FLOAT"
         },
         "eventDetectors":[
         ],
         "engineeringUnits":"",
         "chartColour":null,
         "chartRenderer":null,
         "dataSourceXid":"DS_161663",
         "defaultCacheSize":1,
         "deviceName":"RECEBER NODERED\/MQTT",
         "discardExtremeValues":false,
         "discardHighLimit":1.7976931348623157E308,
         "discardLowLimit":-1.7976931348623157E308,
         "enabled":true,
         "intervalLoggingPeriod":15,
         "name":"FLOAT",
         "purgePeriod":1,
         "textRenderer":{
            "type":"PLAIN",
            "suffix":""
         },
         "tolerance":0.0
      }
   ],
   "scheduledEvents":[
   ],
   "compoundEventDetectors":[
   ],
   "pointLinks":[
   ],
   "users":[
      {
         "admin":true,
         "disabled":false,
         "email":"admin@yourMangoDomain.com",
         "homeUrl":"",
         "password":"0DPiKuNIrrVmD8IUCuw1hQxNqZc=",
         "phone":"",
         "receiveOwnAuditEvents":false,
         "userProfile":0,
         "username":"admin"
      }
   ],
   "mailingLists":[
   ],
   "publishers":[
      {
         "xid":"PUB_190018",
         "type":"HTTP_SENDER",
         "points":[
            {
               "dataPointId":"DP_114918",
               "includeTimestamp":false,
               "parameterName":"BIN"
            },
            {
               "dataPointId":"DP_600541",
               "includeTimestamp":false,
               "parameterName":"FLOAT"
            },
            {
               "dataPointId":"DP_052981",
               "includeTimestamp":false,
               "parameterName":"INT"
            }
         ],
         "snapshotSendPeriodType":"SECONDS",
         "dateFormat":"DATE_FORMAT_BASIC",
         "cacheWarningSize":10000,
         "changesOnly":false,
         "enabled":true,
         "name":"ENVIAR PARA NODERED",
         "raiseResultWarning":true,
         "sendSnapshot":true,
         "snapshotSendPeriods":30,
         "staticHeaders":[
         ],
         "staticParameters":[
         ],
         "url":"http:\/\/localhost:1880\/nodered",
         "usePost":false
      }
   ],
   "pointHierarchy":[
   ],
   "eventHandlers":[
   ],
   "watchLists":[
      {
         "xid":"WL_757103",
         "user":"admin",
         "dataPoints":[
            "DP_114918",
            "DP_600541",
            "DP_052981",
            "DP_569236",
            "DP_722462",
            "DP_058260"
         ],
         "sharingUsers":[
         ],
         "name":"(sem nome)"
      }
   ],
   "maintenanceEvents":[
   ],
   "scripts":[
   ],
   "systemSettings":[
      {
         "filedata.path":"~\/WEB-INF\/filedata",
         "reportPurgePeriods":1,
         "language":"pt",
         "futureDateLimitPeriodType":3,
         "httpClientProxyUsername":"",
         "eventPurgePeriodType":7,
         "httpClientProxyPort":-1,
         "httpdsPrologue":"",
         "uiPerformance":2000,
         "emailSmtpHost":"",
         "plotGridlineColour":"silver",
         "emailSmtpPassword":"",
         "httpdsEpilogue":"",
         "databaseSchemaVersion":"1.2.0",
         "emailFromAddress":"",
         "groveLogging":false,
         "reportPurgePeriodType":6,
         "futureDateLimitPeriods":24,
         "plotBackgroundColour":"white",
         "httpClientProxyPassword":"",
         "instanceDescription":"ScadaBR 1.2",
         "emailFromName":"ScadaBR",
         "newVersionNotificationLevel":"S",
         "emailSmtpPort":25,
         "httpClientProxyServer":"",
         "chartBackgroundColour":"white",
         "emailSmtpUsername":"",
         "eventPurgePeriods":1
      }
   ]
}

Json Node-RED

[
    {
        "id": "d91d72c8e2657eef",
        "type": "tab",
        "label": "ScadaBR / Node-RED",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "af07bd6f91ed13b4",
        "type": "http in",
        "z": "d91d72c8e2657eef",
        "name": "",
        "url": "/nodered",
        "method": "get",
        "upload": false,
        "swaggerDoc": "",
        "x": 150,
        "y": 80,
        "wires": [
            [
                "7b8bc56509da3d01",
                "915e1e522de500f0",
                "6d4983fb09b63e74"
            ]
        ]
    },
    {
        "id": "915e1e522de500f0",
        "type": "template",
        "z": "d91d72c8e2657eef",
        "name": "",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "",
        "output": "str",
        "x": 360,
        "y": 80,
        "wires": [
            [
                "4f89aa1c956570ef"
            ]
        ]
    },
    {
        "id": "4f89aa1c956570ef",
        "type": "http response",
        "z": "d91d72c8e2657eef",
        "name": "",
        "statusCode": "",
        "headers": {},
        "x": 510,
        "y": 80,
        "wires": []
    },
    {
        "id": "7b8bc56509da3d01",
        "type": "split",
        "z": "d91d72c8e2657eef",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 350,
        "y": 160,
        "wires": [
            [
                "40bfbd2cdbfa2437"
            ]
        ]
    },
    {
        "id": "40bfbd2cdbfa2437",
        "type": "switch",
        "z": "d91d72c8e2657eef",
        "name": "",
        "property": "parts.key",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "BIN",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "INT",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "FLOAT",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 510,
        "y": 160,
        "wires": [
            [
                "6df59cd2d42bf5d3",
                "37068b31e9434fee"
            ],
            [
                "e4f16e364b94bd7d",
                "61735ccce32ef5b4"
            ],
            [
                "bb702970264575d4",
                "eced54c26ca29ab9"
            ]
        ]
    },
    {
        "id": "6df59cd2d42bf5d3",
        "type": "mqtt out",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "BIN",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "58ca3c9651cb1016",
        "x": 670,
        "y": 100,
        "wires": []
    },
    {
        "id": "e4f16e364b94bd7d",
        "type": "mqtt out",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "INT",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "58ca3c9651cb1016",
        "x": 670,
        "y": 160,
        "wires": []
    },
    {
        "id": "bb702970264575d4",
        "type": "mqtt out",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "FLOAT",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "58ca3c9651cb1016",
        "x": 680,
        "y": 220,
        "wires": []
    },
    {
        "id": "f0a957ea74458407",
        "type": "join",
        "z": "d91d72c8e2657eef",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 340,
        "y": 400,
        "wires": [
            [
                "c8bb18a6875c200b",
                "3e0770a11635f2f3"
            ]
        ]
    },
    {
        "id": "c8bb18a6875c200b",
        "type": "http request",
        "z": "d91d72c8e2657eef",
        "name": "http://localhost:8080/ScadaBR/httpds",
        "method": "GET",
        "ret": "txt",
        "paytoqs": "query",
        "url": "http://localhost:8080/ScadaBR/httpds",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 610,
        "y": 400,
        "wires": [
            [
                "58cee4ca60010472"
            ]
        ]
    },
    {
        "id": "8f5c5f5d81e5e368",
        "type": "mqtt in",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "BIN",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "58ca3c9651cb1016",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 400,
        "wires": [
            [
                "f0a957ea74458407"
            ]
        ]
    },
    {
        "id": "a8b7d4fc0e2e166b",
        "type": "mqtt in",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "INT",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "58ca3c9651cb1016",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 460,
        "wires": [
            [
                "f0a957ea74458407"
            ]
        ]
    },
    {
        "id": "7945d4fe5a11a867",
        "type": "mqtt in",
        "z": "d91d72c8e2657eef",
        "name": "",
        "topic": "FLOAT",
        "qos": "2",
        "datatype": "auto-detect",
        "broker": "58ca3c9651cb1016",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 130,
        "y": 520,
        "wires": [
            [
                "f0a957ea74458407"
            ]
        ]
    },
    {
        "id": "37068b31e9434fee",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 12",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 820,
        "y": 100,
        "wires": []
    },
    {
        "id": "61735ccce32ef5b4",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 13",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 820,
        "y": 160,
        "wires": []
    },
    {
        "id": "eced54c26ca29ab9",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 14",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 820,
        "y": 220,
        "wires": []
    },
    {
        "id": "3e0770a11635f2f3",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 15",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 520,
        "y": 460,
        "wires": []
    },
    {
        "id": "58cee4ca60010472",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 16",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 880,
        "y": 400,
        "wires": []
    },
    {
        "id": "6d4983fb09b63e74",
        "type": "debug",
        "z": "d91d72c8e2657eef",
        "name": "debug 17",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 380,
        "y": 220,
        "wires": []
    },
    {
        "id": "3e702301bc94383d",
        "type": "comment",
        "z": "d91d72c8e2657eef",
        "name": "RECEBE DADOS SCADABR E ENVIA PARA O BROKER",
        "info": "",
        "x": 290,
        "y": 40,
        "wires": []
    },
    {
        "id": "bfb272f9a40d66da",
        "type": "comment",
        "z": "d91d72c8e2657eef",
        "name": "RECEBE DADOS DO BROKER E ENVIA PARA O SCADABR",
        "info": "",
        "x": 300,
        "y": 360,
        "wires": []
    },
    {
        "id": "58ca3c9651cb1016",
        "type": "mqtt-broker",
        "name": "",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]

Boa Sorte!!

3 curtidas

@CarlosOliveira
Que bacana sua postagem, conteúdo valiosíssimo.

Vlw

1 curtida