I’m trying to setup a serial connection to my Solar Inverter, which I’m currently using via perl but want to control directly from OpenHab.
I have created thing below and sending command but don’t see any of the items being updated.
I can see command was received via Perl script, but perhaps I’m missing something
when I sendCommand that items doesn’t update with output only the Command string
Any pointers would be appreciated.
Thing:
Bridge serial:serialBridge:inverter [serialPort="/dev/ttyS0", baudRate=9600,dataBits=8,parity="N" ] {
Thing serialDevice xantrex_inverter [patternMatch=".*"] {
Channels:
Type switch : inverter_status [command="INV?\n"]
Type number : power_in [commandFormat="%s?\n"]
Type number : power_out [commandFormat="%s?\n"]
Type number : kwh_today [commandFormat="%s?\n"]
Type number : kwh_life [commandFormat="%s?\n"]
Type number : kwh_life [commandFormat="%s?\n"]
Type string : energy []
}
}
script:
var inv=items.getItem("inv_energy");
inv.sendCommand("MEASENGY?\n");
console.log(inv );
Next question:
if I have 4 values I want to retrieve from Serial port and most are just numeric values, ie I can’t determine via RegEx which value relates to a specific channel/item.
it looks like the data received is Asynchronous to the command so do I need to “wait” for results?
What is the best Pattern extract ALL these values . As it seems if I send one command all the channels get that data.
eg here I want to get result of two or more commands. I have send command and then update the item
var wait_time=300
var response=items.getItem("inv_response");
var inv_e=items.getItem("inv_energy");
var inv_s=items.getItem("inv_status");
response.sendCommand("INV");
java.lang.Thread.sleep(wait_time);
inv_s.postUpdate(response.state);
console.log("INV="+ response.state );
response.sendCommand("MEASENGY");
java.lang.Thread.sleep(wait_time);
inv_e.postUpdate(response.state);
console.log("MEASENGY="+ response.state );
...
From vendor docs it looks like another adoption of CAN. You can even see CAN_L and CAN_H in RJ45 pin assignment.
Since CAN supports parallel access to the bus you may receive answers in different order than requests are sent (i.e other comms or broadcasts from inverter). Usually it is sufficient to pay attention to the can object id (COB ID) which is a number. Depending on the protocol version it can be 11 (2.0a) or 29 (2.0b) bits long.