I am developing small app that will send SMS using remote device as gateway.
These devices are connected with VPN, but it doesn't matter.
SMS gateway has physically serial port /dev/AMA0
. I'm using ser2net
on SMS Gateway to share serial port over Internet, and I'm using socat
to create virtual serial port on VPS and "receive" shared port.
Here are my confings:
SMS Gw:
cat /etc/ser2net.conf
3333:raw:0:/dev/ttyAMA0:9600,8DATABITS,NONE,1STOPBIT
VPS:
socat pty,link=/dev/tty_remote_serial,waitslave tcp:10.8.0.2:3333
我用来gammu
控制短信设备。当我登录 VPS 并执行此命令时,我看到:
gammu identify
Device : /dev/tty_remote_rpi_serial
Manufacturer : SIMCOM_Ltd
Model : unknown (SIMCOM_SIM800L)
Firmware : Revision:1308B08SIM800L16
IMEI : 867XXXXXXXXXXX23
SIM IMSI : XXXXXXXXXX491925
而且它是完美的。我可以使用远程串口,一切都很完美。问题是当我再跑gammu identify
一次时。设备/dev/tty_remote_rpi_serial
因终止而不存在socat
。当我重新启动socat
服务时,一切正常。我必须重新启动socat
每个关闭的连接(来自 mincom)或执行的命令 ( gammu identify
)。
有没有办法防止socat
终止?
2016/01/06 04:50:04 socat[4233] N read(5, 0x16ea680, 8192): Input/output error (probably PTY closed)
2016/01/06 04:50:04 socat[4233] N socket 1 (fd 5) is at EOF
2016/01/06 04:50:04 socat[4233] I shutdown(6, 1)
2016/01/06 04:50:04 socat[4233] D shutdown() -> 0
2016/01/06 04:50:04 socat[4233] D data loop: sock1->eof=2, sock2->eof=0, closing=1, wasaction=1, total_to={0.000000}
2016/01/06 04:50:04 socat[4233] D select(7, &0x40, &0x0, &0x0, &999.000000)
2016/01/06 04:50:04 socat[4233] D select -> (, 0x40, 0x0, 0x0, &998.974365), 1
2016/01/06 04:50:04 socat[4233] D read(6, 0x16ea680, 8192)
2016/01/06 04:50:04 socat[4233] D read -> 0
2016/01/06 04:50:04 socat[4233] N socket 1 (fd 5) is at EOF
2016/01/06 04:50:04 socat[4233] I shutdown(6, 1)
2016/01/06 04:50:04 socat[4233] D shutdown() -> -1
2016/01/06 04:50:04 socat[4233] I shutdown(6, 1): Transport endpoint is not connected
2016/01/06 04:50:04 socat[4233] N socket 2 (fd 6) is at EOF
2016/01/06 04:50:04 socat[4233] I close(5)
2016/01/06 04:50:04 socat[4233] D close() -> 0
2016/01/06 04:50:04 socat[4233] D unlink("/dev/tty_remote_rpi_serial")
2016/01/06 04:50:04 socat[4233] D unlink() -> 0
2016/01/06 04:50:04 socat[4233] I shutdown(6, 2)
2016/01/06 04:50:04 socat[4233] D shutdown() -> -1
2016/01/06 04:50:04 socat[4233] I shutdown(6, 2): Transport endpoint is not connected
2016/01/06 04:50:04 socat[4233] N exiting with status 0
2016/01/06 04:50:04 socat[4233] D exit(0)
2016/01/06 04:50:04 socat[4233] D starting xioexit()
2016/01/06 04:50:04 socat[4233] D finished xioexit()
答案1
使用
while sleep 1; do
socat pty,link=/dev/tty_remote_serial,waitslave tcp:10.8.0.2:3333;
done