[SOLVED] Serial Binding OH2

Hey there,
I am useing OH2 on my Raspberry Pi. I want it to talk with my Arduino(with USB Serial) wich gets some sensor values.
I do not know how to use the 1x.Binding on OH2.
Thank you for your reply.

1 Like

Well, the good news is that its easy to do!

Create a file in conf/items/ called {filename}.items

Some examples of my items are:

String    Outside_Air_Sensor                                                                                                                                {serial="/dev/ttyPort0@9600,BASE64"}
String    Pool_ORP_Sensor                                                                                                                                     {serial="/dev/ttyPort4@9600"}
String    Pool_pH_Sensor                                                                                                                                      {serial="/dev/ttyPort5@9600"}
String    Softener_Salt_Level_Sensor                                                                                                                          {serial="/dev/ttyPort1@9600,BASE64"}
String    Hydrogen_Peroxide_Sensor                                                                                                                            {serial="/dev/ttyPort2@9600,BASE64"}
String    Septic_Level_Sensor                                                                                                                                 {serial="/dev/ttyPort3@9600"}

My ASCII sensors just have {port}@9600 and my binary sensors use {port}@9600,BASE64 also checkout the openHAB 1 serial binding wiki.

1 Like

Thank you for your fast answer.
I have my item file in /etc/openhab2/Items/home.items
So i have just created a new Item in this file:

String Arduino {serial="/dev/ttyACM0@9600"}

I have also made a rule to toggle the light:

rule "toggleLight"
    when 
        Item Arduino received command
    then
    if(LightOffON.state == ON)
    {
        LightOffON.state = OFF
    }
    else
        LightOffON.state = ON
    logInfo("Reched1-----------------","Reached1------------------")
end

I do not get the log result, but i think i have made something wrong with my Item.
I did test if the serial message comes in (works).
How do i exactly create the item?

I think your problem is received command, I looks like you want to do something when you receive ANYTHING on the serial port. So you could try:

Item Arduino received update

Received update does not change anything, but i really think something is false with the item. (i do not get any errors in the log)

Your item should be fine, what are you sending the serial port? Do you see anything in userdate/logs/events.log when you send data to the port?

The Arduino is sendeing the message “Toggle Light”. And i can not see anything about it in the events.log
I tried to get the message to see on a serial monitor (works fine, so the port is fine)
Do you know that i am useing openhab2?
Do I first have to make a thing and give the item then the channel of the thing?

Right, your not going to see anything about Toggle Light in the logs, its just text in the String Arduino. I wanted to know if you see anything about Arduino in the event.og.

The serial binding is for openHAB 1, so you don’t need to worry about channels or things.

1 Like

There is not anything about the Arduino String.

Not sure what to say, do you see any errors? I am still on openHAB 1.8.3 so I may not be able to help more.

You could try DEBUG, and also could try adding the following to userdata/etc/org.ops4j.pax.logging.cfg

# serial logger
log4j.logger.org.openhab.binding.serial = DEBUG, serial, osgi:*
log4j.appender.serial=org.apache.log4j.RollingFileAppender
log4j.appender.serial.layout=org.apache.log4j.PatternLayout
log4j.appender.serial.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} [%-26.26c{1}] - %m%n
log4j.appender.serial.file=${openhab.logdir}/serial.log
log4j.appender.serial.append=true
log4j.appender.serial.maxFileSize=100MB
log4j.appender.serial.maxBackupIndex=10

I do not get any errors. Maybe i have found something. In the wiki it says "If you are using non standard serial ports you have to
adapt start.sh to have the serial port included. the java command line
should then include the following parameters:

-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0

So maybe openhab is not useing the Port because of that. (is it possible?)

Yes, its possible, in openHAB 2 you can do that via an environment variable.

Try:
export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0"
./start_debug.sh

Should i just execute this command in the unix command line in the /usr/shared/openhab2 folder?

yep

I have found something in the log :

Binding configuration of type ‘serial’ of item ‘Arduino’ could not be parsed correctly.
org.eclipse.smarthome.model.item.BindingConfigParseException: Could not open serial port /dev/ttyACM0: Serial port ‘/dev/ttyACM0’ could not be found. Available ports are:

But nothing is listed after that. Maybe that would help us to find the solution. (the Arduino is definetly on /dev/ttyACM0)

Yep, you need to tell Java that it can use that port.

export EXTRA_JAVA_OPTS="-Dgnu.io.rxtx.SerialPorts=/dev/ttyACM0"
./start_debug.sh

<>
nathan stratton

1 Like

That does not change anything. :disappointed:

Now that is odd, I am not a debian fan so I don’t use the .deb package, but I thought that setting the env var would work. Your starting with ./start_debug.sh after export right? Or are you trying to start with system scripts?

1 Like