Comfoair Binding serial port

Dear all
I need a special advise.

I have openhab v2.3 running and Comfoair binding installed. The system is not productive yet.
In service/comfoair.cfg I have set the port /dev/ttyS4 to be used. That port is not existing it is created through a systemd service that calls socat

ExecStart=/usr/bin/socat pty,link=/dev/ttyS4,b9600,raw,echo=0 TCP:192.168.223.110:2021
---
root@orlando:/etc/openhab2/services# ls -l /dev/ttyS*
crw-rw---- 1 root dialout 4, 64 Aug  2 20:17 /dev/ttyS0
crw-rw---- 1 root dialout 4, 65 Aug  2 20:17 /dev/ttyS1
crw-rw---- 1 root dialout 4, 66 Aug  2 20:17 /dev/ttyS2
crw-rw---- 1 root dialout 4, 67 Aug  2 20:17 /dev/ttyS3
lrwxrwxrwx 1 root dialout    10 Aug  8 09:50 /dev/ttyS4 -> /dev/pts/1

I am able to establish a communication with minicom from the openhab host to the target serial port using a putty terminal attached.

the Comfoair binding reports anyway:
2018-08-08 09:54:39.722 [ERROR] [ng.comfoair.internal.ComfoAirBinding] - Serial port '/dev/ttyS4' could not be found. Available ports are:

How is the Binding using the defined interface?

Maybe the problem is with the socat command, but Iā€™m really scatching my head whit shouldnā€™t be possible that way.

EDIT:

In reference to: ā€œSerial port not recognizedā€, this was the solution. Thanks to Miika for bringing this in focus.

Kind regards
Stefan

Hi Stefan,

you need to include the non standard serial port in the EXTRA_JAVA_OPTS, like this:

EXTRA_JAVA_OPTS=ā€-Dgnu.io.rxtx.SerialPorts=/dev/ttyS4"

For openhab2 you should be able to set this in /etc/default/openhab2 (depending how you installed openhab2).

Regards,
Matt

Hi Matt

Thanks for that hint. Which I just tried out even with my personal expectation that it wouldnā€™t change anything.

The result is the same. Meanwhile I attached a USB to serial converter to the System. The output of openhab.log shows now:

2018-08-10 18:17:12.814 [ERROR] [ng.comfoair.internal.ComfoAirBinding] - Serial port '/dev/ttyS4' could not be found. Available ports are:
/dev/ttyUSB0

Which means that the binding is checking for physical presence of a serial port. Which is what I was hopeing to prevent with socat.
But the connection looks now as follows:

openHAB > USB-to-Serial ā†’ Serial-To-Ethernet Gateway ā†’ Ethernet-To-Serial Gateway > Serial Port to ComfoAir

I would appreciate for the future to extend the openHAB binding in that way, that i can directly communicate to an Ethernet-To-Serial Gateway or at least using a Virtual Serial Port connection (i.e. using socat).

Would ser2net be useful here?

Iā€™m sure you have checked but how have you configured permissions and usergroups. User openhab is in groups tty and dialout?

Hi Miika

Yes, iā€™ve checked that. Before I even started to play around with. I mean there is enough available on the internet. And the fact that a terminal to terminal connection worked nice shows that socat to Ethernet-To-Serial adapter is fine. Just the binding is not able to handle it.

Just for the fun. I have used port=TCP-ADDRESS:PORT instead of the /dev/tty?? the outcome of this was that the binding found the attached USB to serial adapter:

2018-08-09 19:00:15.799 [ERROR] [ng.comfoair.internal.ComfoAirBinding] - Serial port '192.168.223.110:2021' could not be found. Available ports are:
/dev/ttyUSB0

I also had a look at ser2net and tcpser, with no chance. And to my understanding ser2netā€™s operation mode is to provide a TCP Port to which i can connect with telnet and then it opens a Serial connection to an attached device. Please someone correct me if iā€™m wrong, but this is what I found in whatever guideline I went through.
tcpser even failed to startup with the configuration I tried as there was no serial device

2018-08-09 21:24:05:1365124864:ENTER_EXIT:Entering ctrl_thread function
2018-08-09 21:24:05:1365124864:FATAL:Could not obtain serial port status (Input/output error)

2018-08-09 21:24:05:1365124864:ENTER_EXIT:Exitting ctrl_thread function

Cheers
Stefan

1 Like

Hmm I just remembered that I previously had a working setup like yours. I implemented serial interface to a binding and had rs485 -> rpi2+ser2net - > ethernet - > socat - > /dev/ttySx connection for testing purposes. Just canā€™t remember all the details. Is the symlink created by socat?

If you have that port added to extra_java_opts what does ps -aux | grep ttyS4 output?

Just to be sure. What platform and what is your java version?

Hi Stefan,

Refering to your first post ā€œI am able to establish a communication with minicom from the openhab host to the target serial port using a putty terminal attached.ā€

Did you tried that with openhab user ?

If not, please try and let us know.

Hi

Did you tried that with openhab user ?

Yes, firstly I tried it as root which was working fine, later on I tested it as openhab user for what I had openhab to the dialout group first and it worked fine.

I used to start minicom with param -D /dev/ttyS4

Cheers
Stefan

Hi Miika

Yes the port /dev/ttyS4 is created by socat.

$ uname -a
Linux orlando 4.9.0-7-amd64 #1 SMP Debian 4.9.110-1 (2018-07-05) x86_64 GNU/Linux
$ java -version
openjdk version "1.8.0_171"
OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-1~deb9u1-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)

I donā€™t use the extra_java_opts for now as it doesnā€™t seem to significantly change something in this condition.

Cheers

Please read here: Creating Addon: Could not find artifact com.sunšŸ› jar:1.8.0 This topic is about maven builds but as Hans-Jƶrg states there are known problems with OpenJDK. It affects wether you are running openhab or anything related.

Please switch to Oracle or Zulu java and try again.

FYI I just checked the binding java code.

    } catch (NoSuchPortException e) {
        StringBuilder sb = new StringBuilder();
        @SuppressWarnings("rawtypes")
        Enumeration portList = CommPortIdentifier.getPortIdentifiers();
        while (portList.hasMoreElements()) {
            CommPortIdentifier id = (CommPortIdentifier) portList.nextElement();
            if (id.getPortType() == CommPortIdentifier.PORT_SERIAL) {
                sb.append(id.getName() + "\n");
            }
        }

        throw new InitializationException(
                "Serial port '" + port + "' could not be found. Available ports are:\n" + sb.toString());
    }

So maybe this is because /dev/ttyS4 is not defined as PORT_SERIAL.

If changing from OpenJDK to Oracle or Zulu does not resolve the problem, I suggest you could try to install Eclipse IDE with all configuration for Binding development. Then try to start Comfoair Binding and if it is still not working, try to update the code in src/main/java/org/openhab/binding/comfoair/handling/ComfoAirConnector.java around line 108 to log all ports and their type.

Imo if java canā€™t recognize your serial ports thereā€™s no use to alter any specific bindings code. The problem lies elsewhere.

Meanwhile I have changed to oracle Java

# java -version
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)

Changed the port to be used to /dev/ttyS0 and adjusted the socat start command accordingly (i.e using existing and not create own one)

Same issue, openHAB still tells me:

2018-08-11 13:42:01.067 [ERROR] [ng.comfoair.internal.ComfoAirBinding] - Serial port '/dev/ttyS0' could not be found. Available ports are:
/dev/ttyUSB0

I also added the EXTRA_JAVA_OPTS param again, just for the fun of it. which results in the same message as shown above.

# ps -aux | grep ttyS0
root     21587  0.0  0.0  24560  2032 ttyS0    Ss+  13:41   0:00 /usr/bin/socat /dev/ttyS0 TCP:192.168.223.110:2021

Cheers
Stefan

Did you restart OH after configuring extra_java_opts? And are you sure you have it configured correctly? Because grepping with ttyS0 it should display openhab process when you have -Dgnu.io.rxtx.SerialPorts=/dev/ttyS0 set up and picked up by java process when itā€™s starting.

Something like this:

# ps -aux | grep ttyS0
openhab  32590  7.2 15.0 4818524 605080 ?      Ssl  15:29   1:57 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2
-Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2
-Dopenhab.logdir=/var/log/openhab2 *-Dgnu.io.rxtx.SerialPorts=/dev/ttyS0* ....

This is indeed strange, it looks as the Param as not beeing promoted to the start sequence at all.

Nope but it could be a clue on what is going onā€¦

@smhaller have you read this? Looks alot like your case. Somekind of priviledge problem with socat.

1 Like

Miika

No I didnā€™t read that thread, thanks for that one. It seems to work! I will do sume further checks over the next days.

1 Like

Hi all,
Iā€™m sorry to ask this again, while reading that the Issue seems to be solved,ā€¦

Iā€™m better in german and total new in Linux/ Raspberry pi, but i hope you will halp me with my issue.

I try to select the correct port by serial ID like this:
port=/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0

But i get the same error as Stefan.
2020-01-23 15:29:31.698 [ERROR] [ng.comfoair.internal.ComfoAirBinding] - Serial port ā€˜/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0ā€™ could not be found. Available ports are:
/dev/ttyUSB0
/dev/ttyAMA0

Can someone help me with an easy solution to fix the ports?
I always need to reconfigure that, when the pi restarts.

I wold be soooooooooooooooooooo happy if there is someone who like to help me out.
Thx a Lot,
Mark

Hello,

First you have to run this command in terminal to see where your usb converter is linked to.

dmesg | grep tty

[17:44:42] openhabian@openhabian-server:~$ dmesg | grep tty
[    0.000000] console [tty0] enabled
[    1.411572] 00:01: ttyS0 at I/O 0x3f8 (irq = 4, base_baud = 115200) is a 16550A
[    1.432553] 00:02: ttyS1 at I/O 0x2f8 (irq = 3, base_baud = 115200) is a 16550A
[    1.491362] tty tty1: hash matches
[    6.702787] usb 1-4: FTDI USB Serial Device converter now attached to ttyUSB0
[    6.705346] usb 1-6: FTDI USB Serial Device converter now attached to ttyUSB1

Here you can see i have 2 usb converters ttyUSB0 and ttyUSB1
When you plug in 1 and run the command you can see where the usb converter is linked to.

When you reboot or plug the converter in or out, it is possible that it will change location.
you can create simlinks and then your usb converter is fixed to that port.
Here is a tutorial.