Hi @elfedagger
If I’m given modifications to make to the Gladys Node-RED container, I’ll be happy to do them ![]()
I’m looking forward to my Somfy solar shutters closing and opening automatically again, it’s really a pleasant convenience that Gladys lets me have via Node-RED. But what I’ve tried to follow about what has been done on this issue is far beyond my skills.
Everything is in @Psoy’s hands
Sorry I’m not much help on this topic, I’m 100% Zigbee at home.
But for me it works, I just want to test by plugging in my Zigbee USB stick and the RFLink to see how this change reacts. I will do that next week.
But already, by plugging in only the RFLink it works very well. I will make a summary of the procedure; however I don’t know how to integrate that into the Gladys image.
I’m all Zigbee too, but with Somfy I don’t have a choice.
Hello @Psoy @elfedagger
I just found in the z2m docs that you can « attach » the port of an external USB device to an internal USB port inside the Docker: Docker | Zigbee2MQTT
You can see that we map a specific device to a defined port and grant user permissions on it.
Could you by any chance test that instead of my script?
In my opinion (not tested yet), this won’t solve automatically mounting a very specific device via Gladys that launches an internal Node-RED, but if we use a dedicated Docker for Node-RED then it will be possible for everyone (provided the exact device path/name on the host can be found).
Good evening,
So I tested with my Zigbee dongle, the Serial node connects fine and Zigbee works perfectly. The constraint that exists, also like on the mini PC, is that as soon as you unplug the Zigbee dongle which is on port USB0 and you unplug the Rflink which is on port USB1 (for X reasons, circuit breaker trips (we don’t unplug anything, but it looks like that)), then if you plug the Rflink back in first, it will be assigned port USB0 and the Zigbee dongle will be assigned port USB1.
And there Zigbee will no longer work until the Zigbee dongle is back on port USB0 and it’s impossible to assign it to port USB1 in the Gladys integration (I haven’t found out why). On the other hand the Rflink will work: the serial node will be connected and will send the messages received by the Zigbee dongle (in gibberish of course) since it sees something on its original port USB1.
The solution is to unplug everything and plug them back in; if the Zigbee dongle was on port USB0, plug it back in first and the Rflink second so it will be on USB1, as at initialization.
So is this really a problem? Who unplugs their USB ports?
In steady operation, this change, to get the serial node connected, works fine. For info, you just need a Mega 2560 board and load the Rflink program onto it to be able to test the connection.
Here is what I entered via SSH on the Raspberry:
All commands are run on the host, not in the Gladys docker.
You also need your Gladys and Node-RED docker to be running.
You need to create a file named « 99-docker-tty.rules »
In the folder /etc/udev/rules.d
you need to run this command to go to that folder
cd /etc/udev/rules.d
then create and edit the new file: 99-docker-tty.rules
sudo nano 99-docker-tty.rules
copy/paste into it the following instructions:
ACTION==\"add\", SUBSYSTEM==\"tty\", RUN+=\"/usr/local/bin/docker_tty.sh 'added' '%E{DEVNAME}' '%M' '%m'\"\nACTION==\"remove\", SUBSYSTEM==\"tty\", RUN+=\"/usr/local/bin/docker_tty.sh 'removed' '%E{DEVNAME}' '%M' '%m'\"\n```
to save the file type:
`ctrl+X`
then type
Y
press the `Enter` key to save and exit.
Then apply the rules, run the command below
`sudo udevadm control --reload`
Finally you need to create the script that will automatically mount and unmount the device on the USB port:
Go to the folder: /usr/local/bin
run this command
`cd /usr/local/bin`
Then create a file named « docker_tty.sh »
`sudo nano docker_tty.sh`
Copy/paste:
#!/usr/bin/env bash
echo "Usb event: $1 $2 $3 $4" \u003e\u003e /tmp/docker_tty.log
if [ ! -z "$(docker ps -qf name=gladys-node-red)" ]
th en
if [ "$1" == "added" ]
then
chmod a+rw $2
docker exec -u 0 gladys-node-red mknod $2 c $3 $4
docker exec -u 0 gladys-node-red chmod -R 777 $2
echo "Adding $2 to docker" \u003e\u003e /tmp/docker_tty.log
else
docker exec -u 0 gladys-node-red rm $2
echo "Removing $2 from docker" \u003e\u003e /tmp/docker_tty.log
fi
fi
exit and save
`ctrlX`
then type `Y` and press the `Enter` key
And finally make this script executable:
`sudo chmod +x /usr/local/bin/docker_tty.sh`
WARNING: this script is not validated by @pierre-gilles and if you want to test it do not use your machine that runs Gladys every day
@mutmut thanks for developing this program.
If you agree @pierre-gilles, these commands should be automated and integrated into the Gladys Node-RED test image, which I could possibly retest. Thanks in advance
Good evening @mutmut
I just looked at what you sent, but from what I can see it’s for the zigbee port, and for the rflink port we’ll need to go over the instructions again I think, and that’s a bit too technical for me ![]()
If you have the time, can you guide me, as before, I will gladly test ![]()
I’m not sure that’s the best solution, I must admit!
Your proposal involves operations on the host and modifies the running Docker container, which is not a good practice. A container is supposed to be immutable: it should never be modified directly, because with each image update it is removed and recreated (that’s the whole point of Docker).
I think it would be better to refocus on a simpler solution. In my opinion, we can get by by simply adjusting the docker run ![]()
hello @pierre-gilles
thanks for your reply
Yes I agree with you, that’s why I was asking if you had time to rebuild an image that includes these changes, and so, if I understood correctly, it would be launched with the docker run
Except that your solution isn’t something that belongs in the docker run ![]()
I just want you to give me a docker run that works without any other modifications!
I’ll try to look into that, but it’s not a sure thing
I’ll try to look into that, but it’s not a sure thing.
Do I need to create a new Gladys container with Docker? Or do I just add command lines in the docker run?
Actually the idea is simply that you need to provide me with the complete docker run command to properly launch the official Node-RED container.
For now, in the tutorial on the site ( Intégrer Node-RED avec Gladys Assistant en MQTT | Gladys Assistant ), I was starting the container like this:
docker run -d \
--log-opt max-size=10m \
--restart=always \
--privileged \
-u root \
--network=host \
--name node_red \
-v /var/lib/node-red:/data \
nodered/node-red
You need to investigate to find a docker run that works with access to USB ports inside this container, without any modifications after launching the container.
Are you telling me to modify the docker run that Gladys launches when we request access to Node-RED?
If that’s the case, how do I access that docker run to modify it? Do I use the one you just sent me? And then how do I launch it?
For now I only know this docker run:
docker run -d \
--log-driver json-file \
--log-opt max-size=10m \
--cgroupns=host \
--restart=always \
--privileged \
--network=host \
--name gladys \
-e NODE_ENV=production \
-e SERVER_PORT=80 \
-e TZ=Europe/Paris \
-e SQLITE_FILE_PATH=/var/lib/gladysassistant/gladys-production.db \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/gladysassistant:/var/lib/gladysassistant \
-v /dev:/dev \
-v /run/udev:/run/udev:ro \
gladysassistant/gladys:node-red-usb-ports
Yes!
That’s the one I just gave you in my previous message, yes ![]()
By typing it into the terminal and running it? I’m having trouble seeing the question ![]()
You’re confusing it with Gladys’ Docker run, here we’re talking about Node-RED
No, it’s very clear: the first starts the Gladys container which contains the startup of Node-RED (so to speak), and the other is just the Node-RED container, the one that is started by Gladys.
So if I start the container you just gave me, am I starting Node-RED as if Gladys were launching it?
Not exactly, the configuration is here, which gives us a docker run:
docker run -d \
--name gladys-node-red \
--restart always \
-p 1881:1880 \
-v /var/lib/gladysassistant/node-red:/data \
--log-opt max-size=10m \
nodered/node-red:3.1
(In production)
I’m lost, I don’t see how to go about it ![]()
Good evening @pierre-gilles
When I run your docker run (with or without sudo in front), there is a permissions problem
• Error: EACCES: permission denied, copyfile '/usr/src/node-red/node_modules/node-red/settings.js' -> '/data/settings.js'
This error indicates that the Node-RED container does not have permission to copy the settings.js configuration file from the source directory /usr/src/node-red/node_modules/node-red/ to the data directory /data/.
But when I start Node-RED from Gladys it works, so is something missing? I tried adding --user 1000:1000 \\, but it doesn’t change anything.
I solved the problem like this:
pi@rasp3b:~ $ sudo chmod 777 /var/lib/gladysassistant/node-red pi@rasp3b:~ $ docker restart ada12c9cdc4a ada12c9cdc4a pi@rasp3b:~ $ ls -l /var/lib/gladysassistant/node-red total 36 drwxr-xr-x 3 pi pi 4096 Mar 24 23:12 lib drwxr-xr-x 2 pi pi 4096 Mar 24 23:12 node_modules -rw-r--r-- 1 pi pi 120 Mar 24 23:12 package.json -rw-r--r-- 1 pi pi 23200 Mar 24 23:12 settings.js
There Node-RED starts and if I change the permissions to restrict them a bit nothing works,
pi@rasp3b:~ $ sudo chmod 766 /var/lib/gladysassistant/node-red
pi@rasp3b:~ $ docker restart ada12c9cdc4a
ada12c9cdc4a
pi@rasp3b:~ $ ls -l /var/lib/gladysassistant/node-red
ls: cannot access '/var/lib/gladysassistant/node-red/package.json': Permission denied
ls: cannot access '/var/lib/gladysassistant/node-red/settings.js': Permission denied
ls: cannot access '/var/lib/gladysassistant/node-red/node_modules': Permission denied
ls: cannot access '/var/lib/gladysassistant/node-red/lib': Permission denied
total 0
d????????? ? ? ? ? ? lib
d????????? ? ? ? ? ? node_modules
-????????? ? ? ? ? ? package.json
-????????? ? ? ? ? ? settings.js
and then Node-RED loops as before
a bit of help would be welcome, because I’m going in circles and not making progress ![]()
thanks in advance
In the Node-RED integration code, there is indeed a chown to change the owner of the folder: