大神你好,我按照你教程出现以下问题,电表是派诺的导轨表。
请帮忙看看是那个数据不对。
[{“id”:“81e76ded.e0413”,“type”:“tab”,“label”:“流程 1”,“disabled”:false,“info”:""},{“id”:“53f713aa.02331c”,“type”:“comment”,“z”:“81e76ded.e0413”,“name”:“电表”,“info”:"",“x”:50,“y”:300,“wires”:[]},{“id”:“b2364e74.d1caf”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L电压”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“2”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:360,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“6b28b516.68074c”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L电流”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“3”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:400,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“bb4c64c4.ea99f8”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L功率”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“5”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:370,“y”:440,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“5fc3ed1f.eee5b4”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L度数”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“0”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:360,“y”:500,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“7d244333.da4d2c”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“数据转换”,“func”:“var data_hex1 = ‘0000’+msg.payload[0].toString(16);\nvar data_hex2 = ‘0000’+msg.payload[1].toString(16);\nvar value\nvar data_hex = data_hex1.substr(-4) + data_hex2.substr(-4);\n\nvar name\nswitch(msg.modbusRequest.address)\n{\n case “2”:\n name = “Voltage”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE().toFixed(2)*1\n break;\n case “3”:\n name = “Electric_current”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE().toFixed(2)*1\n break;\n case “5”:\n name = “Power”\n value = Buffer.from(data_hex, ‘hex’).readFloatBE()/1000\n value = value.toFixed(2)*1\n break;\n case “0”:\n name = “Energy_used”\n value = Buffer.from(data_hex, ‘hex’).readUInt32BE().toFixed(2)/10\n break;\n case “12”:\n name = “Power_factor”\n value = Buffer.from(data_hex, ‘hex’).readUInt32BE()\n}\n\nvar data={}\ndata[${name}
]=value\nmsg.payload = data;\nreturn msg;”,“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:570,“y”:360,“wires”:[[“eba64408.074a58”]]},{“id”:“957b0b6f.a3ed48”,“type”:“json”,“z”:“81e76ded.e0413”,“name”:"",“property”:“payload”,“action”:“str”,“pretty”:false,“x”:970,“y”:380,“wires”:[[“f91ba44a.58eff8”]]},{“id”:“eba64408.074a58”,“type”:“join”,“z”:“81e76ded.e0413”,“name”:"",“mode”:“custom”,“build”:“merged”,“property”:“payload”,“propertyType”:“msg”,“key”:“topic”,“joiner”:"\n",“joinerType”:“str”,“accumulate”:false,“timeout”:"",“count”:“5”,“reduceRight”:false,“reduceExp”:"",“reduceInit”:"",“reduceInitType”:"",“reduceFixup”:"",“x”:590,“y”:460,“wires”:[[“d722f760.e15338”,“5894f214.8dd50c”]]},{“id”:“d722f760.e15338”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“阶梯电价”,“func”:"// 通过当月月份判断阶梯一的阈值\nfunction Get_level_One_threshold(){\n var Month = new Date().getMonth() + 1\n if (Month >= 5 && Month <= 10) {\n return 260\n } else {\n return 200\n }\n}\n// 返回计算结果函数\nfunction Result_obj(){\n Total_cost = Level_One_cost + Level_Two_cost + Level_Three_cost\n return {\n “Level_One”:{\n “used”:Level_One_used,\n “univalent”:Level_One_univalent,\n “cost”:Level_One_cost.toFixed(2)*1\n },\n “Level_Two”:{\n “used”:Level_Two_used,\n “univalent”:Level_Two_univalent,\n “cost”:Level_Two_cost.toFixed(2)*1\n },\n “Level_Three”:{\n “used”:Level_Three_used,\n “univalent”:Level_Three_univalent,\n “cost”:Level_Three_cost.toFixed(2)*1\n },\n “Total_cost”: Total_cost.toFixed(2)*1\n }\n}\n\nvar energy_used = msg.payload.Energy_used\n\nvar Level_Two = false\nvar Level_Three = false\n\nvar Level_One_cost = 0\nvar Level_Two_cost = 0\nvar Level_Three_cost = 0\nvar Total_cost = 0\n\nvar Level_One_used = 0\nvar Level_Two_used = 0\nvar Level_Three_used = 0\n\n// 阶梯一电费单价\nvar Level_One_univalent=0.61886875\n// 阶梯二电费单价\nvar Level_Two_univalent=0.66886875\n// 阶梯三电费单价\nvar Level_Three_univalent=0.91886875\n// 获取阶梯一阈值\nvar Level_One_threshold = Get_level_One_threshold()\n// 获取阶梯二阈值\nvar Level_Two_threshold = 600\n\n// 阶梯一\nif (energy_used > Level_One_threshold ) {\n Level_One_used = Level_One_threshold\n Level_One_cost = Level_One_used * Level_One_univalent\n}\nelse {\n Level_One_used = energy_used\n Level_One_cost = Level_One_used * Level_One_univalent\n msg.payload = Result_obj()\n return msg;\n}\n\n// 阶梯二和三\nif (energy_used > Level_Two_threshold ) {\n Level_Two_used = Level_Two_threshold\n Level_Two_cost = Level_Two_threshold * Level_Two_univalent\n Level_Three_used = energy_used - Level_One_threshold - Level_Two_threshold\n Level_Three_cost = Level_Three_used * Level_Three_univalent\n}\nelse {\n Level_Two_used = energy_used - Level_One_threshold\n Level_Two_cost = Level_Two_used * Level_Two_univalent\n}\n\n\nmsg.payload = Result_obj()\nreturn msg",“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:760,“y”:500,“wires”:[[“55a05fc8.7e3f7”,“c7e70174.ed65d”]]},{“id”:“616b1c75.c18f54”,“type”:“mqtt in”,“z”:“81e76ded.e0413”,“name”:“刷新”,“topic”:“DDSD720-L/Refresh”,“qos”:“2”,“datatype”:“auto”,“broker”:“db831950.868148”,“x”:110,“y”:500,“wires”:[[“b2364e74.d1caf”,“6b28b516.68074c”,“5fc3ed1f.eee5b4”,“bb4c64c4.ea99f8”,“84a63db2.65fdb”]]},{“id”:“55a05fc8.7e3f7”,“type”:“json”,“z”:“81e76ded.e0413”,“name”:"",“property”:“payload”,“action”:“str”,“pretty”:false,“x”:910,“y”:460,“wires”:[[“4c7b061.150b8f8”]]},{“id”:“4c7b061.150b8f8”,“type”:“mqtt out”,“z”:“81e76ded.e0413”,“name”:"",“topic”:“DDSD720-L/cost”,“qos”:“0”,“retain”:“true”,“broker”:“db831950.868148”,“x”:1070,“y”:460,“wires”:[]},{“id”:“5894f214.8dd50c”,“type”:“function”,“z”:“81e76ded.e0413”,“name”:“计算当天用电量”,“func”:"\nvar zeroTime_Energy_used = context.get(‘zeroTime_Energy_used’);\nvar date = context.get(‘zeroTime_Energy_date’);\n// 如果当前触发时间是0点,并且存储在节点变量日期不是当前日期,则记录下当前的度数\n// 作为当日初始度数。\nif ( new Date().getHours() == 0 && date != new Date().getDate() ){\n zeroTime_Energy_used = msg.payload.Energy_used;\n context.set(‘zeroTime_Energy_used’,zeroTime_Energy_used)\n context.set(‘zeroTime_Energy_date’,new Date().getDate())\n}\n// 当前用电量-今日用电量=今日用电量\nvar Today_Energy_Used = (msg.payload.Energy_used - zeroTime_Energy_used).toFixed(2)*1;\nmsg.payload.Today_Energy_Used = Today_Energy_Used;\nreturn msg;",“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“x”:810,“y”:380,“wires”:[[“957b0b6f.a3ed48”]]},{“id”:“84a63db2.65fdb”,“type”:“modbus-getter”,“z”:“81e76ded.e0413”,“name”:“DDSD720-L功率因数”,“showStatusActivities”:false,“showErrors”:false,“logIOActivities”:false,“unitid”:“20”,“dataType”:“HoldingRegister”,“adr”:“12”,“quantity”:“2”,“server”:“26fd2f5d.e1cab”,“useIOFile”:false,“ioFile”:"",“useIOForPayload”:false,“emptyMsgOnFail”:false,“keepMsgProperties”:false,“x”:380,“y”:540,“wires”:[[“7d244333.da4d2c”],[]]},{“id”:“f91ba44a.58eff8”,“type”:“mqtt out”,“z”:“81e76ded.e0413”,“name”:"",“topic”:“DDSD720-L/data”,“qos”:“0”,“retain”:“true”,“broker”:“db831950.868148”,“x”:1150,“y”:360,“wires”:[]},{“id”:“c7e70174.ed65d”,“type”:“debug”,“z”:“81e76ded.e0413”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:990,“y”:560,“wires”:[]},{“id”:“8cd8bbe4.7ebef8”,“type”:“cronplus”,“z”:“81e76ded.e0413”,“name”:“每10分钟执行一次”,“outputField”:“payload”,“timeZone”:"",“persistDynamic”:false,“commandResponseMsgOutput”:“output1”,“outputs”:1,“options”:[{“name”:“每10分钟执行一次”,“topic”:“每10分钟执行一次”,“payloadType”:“str”,“payload”:"",“expressionType”:“cron”,“expression”:“0 0/10 * * * ? “,“location”:””,“offset”:“0”,“solarType”:“all”,“solarEvents”:“sunrise,sunset”}],“x”:110,“y”:360,“wires”:[[“b2364e74.d1caf”,“6b28b516.68074c”,“bb4c64c4.ea99f8”,“5fc3ed1f.eee5b4”,“84a63db2.65fdb”]]},{“id”:“26fd2f5d.e1cab”,“type”:“modbus-client”,“z”:"",“name”:"",“clienttype”:“tcp”,“bufferCommands”:true,“stateLogEnabled”:false,“queueLogEnabled”:false,“tcpHost”:“192.168.31.38”,“tcpPort”:“2020”,“tcpType”:“DEFAULT”,“serialPort”:"/dev/ttyUSB",“serialType”:“RTU-BUFFERD”,“serialBaudrate”:“9600”,“serialDatabits”:“8”,“serialStopbits”:“1”,“serialParity”:“none”,“serialConnectionDelay”:“100”,“unit_id”:“1”,“commandDelay”:“1”,“clientTimeout”:“1000”,“reconnectOnTimeout”:true,“reconnectTimeout”:“2000”,“parallelUnitIdsAllowed”:true},{“id”:“db831950.868148”,“type”:“mqtt-broker”,“z”:"",“name”:“hassio-mqtt-HA”,“broker”:“127.0.0.1”,“port”:“1883”,“clientid”:“nodered-client”,“usetls”:false,“compatmode”:true,“keepalive”:“60”,“cleansession”:true,“birthTopic”:"",“birthQos”:“0”,“birthPayload”:"",“closeTopic”:"",“closeQos”:“0”,“closePayload”:"",“willTopic”:"",“willQos”:“0”,“willPayload”:""}]