Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add openhab user to dialout group #18

Closed
bodiroga opened this issue Oct 6, 2016 · 9 comments
Closed

Add openhab user to dialout group #18

bodiroga opened this issue Oct 6, 2016 · 9 comments

Comments

@bodiroga
Copy link
Contributor

bodiroga commented Oct 6, 2016

Good morning Thomas!

Would it be possible to add the openhab user to the dialout group after openHAB is successfully installed?

Bindings that depend on USB controllers (ZWave, Enocean, RXFcom,...) need access to the USB devices (/dev/ttyUSB0, /dev/ttyACM0,...), so automatically adding the openhab user to the dialout group will avoid users to ssh the device just to type "sudo usermod openhab -a -G dialout".

Small detail that will make openhab users life easier ;)

Thank you for your patience!

@ThomDietrich
Copy link
Member

Hey, that's a topic we also discussed in the forum thread a few times. What's a bit troubling for me: dialout is always only halve the solution. Not saying that I'll not do it but there are a few extra steps needed to make your ZWave dongle etc. work in openHAB (activate the serial port, change java parameters, ...) Do you have an idea for a more complete approach?

@bodiroga
Copy link
Contributor Author

bodiroga commented Oct 7, 2016

Hi again Thomas!

Yeah, you are right, adding the openhab user to the dialout group doesn't solve the problem completely and in all cases, but, for example, the default file where the distribution mounts the USB devices ("/dev/ttyAMC0") can be read by openHAB and therefore it can be used immediately without further modifications.

If you want to link the file to another file ("/dev/zwave" -> "/dev/ttyAMC0" using an udev rule), then what you say is correct, you need to pass the "/dev/zwave" file as a -Dgnu.io.rxtx.SerialPorts java parameter, and I'm not sure what would be the best solution to handle the problem, sorry 😢

@ThomDietrich
Copy link
Member

ThomDietrich commented Oct 8, 2016

Just a few notes on the topic.
https://community.openhab.org/t/12539
https://community.openhab.org/t/13379/89

devices:

  • /dev/ttyUSB0
  • /dev/ttyS0
  • /dev/ttyAMA0
  • /dev/ttyAMC0

openHAB runtime parameters
/etc/init.d/openhab2 OR /etc/default/openhab2 (?) OR /usr/share/openhab2/runtime/karaf/bin/setenv

-Dgnu.io.rxtx.SerialPorts=/dev/ttyUSB0
# or
-Dgnu.io.rxtx.SerialPorts=/dev/ttyS0:/dev/ttyUSB0

Serial port

  • Add to /boot/config.txt: enable_uart=1
  • Remove serial port from /boot/cmdline.txt
  • /etc/inittab - comment or delete: T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

System

Judging from what was said in the threads, only the following is needed:

sudo adduser openhab dialout
sudo adduser openhab tty   # ?

Judging by what I saw in the forum, the real problem is to select the right serial device and to decide wether it needs to be added to gnu.io.rxtx.SerialPorts.
Also: There are some discussions about the RPi3 BT module.

@bodiroga
Copy link
Contributor Author

Hi Thomas!

Sorry for the late response :(

Yes, you are right, it's not an easy task to configure the Razberry board to be used with openHAB (well, it's not difficult, but require a few steps), but for examples, the default mounting points of the USB sticks like /dev/ttyUSB0 or /dev/ttyACM0 can be accessed by openHAB just adding the openhab user to the dialout group. You don't need to add any line to the /etc/default/openhab2 file (-Dgnu.io.rxtx.SerialPorts parameter) nor to the /boot/config.txt file, just execute "sudo usermod openhab -a -G dialout" and you are ready to go!

That's why my suggestion was to add the openhab user to the dialout group, at least the USB stick user's life (Z-Wave, RFXcom, Enocean,...) will be simpler ;)

@ThomDietrich
Copy link
Member

@bodiroga I've done the needed changes (finally!)

When installing openHAB:

adduser openhab dialout
adduser openhab tty

After selecting the menu entry "Serial Port":

if grep -q "enable_uart" /boot/config.txt; then
    sed -i 's/^.*enable_uart=.*$/enable_uart=1/g' /boot/config.txt
else
    echo "enable_uart=1" >> /boot/config.txt
fi
sed -i 's/console=tty.*console=tty1/console=tty1/g' /boot/cmdline.txt
sed -i 's/^T0/\#T0/g' /etc/inittab

This should also respect the differences between RPi1+2 and 3. I will test this now in my RPi3.
Do you agree that this covers what it should?

The last piece needed by some users is the addition of "gnu.io.rxtx.SerialPorts" but as details are missing, I'll leave that to the user for now.

@bodiroga
Copy link
Contributor Author

Awesome work Thomas, many thanks for your patient!

I will try to test it next week and report back if I find any problem, although I'm sure that everything will work flawlessly ;)

Keep up with the good job and thanks for your contribution to the openHAB community!

@ThomDietrich
Copy link
Member

Thanks for your help. Any further additions from your side are always welcome ;) Let me know if everything went smooth!

@ThomDietrich
Copy link
Member

ThomDietrich commented Nov 6, 2016

@bodiroga, earlier you said:

the default mounting points of the USB sticks like /dev/ttyUSB0 or /dev/ttyACM0 can be accessed by openHAB just adding the openhab user to the dialout group.

Do you by any chance know the reason behind that? Maybe a better solution could evolve out of a short investigation. Also feel free to take part in the referenced issue #33!

@bodiroga
Copy link
Contributor Author

bodiroga commented Nov 7, 2016

Hi Thomas!

As far as I know (I'm not an expert by all means), openHAB can read the /dev/ttyUSB0 or /dev/ttyACM0 ports being part of the dialout group because in Linux, serial ports mounted in /dev folder are owned by root under the dialout group. Here you have a link that talks about it:

http://askubuntu.com/questions/774541/what-is-dialout-group-in-ubuntu/774545

The problem with the "-Dgnu.io.rxtx.SerialPorts" parameter is that Java is not able to "see" serial ports with non-standard port names (/dev/ttyAMA0 or custom names such as /dev/zwave and /dev/rfxcomm) and in order to solve that you need specify the ports that you need to use manually in the -Dgnu parameter. (More information: http://angryelectron.com/rxtx-on-raspbian/). And I don't know what can be done to solve it... 😢

Perhaps, the best solution is to add an udev rule (there is an entry for that in the openHAB wiki: https://github.com/openhab/openhab/wiki/symlinks), create a list of most used devices (in the link you have the idVendor and idProduct of two ZWAVE usb dongles and the RFXcom transceiver, we could add the information about the Razberry), define a name for each device (/dev/zwave or /dev/USBzwave for all the ZWave devices, as it is very unlikely that someone will plug two ZWave controllers in the same device) and add those personal names to the -Dgnu.rxtx.SerialPorts parameter, instead of adding all possible ports combination (/dev/ttyS1, /dev/ttyS2, /dev/ttyAMA0, /dev/ttyAMA1,...).

How does it sound?

At least, at the binding configuration time, /dev/USBzwave is a much more meaningful name than /dev/ttyAMA0...

Thanks for your work as always and best regards,

Aitor

mstormi added a commit to mstormi/openhabian that referenced this issue Jul 31, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
mstormi added a commit to mstormi/openhabian that referenced this issue Aug 18, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
mstormi added a commit to mstormi/openhabian that referenced this issue Aug 19, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
mstormi added a commit to mstormi/openhabian that referenced this issue Aug 21, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
mstormi added a commit to mstormi/openhabian that referenced this issue Aug 27, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
mstormi added a commit to mstormi/openhabian that referenced this issue Nov 5, 2019
Signed-off-by: Markus Storm <markus.storm@gmx.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants