[
  {
    "id": "a3050bb100000001",
    "type": "tab",
    "label": "02 Public Modbus TCP",
    "disabled": false,
    "info": "Public port 502 uses the WEM3050T three-phase layout. Selecting WEM2067 in the browser does not change it. Use zero-based addresses and high-word-first order."
  },
  {
    "id": "a3050bb100000002",
    "type": "comment",
    "z": "a3050bb100000001",
    "name": "Shared three-phase service: A = solar, B = grid, C = unused. Energy = raw value / 800.",
    "info": "This example uses the public simulator legacy registers. Check the model and firmware scaling before using a physical meter. This is not SunSpec.",
    "x": 390,
    "y": 70,
    "wires": []
  },
  {
    "id": "a3050bb100000003",
    "type": "modbus-read",
    "z": "a3050bb100000001",
    "name": "Read registers 0–37",
    "topic": "",
    "showStatusActivities": false,
    "logIOActivities": false,
    "showErrors": true,
    "showWarnings": true,
    "unitid": "1",
    "dataType": "HoldingRegister",
    "adr": "0",
    "quantity": "38",
    "rate": "10",
    "rateUnit": "s",
    "delayOnStart": true,
    "startDelayTime": "1",
    "server": "a3050bb100000006",
    "useIOFile": false,
    "ioFile": "",
    "useIOForPayload": false,
    "emptyMsgOnFail": false,
    "x": 180,
    "y": 180,
    "wires": [
      [
        "a3050bb100000004"
      ],
      []
    ]
  },
  {
    "id": "a3050bb100000004",
    "type": "function",
    "z": "a3050bb100000001",
    "name": "Decode power and energy",
    "func": "const r = msg.payload;\nif (!Array.isArray(r) || r.length < 38 || !r.every(v => Number.isInteger(v) && v >= 0 && v <= 65535)) {\n    node.error(\"Expected at least 38 valid 16-bit registers starting at address 0.\", msg);\n    return null;\n}\nconst u32 = i => r[i] * 65536 + r[i + 1];\nconst i32 = i => {const value = u32(i); return value >= 2147483648 ? value - 4294967296 : value;};\nconst channel = i => ({voltage_V:r[i]/100, current_A:r[i+1]/100, power_W:i32(i+2),\n    import_kWh:u32(i+4)/800, export_kWh:u32(i+6)/800, power_factor:r[i+8]/1000});\nmsg.payload = {source:\"Modbus/TCP\", model_register:r[9], updated_at:new Date().toISOString(),\n    A:channel(0), B:channel(10), C:channel(20), frequency_Hz:r[30]/100, total_power_W:i32(32),\n    total_import_kWh:u32(34)/800, total_export_kWh:u32(36)/800};\nflow.set(\"latestModbusReading\", msg.payload);\nnode.status({fill:\"green\",shape:\"dot\",text:\"Grid \" + msg.payload.B.power_W + \" W\"});\nreturn msg;",
    "outputs": 1,
    "timeout": 0,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 460,
    "y": 180,
    "wires": [
      [
        "a3050bb100000005"
      ]
    ]
  },
  {
    "id": "a3050bb100000005",
    "type": "debug",
    "z": "a3050bb100000001",
    "name": "Modbus three-phase readings",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "payload",
    "targetType": "msg",
    "x": 760,
    "y": 180,
    "wires": []
  },
  {
    "id": "a3050bb100000006",
    "type": "modbus-client",
    "name": "IAMMETER Public Simulator",
    "clienttype": "tcp",
    "bufferCommands": true,
    "stateLogEnabled": false,
    "queueLogEnabled": false,
    "failureLogEnabled": true,
    "tcpHost": "simulator.iammeter.com",
    "tcpPort": "502",
    "tcpType": "DEFAULT",
    "serialPort": "/dev/ttyUSB",
    "serialType": "RTU-BUFFERD",
    "serialBaudrate": "9600",
    "serialDatabits": "8",
    "serialStopbits": "1",
    "serialParity": "none",
    "serialConnectionDelay": "100",
    "serialAsciiResponseStartDelimiter": "0x3A",
    "unit_id": 1,
    "commandDelay": 1,
    "clientTimeout": 5000,
    "reconnectOnTimeout": true,
    "reconnectTimeout": 2000,
    "parallelUnitIdsAllowed": true,
    "showErrors": true,
    "showWarnings": true,
    "showLogs": false
  },
  {
    "id": "a3050bb100000007",
    "type": "catch",
    "z": "a3050bb100000001",
    "name": "Catch Modbus errors",
    "scope": null,
    "uncaught": false,
    "x": 200,
    "y": 290,
    "wires": [
      [
        "a3050bb100000008"
      ]
    ]
  },
  {
    "id": "a3050bb100000008",
    "type": "debug",
    "z": "a3050bb100000001",
    "name": "Modbus error",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "error",
    "targetType": "msg",
    "x": 470,
    "y": 290,
    "wires": []
  }
]