Author Topic: Node-Red to Classic Modbus for beginners  (Read 750 times)

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #15 on: October 03, 2018, 07:39:38 PM »
Has someone gotten this to work over ethernet?  I have Node-Red running.  I have the client node using the IP# of the Classic as it appears from my router.  I can ping the Classic and within Node-Red have a ModBus-read node using  port 502, type TCP, and DEFAULT TCP Type.  It keeps displaying "Error: Modbus exception 1" and wondering what I am doing wrong.

What modbus registers are you trying to read from the Classic ?

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

David

  • Jr. Member
  • **
  • Posts: 64
Re: Node-Red to Classic Modbus for beginners
« Reply #16 on: October 03, 2018, 11:49:06 PM »
Thanks Larry.  I was able to figure out my issue(s) after much trial and error.
  • Use FC 3: Read Holding Registers (I was using FC 4)
  • Need to subtract 1 from Modbus address that Midnite specifies, i.e. 4114 for bat voltage not 4115
  • TCP Type should be RTU-BUFFERED

After those changes I now can see my battery voltage being dumped to debugger.

Now trying to figure out how to display in node-red-dashboard.
 

RossW

  • Sr. Member
  • ****
  • Posts: 354
Re: Node-Red to Classic Modbus for beginners
« Reply #17 on: October 04, 2018, 07:31:37 AM »
It keeps displaying "Error: Modbus exception 1" and wondering what I am doing wrong.

Silly question, but do you have anything else reading the classic at the same time?
Eg, the local-app?
The classic only supports one modbus connection at a time, and if something else is using it, that could explain your errors?
3600W on 6 tracking arrays.
7200W on 2 fixed array.
Midnite Classic 150
Outback Flexmax FM80
16 x LiFePO4 600AH cells
16 x LiFePO4 300AH cells
Selectronics SP-PRO 481 5kW inverter
Fronius 6kW AC coupled inverter
Home-brew 4-cyl propane powered 14kVa genset
2kW wind turbine

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #18 on: October 04, 2018, 12:34:29 PM »
It keeps displaying "Error: Modbus exception 1" and wondering what I am doing wrong.

Silly question, but do you have anything else reading the classic at the same time?
Eg, the local-app?
The classic only supports one modbus connection at a time, and if something else is using it, that could explain your errors?

That is one advantage of hooking up the serial output since it will also work with the network side going too.

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #19 on: October 04, 2018, 12:37:37 PM »
Thanks Larry.  I was able to figure out my issue(s) after much trial and error.
  • Use FC 3: Read Holding Registers (I was using FC 4)
  • Need to subtract 1 from Modbus address that Midnite specifies, i.e. 4114 for bat voltage not 4115
  • TCP Type should be RTU-BUFFERED

After those changes I now can see my battery voltage being dumped to debugger.

Now trying to figure out how to display in node-red-dashboard.

Glad to hear you got it going. Look forward to seeing how you go about getting the data to display. I have not worked on Node Red more than I had in the initial post just because it got to be summer - maybe this winter I can dig back into it. Hopefully by the time maybe you will have something worked out and shared and save me a lot of effort !
We need someone like Ricardo to get a Classic because he is a whiz at Node Red for what he did with it for his Kid controller.

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

jedon

  • Newby
  • *
  • Posts: 11
Re: Node-Red to Classic Modbus for beginners
« Reply #20 on: October 17, 2018, 12:29:15 PM »
Here is my modbus parsing code.
Note that the classic seems very sensitive to multiple connections so I set my polling to 30s and only from one device.

You will need the modbustcp node

This is the code from  modbus to nodered

//[ 549, 19, 0, 94, 1027, 14, 650, 1417, 0, 46335, 20948, 0, 5381, 4380, 4100, 12800, 65326, 375, 450, 0, 600, 502, 15, 14400, 19 ]
/*
ChargeStage= [4120]MSB
Lifetime kW-Hours= (([4127] << 16) + [4126]) kWh
Infoflags = (([4131] << 16) + [4130])
FloatTimeToday= ([4138]) s
KwhToday=    ([4118]) kWh
Tbatt=   ([4132] /10) degC
Tfet=   ([4133] /10) degC
Vbatt= ([4115] /10) V
Ibatt= ([4117] /10) A
Vpv=    ([4116] /10) V
Ipv=    ([4121] /10) A
Watts= ([4119]) W
*/

var base = 4114;
var EMP = msg.payload[4131-base]/10.0

var newMsg = {
    payload: {
    BatteryVolts:msg.payload[4114-base]/10.0,
    TotalKWH:msg.payload[4117-base]/10.0,
    Watts:msg.payload[4118-base],
    AmpHours:msg.payload[4124-base]/10.0}
};
return newMsg;

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #21 on: October 17, 2018, 12:57:39 PM »
Thanks Jedon for sharing that .
Any chance you could copy the flow for that block like I did in this post  ?
http://midniteftp.com/forum/index.php?topic=4081.msg40102#msg40102
Then it is easy to just load that in the Node Red and the exact blocks you have will show up in our Node Red screens with all the associated logic and formulas.
I don't remember exactly how I copied that - but I can look it up sometime .
I am too busy with getting ready for winter stuff now to try out the Node Red - sunshine and no rain is rarity these days in Wisconsin !
thanks
Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

jedon

  • Newby
  • *
  • Posts: 11
Re: Node-Red to Classic Modbus for beginners
« Reply #22 on: October 23, 2018, 05:09:02 PM »
Sure, here:
Code: [Select]
[{"id":"8b332f45.a5e82","type":"function","z":"7126d246.da35cc","name":"ModBus to NodeRed Format","func":"//[ 549, 19, 0, 94, 1027, 14, 650, 1417, 0, 46335, 20948, 0, 5381, 4380, 4100, 12800, 65326, 375, 450, 0, 600, 502, 15, 14400, 19 ]\n/*\nChargeStage= [4120]MSB\nLifetime kW-Hours= (([4127] << 16) + [4126]) kWh\nInfoflags = (([4131] << 16) + [4130])\nFloatTimeToday= ([4138]) s\nKwhToday=    ([4118]) kWh\nTbatt=   ([4132] /10) degC\nTfet=   ([4133] /10) degC\nVbatt= ([4115] /10) V\nIbatt= ([4117] /10) A\nVpv=    ([4116] /10) V\nIpv=    ([4121] /10) A\nWatts= ([4119]) W\n\nWbJrPercentLeft is 4373\nWbJrRemainingAmpHours is 4377\nWbJrTotalAmpHours is 4381\n\n*/ \n\nvar base = 4114;\nvar EMP = msg.payload[4131-base]/10.0\n\nvar newMsg = {\n    payload: {\n    BatteryVolts:msg.payload[4114-base]/10.0,\n    TotalKWH:msg.payload[4117-base]/10.0,\n    Watts:msg.payload[4118-base],\n    AmpHours:msg.payload[4124-base]/10.0,\n    Vpv:msg.payload[4116-base]/10.0,\n    Ipv:msg.payload[4121-base]/10.0, \n    }\n};\nreturn newMsg;\n\n\n","outputs":1,"noerr":0,"x":374.9999313354492,"y":469.999963760376,"wires":[["d4f35a30.49c3f8","6d199560.c3177c"]]},{"id":"d4f35a30.49c3f8","type":"debug","z":"7126d246.da35cc","name":"","active":true,"console":"false","complete":"payload","x":396.99996185302734,"y":419.9999523162842,"wires":[]},{"id":"4c5183ae.ce4b2c","type":"modbustcp-read","z":"7126d246.da35cc","name":"Midnite Classic 150 ","dataType":"HoldingRegister","adr":"4114","quantity":"20","rate":"30","rateUnit":"s","server":"1764ed5a.412543","x":120.82637786865234,"y":469.8439064025879,"wires":[["8b332f45.a5e82"]]},{"id":"6d199560.c3177c","type":"mqtt out","z":"7126d246.da35cc","name":"MidniteClassic","topic":"MidniteClassic/BatteryVolts","qos":"","retain":"","broker":"884615ee.3ead88","x":617.9999885559082,"y":475.9999475479126,"wires":[]},{"id":"1764ed5a.412543","type":"modbustcp-server","z":"7126d246.da35cc","host":"192.168.2.103","port":"502","unit_id":"1","reconnecttimeout":"32"},{"id":"884615ee.3ead88","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #23 on: October 23, 2018, 05:45:29 PM »
Thanks Jedon ,
I pasted that flow in on my node red -  then loaded the modbustcp and changed the IP address to match mine and  it works !
though I had to remember that I had to shut off Local Status app first since only one tcp connection at at time.
Not sure when I get to it but I will remove the network and replace it with my serial connection which I had running earlier.
I like the way you get the data and convert it to display - I can understand how you did it .
I forgot how to see the data on a webpage - I was just looking at it in debug . Next time I play with it I will re-remember how to display that . At least I got Node Red running again pretty easily on my computer.
Appreciate you sharing this - saved me hours trying to figure out how to do that !

Larry
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #24 on: October 24, 2018, 12:27:36 PM »
I took Jedon's flow , removed the Classic network connection he had, the copy and pasted in the serial modbus connection I had previously and wired it in to Jedons Modbus to Node Red Format block and it works via serial . 

This is the serial block flow from my Classic that I pasted in

[{"id":"e777cb21.3043d8","type":"modbus-read","z":"db127068.f821d8","name":"Midnite Classic ","topic":"","showStatusActivities":false,"showErrors":false,"unitid":"10","dataType":"HoldingRegister","adr":"4131","quantity":"3","rate":"2","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"61de09d5.6be308","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":160,"y":320,"wires":[["d9fbc654.2d9128"],[]]},{"id":"61de09d5.6be308","type":"modbus-client","z":"","name":"Classic ","clienttype":"simpleser","bufferCommands":false,"stateLogEnabled":false,"tcpHost":"192.168.3.21","tcpPort":"502","tcpType":"TPC-RTU-BUFFERED","serialPort":"COM3","serialType":"RTU","serialBaudrate":"19200","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"10","commandDelay":"1","clientTimeout":"1000","reconnectTimeout":"2000"}]
system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie

jedon

  • Newby
  • *
  • Posts: 11
Re: Node-Red to Classic Modbus for beginners
« Reply #25 on: November 03, 2018, 05:29:03 PM »
Fantastic! I use the Node-Red built in UI code to generate gauges and graphs from the Classic data.
Here are the UI Nodes

Code: [Select]
[{"id":"fdc37f4e.d79b1","type":"mqtt in","z":"27cd102b.b84a5","name":"","topic":"MidniteClassic/BatteryVolts","qos":"2","broker":"884615ee.3ead88","x":296.1666564941406,"y":681.8000717163086,"wires":[["ea7d5a00.92fc98"]]},{"id":"b9104a38.308a78","type":"ui_gauge","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":3,"width":0,"height":0,"gtype":"gage","title":"Solar Panel Watts","label":"Watts","format":"{{value}}","min":"0","max":"5000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":930,"y":580,"wires":[]},{"id":"8ff1bdc3.68db6","type":"ui_chart","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":5,"width":"0","height":"0","label":"Solar Panel Watts Graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"No Data","dot":false,"ymin":"0","ymax":"5000","removeOlder":"12","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":950,"y":620,"wires":[[],[]]},{"id":"ea7d5a00.92fc98","type":"json","z":"27cd102b.b84a5","name":"","x":499.1666564941406,"y":680.1333389282227,"wires":[["82e00190.beaf7","7e4d55bf.32c21c","dfe48fb3.070b2"]]},{"id":"82e00190.beaf7","type":"change","z":"27cd102b.b84a5","name":"Watts","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Watts","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":640,"wires":[["b9104a38.308a78","8ff1bdc3.68db6","3ace8642.724a7a"]]},{"id":"3ace8642.724a7a","type":"function","z":"27cd102b.b84a5","name":"Date","func":"msg.payload = Date();\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":720,"wires":[["a322fa33.6a4758"]]},{"id":"a322fa33.6a4758","type":"ui_text","z":"27cd102b.b84a5","group":"bda2cbde.f2edc8","order":2,"width":0,"height":0,"name":"","label":"Solar Watts Timestamp","format":"{{msg.payload}}","layout":"row-spread","x":1150,"y":720,"wires":[]},{"id":"c9fa43ea.4a89c","type":"ui_gauge","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":7,"width":0,"height":0,"gtype":"gage","title":"Solar Panels - TotalKWH","label":"KW/Hours","format":"{{value}}","min":"0","max":"30","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":1510,"y":760,"wires":[]},{"id":"6d360c70.a5a9d4","type":"ui_chart","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":8,"width":"0","height":"0","label":"Solar Panels TotalKWH","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"No Data","dot":false,"ymin":"0","ymax":"25","removeOlder":"7","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":1506.0664367675781,"y":814.0666275024414,"wires":[[],[]]},{"id":"7e4d55bf.32c21c","type":"change","z":"27cd102b.b84a5","name":"TotalKWH","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.TotalKWH","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1153.9998779296875,"y":812.9999465942383,"wires":[["c9fa43ea.4a89c","6d360c70.a5a9d4","5ad57b5b.ccca94"]]},{"id":"5ad57b5b.ccca94","type":"function","z":"27cd102b.b84a5","name":"Date","func":"msg.payload = Date();\nreturn msg;","outputs":1,"noerr":0,"x":1446.0664367675781,"y":854.0666275024414,"wires":[["a1588468.e34ab8"]]},{"id":"a1588468.e34ab8","type":"ui_text","z":"27cd102b.b84a5","group":"bda2cbde.f2edc8","order":4,"width":0,"height":0,"name":"","label":"Solar Panel kW/h Timestamp","format":"{{msg.payload}}","layout":"row-spread","x":1676.0664367675781,"y":854.0666275024414,"wires":[]},{"id":"11fa3ccd.4e1303","type":"ui_gauge","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":1,"width":0,"height":0,"gtype":"gage","title":"BatteryVolts","label":"Volts","format":"{{value}}","min":"46","max":"63","colors":["#ff0000","#e6e600","#00b700"],"seg1":"","seg2":"","x":1810,"y":620,"wires":[]},{"id":"3b5845ba.552d8a","type":"ui_chart","z":"27cd102b.b84a5","name":"","group":"bda2cbde.f2edc8","order":9,"width":"0","height":"0","label":"BatteryVolts","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"No Data","dot":false,"ymin":"46","ymax":"63","removeOlder":"7","removeOlderPoints":"","removeOlderUnit":"86400","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":true,"x":1806.0664367675781,"y":674.0666275024414,"wires":[[],[]]},{"id":"dfe48fb3.070b2","type":"change","z":"27cd102b.b84a5","name":"BatteryVolts","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.BatteryVolts","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1503.9998779296875,"y":672.9999465942383,"wires":[["11fa3ccd.4e1303","3b5845ba.552d8a","1a37c91a.18dd97","22d5dca9.677f94"]]},{"id":"1a37c91a.18dd97","type":"function","z":"27cd102b.b84a5","name":"Date","func":"msg.payload = Date();\nreturn msg;","outputs":1,"noerr":0,"x":1786.0664367675781,"y":714.0666275024414,"wires":[["c71c4f75.09ba8"]]},{"id":"c71c4f75.09ba8","type":"ui_text","z":"27cd102b.b84a5","group":"bda2cbde.f2edc8","order":6,"width":0,"height":0,"name":"","label":"Battery Volts Timestamp","format":"{{msg.payload}}","layout":"row-spread","x":2006.0664367675781,"y":714.0666275024414,"wires":[]},{"id":"22d5dca9.677f94","type":"function","z":"27cd102b.b84a5","name":"Set global battery volts to midnite battery volts","func":"global.set(\"battery_volts\",msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":1930,"y":580,"wires":[[]]},{"id":"884615ee.3ead88","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"bda2cbde.f2edc8","type":"ui_group","z":"","name":"Darkling Power","tab":"fdc4aa12.d8f4f8","order":1,"disp":true,"width":"10","collapse":false},{"id":"fdc4aa12.d8f4f8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]

ClassicCrazy

  • Hero Member
  • *****
  • Posts: 1926
Re: Node-Red to Classic Modbus for beginners
« Reply #26 on: November 04, 2018, 09:27:52 PM »
thanks Jedon,
I copied your code - pasted it in my flow. But I have to go back and figure out how I did the display graphics because I don't remember how to get them up on the screen now.

Larry

system one
Classic 150 , 5s4p  Kyocera 135watt , 12s Soneil 2v 540amp lead crystal for 24v pack , Outback 3524 inverter
system two
Classic 150 ,5s 135 watt Kyocero , 16s Calb 100AH LiFePO4 , Outback VFX 3648 inverter
system three
Midnite KID MPPT 24 DC in to  12 volt AGM batterie