Hello.
I have a problem with LuCI again...
I have an htm page like this:
applications/luci-app-tiod/luasrc/view/tiod.htm:
<%
local sys = require "luci.sys"
local sessions = sys.exec("/usr/bin/tmux list-sessions")
if not string.match(sessions, "con1") then
sys.exec("/usr/bin/tmux new -d -s con1 /usr/bin/ttyd -p 2321 tio -b 115200 /dev/ttyS4")
end
%>
<%+header%>
<div style="align: left; width: 100%; height: 100%;">
<iframe style="width: 100%; min-height: 500px; border: none; border-radius: 3px; resize: vertical;"
src="http://192.168.0.171:2321"></iframe>
</div>
<br>
<%+footer%>
I'm using tmux to create multiple sessions on multiple ports for each rs232 connection.
The problem is that I can enter the command manually through the console:
root@NTR-100:~# /usr/bin/tmux new -d -s con1 /usr/bin/ttyd -p 2321 tio -b 115200
/dev/ttyS4.
And then everything works:
It doesn't connect and keeps rebooting. If you go to this address separately, then everything is the same. And only if you delete this session through the terminal and create it again in the terminal (and not using lua commands), then everything works again.
Moreover, the script works even after the page is loaded, if you write tmux list-sessions, then there is a session there (though I don’t know how to view it completely, perhaps it is written incorrectly).
After some experimentation I realized that the problem was with the ttyd utility.
The fact is that when rendering pages, a tmux session is created with the ttyd process, which creates a terminal on the desired port with the tio command, but it creates it more than once, which breaks ttyd, because for some reason, after creation, abruptly turning off and turning on again, it does not creates a new terminal.
But I found an interesting thing: if you kill the tmux server using bash scripts and create them again (again with bash scripts), then it should work.
I wrote a convenient config for myself and I want that after clicking the “Apply” button, a bash script will be created with the necessary commands and run. How can this be done through lua??
Yes, I am aware of the existence of the uci api, but the add method did not work for me and I still did not understand why, so I implemented it through terminal commands.