How-To : Install and Run VelServ - a Velbus TCP Gateway

In this How to, @jeroends and I will try to briefly explain how to download, compile and auto-start VelServ.
A simple and effective Linux TCP server for Velbus.

If you are a Windows user and need a TCP server for Velbus, then @Golfy has created a great purebasic application that can be found here : https://forumtest.velbus.eu/t/an-other-velbus-server-purebasic/5523/53

Download the VelServ code

For now, you can download VelServ 1.5 in a neat Zip file from my website, this will be moved to GitHub soon (This post will be updated)

velserv1.5.zip

The Zip file contains :-

Compile.txt - An archive file with how to use GCC to compile for your Linux OS
readme.txt - A brief explanation of how to compile velserv for your Linux OS and how to run the velserv.service file
top-velserv.sh - A Linux script to run TOP with a filter for Velserv, a historical script I used before using systemd
velserv.c - the C code for Velserv 1.5
velserv.service - The Linux SystemD service file, set to use port /dev/ttyACM0 and port 6000
velserv.sh - A script file to simplify starting VelServ with startup values that differ from the defaults
Version-1.5.txt - A version ID file

How To

For now it is just the text from the readme.txt file

source can be downloaded at the following link: leachy.homeip.net/velbus/velserv.c

Use GCC to compile the C code for your system

sudo apt-get install gcc

Or

sudo apt-get install build-essential

Use this command line to compile for your system

gcc -o velserv velserv.c -lpthread

Usage: ./velserv -csfvhV] -d DEVICE] -a ADDRESS] -p PORT]
Tip : try to run as root

-s --server act as server only, gateway will be disabled
when in server mode, the address is always 127.0.0.1
-c --client act as client only, server wil be disabled
-d --device INTERFACE device where the Velbus interface is connected to
default device is: /dev/ttyACM0
-a --address HOST IP address or hostname where to connect to as client
default is 127.0.0.1
-p --port port where to connect
default is 3788
-f --foreground do not run in background
-v --verbose verbose operation, repeat for debugging output
1 general debug, 2-3 com to socket debug, 4-6 server socket debug
-h --help print this help and exit
-V --version print version information and exit

An example

To start VelServ and use /dev/ttyACM0 and port 6000, the following command line should be used

sudo ./velserv -d /dev/ttyACM0 -p 6000

VelServ as a Linux Service

When enabled, the velserv.service file starts, stops and restarts VelServ as a service in Linux systems that support SystemD.

The velserv.service file is set to use device /dev/ttyACM0 and port 6000, if you wish a different configuration, please edit the service file, you will find the parameters in a line towards the end that starts ExecStart=/opt/velserv

Move the velserv.service file into /etc/systemd/system/

{You can create a symlink if you wish}

with the compiled velserv application in /opt/velserv/ {Edit the verserv.service file if your ./velserv application is in a different folder}

run the following commands to activate velserv.service

sudo systemctl daemon-reload

sudo systemctl enable velserv.service

reboot to get VelServ to load on boot, or to start the service now :-

sudo systemctl start velserv

you can also use

sudo systemctl restart velserv

sudo systemctl stop velserv

or any user can use

systemctl status velserv

Useful Links from this forum

Swapping OpenHab2 from a Serial Bridge to a Network bridge

https://forumtest.velbus.eu/t/velbus-binding-for-openhab/14992/108

3 Likes

Hi guys

You have helped me already in another thread: Velbus binding for OpenHAB

Now I’m trying to get velserv running (I used Velbus binding connecting to Velser but it’s similar to this thread).
I get following error when trying to enable velserv.service:
Failed to enable unit: File velserv.service: Bad message

When checking the status I get this:
● velserv.service
Loaded: error (Reason: Bad message)
Active: inactive (dead)

Jan 04 12:34:31 openHABianPi systemd[1]: [/etc/systemd/system/velserv.service:9] Invalid section header

Any idea what’s going wrong?

Hi :slight_smile:

There’s your problem…

“Invalid Section Header”

It doesn’t like something in the service file I wrote.
(Which isn’t surprising, as I’ll happily confess that I know little to nothing about coding)

You could try deleting this “file present” checking Unit?

File velserv.service

Failed to enable unit: File velserv.service: Bad message

So…

Can you start VelServ via a command line ?

something like :

./velserv -p 6000 -d /dev/ttyACM0

Assuming that your USB device is mapped to ttyACM0

Check out this post for more information - USB Problems on linux - #8 by MDAR - Beginners - openHAB Community

Then use

pidof velserv

To confirm that it’s loaded and running.

(Which is all that the service file is doing)

Once you’ve got VelServ running manually, you can look into what’s wrong with the service file.

FYI, the service file is working for me on a number of machines, running Debian or Ubuntu.

It’s very possible that Raspberry Pi needs something different in the velserv.service file to get it running.

I hope this helps you.

FYI

When you say that this topic is “similar” to the one on the openHAB forum, do you mean that it almost looks like someone has “copied” it? :wink:

@MDAR
You did it again :slight_smile:

I tried to start the system with

Then

I got the number 3809, which (I suppose) means that it’s running.
Then I just started “cleaning up” the velserv.service, meaning I put everything on a new line when I felt it should :smile:

I rebooted, and then this is what happened:

[17:56:19] openhabian@openHABianPi:~$ systemctl status velserv
● velserv.service - Velserv
Loaded: loaded (/etc/systemd/system/velserv.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-01-04 17:56:11 CET; 42s ago
Process: 475 ExecStartPost=/bin/bash -c /bin/pidof velserv >> /var/log/velserv.log (code=exited, status=0/SUCCESS)
Process: 462 ExecStartPost=/bin/bash -c /bin/echo Velserv Started $(date) >> /var/log/velserv.log (code=exited, status=0/SUCCE
Process: 430 ExecStartPost=/bin/bash -c /bin/touch /var/log/velserv.log (code=exited, status=0/SUCCESS)
Process: 413 ExecStart=/opt/velserv/velserv -d /dev/ttyACM0 -p 6000 (code=exited, status=0/SUCCESS)
Main PID: 426 (velserv)
CGroup: /system.slice/velserv.service
└─426 /opt/velserv/velserv -d /dev/ttyACM0 -p 6000

Jan 04 17:56:11 openHABianPi systemd[1]: Starting Velserv…
Jan 04 17:56:11 openHABianPi systemd[1]: Started Velserv.

[17:57:09] openhabian@openHABianPi:~$ pidof velserv
426

So I guess it works now, I can connect with Velbuslink over TCP/IP, so that’s great.
Just to be sure, I’m gonna reboot the RPi again, and test if I can connect with Velbuslink

I’ll reply if it’s still OK.

1 Like

Yep! Works perfect!

Again, many thanks for the quick help.

About this:

You actually thanked the author for referencing to your website…
But I honestly have to say, his explanation was more understandable than yours :stuck_out_tongue:
I’m pretty sure the problem lies with me, since I know sh*t about linux coding.

Anyway, I got Velserv working, so I’m happy :smiley:

I’ll take that on the chin :slight_smile:

I am very happy that you’ve got it all up and running :slight_smile:

If you’d care to share your modified velserv.service file. I’ll drop it into the zip file so someone else can benefit :smile:

Offcourse! I’m happy if I can help someone else :smile:
Here’s the text to put in velserv.service:

[Unit]
Description=Velserv
ConditionFileIsExecutable=/opt/velserv/velserv.sh
After=network.target
After=network-online.target

[Service]
Type=forking
ExecStart=/opt/velserv/velserv -d /dev/ttyACM0 -p 6000
ExecStartPost=/bin/bash -c “/bin/touch /var/log/velserv.log”
ExecStartPost=/bin/bash -c “/bin/echo Velserv Started $(date) >> /var/log/velserv.log”
ExecStartPost=/bin/bash -c “/bin/pidof velserv >> /var/log/velserv.log”
ExecStop=/bin/kill $MAINPID
TimeoutSec=0
RemainAfterExit=yes
StandardOutput=journal+console
StandardError=journal+console

[Install]
WantedBy=multi-user.target

This works for me. I hope someone else can test it and confirm it works for them too.

Greets!

1 Like

Hello all.

If assigning USB devices to the same ttyACM port at boot up in Linux is an issue, give this a try :

./velserv -d /dev/serial/by-id/usb-Velleman_Projects_VMB1USB_Velbus_USB_interface-if00

Please post your results, as this is just something we’re experimenting with.

Hi guys.

I just wanted to let you guys know that I have disabled the Velserv service, as it interfered with the status-updates in Habpanel. Statuses weren’t shown correct when I pushed a button, temperatures were N/A.
So I disabled the service, and stopped it. Now, whenever I need it, I just start the service, and then stop it again after I have used it.

Still very happy that I don’t have to use a USB-cable anymore to change something with Velbuslink. :grinning::+1:

That’s not a condition that I’ve seen before.

Are you still trying to use a Velbus Serial Bridge in openHAB2?

Or have you created a Velbus Network Bridge in openHAB2 and pointed it to VelServ?

FYI

I haven’t used a direct USB connection (serial bridge) in openHAB2 since Cédric added the Network Bridge.

It’s easy enough to swap your Velbus Things over to a new bridge in openHAB2.

  • Just set up the new Velbus Network Bridge in paperUI. Using the correct IP and port (don’t use localhost, its better to use 127.0.0.1 on the same machine)

  • Edit each Thing so that it uses the Network Bridge.

  • Delete the Serial Bridge once you’ve migrated all the Velbus Things.

You might need to restart openHAB2 (after starting the VelServ service) just so that openHAB2 can re-initialise each Thing)

Good luck

Are you still trying to use a Velbus Serial Bridge in openHAB2?

I am…

I have now installed the Velbus Network Bridge in paper UI. Not sure how to point it to Velserv. I use 127.0.0.1, and port is 8080 (which is the standard openhab port I think).
–>*EDIT: should be port 6000 I suppose, gonna change that and let you know.
–>*EDIT2: nope, 6000 gives an error, 8080 says it works.

Updating each Thing to use the network bridge as we speak. I get a “thing updated” notification, but in the list of Things, everything looks the same. I’m gonna update each thing, then start the velserv service, and reboot the RPi, hoping everything works, and then I’ll delete the serial bridge.

I’ll post an update when I’m done.

Hi

The port to point the Velbus network bridge to is whichever port VelServ is outputting to. (My service file tells VelServ to use port 6000, but the default port for VelServ is 3788)

Until you remove the serial bridge in openHAB2 and start VelServ, it won’t work :slight_smile:

(I’ve got no idea why pointing it to port 8080 suggests that it’s working, as port 8080 is the html server)

(Hence suggesting that you complete the changes, then reboot before deciding if it’s working)

Delete the serial bridge before rebooting, as you’ll never know if the serial bridge locks the USB interface before VelServ gets a chance to connect.

I changed the network binding port setting tot 3788, I get a reply “offline, communication error”
When I change it to 6000, the binding is online. (Velserv is running)

I did remove the serial bridge before rebooting…
When I look at the settings of any of my things, it shows the new network binding, but in the overview with all the things, they still show the old serial binding.

Maybe reboot the RPi again?

That sounds like you’re in the right track now :smile:

Where do you mean?

My bridge looks like this in PaperUI / Configuration / Things …

And here’s a Velbus Thing as an example

Just rebooted the RPi again

This is my network bridge:

And here’s a thing:

So far so good
But here’s the problem:


The 10370302 is the serial binding (which is deleted before reboot)
That’s what I was trying to explain, while changing the settings for each thing to the network bridge, in the settings it changed, I even got a notification that settings were saved, but in the overview nothing changed…

I can even still switch every output in Habpanel (which uses the outputs with the serial binding)

Oooooooo I see :smile:

That makes sense.

I thought that number was just a (random) unique ID for each Thing. I never noticed that it was the ID for the bridge (that was in play when the Thing was first created).

Either way, if the Things are working…

“Who cares which number it is” :wink:

Yeah I guess you’re right.
That’s just something autistic I can’t handle :wink:

Anyway, again a big thank you for your help. :+1: :+1:

Status updates work perfect now (which they didn’t as I mentioned before)

1 Like

Excellent news all round.

Other than the bridge number issue.

I’m not sure what to suggest if it’s really bugging you.

Other than suggest that is a nice reminder of how you got it all working in the first place.

Our software evolves like the rest of us?

The only thing to consider is if you do work out how to change the number, wouldn’t it negatively affect all the rules you’ve created?

That’s probably right.

The thing is, Habpanel is working fine on my phone, but on my laptop it doesn’t. Status updates aren’t correct, it’s like I need to push a button again to have it updated.
Same goes with basic UI, which I recently started playing around in. I had a few thinks working, but now they don’t work anymore. Maybe that has something to do with the new network bridge.

I’ll search on that another time. Since it’s Sunday, maybe I should spend some attention to my girlfriend now :wink:

Always :slight_smile: