babca / python-gsmmodem

Maintained fork of a Python module to control GSM modems attached to the system: send/receive SMS messages in your scripts, handle calls, and more.
GNU Lesser General Public License v3.0
174 stars 109 forks source link

Add native support for remote modems connected over the network (connect to IP address) #2

Open babca opened 8 years ago

babca commented 8 years ago

I'm currently have to use the remote modem with socat command which maps the remote port to virtual local port socat pty,link=/dev/vmodem0,raw tcp:192.168.5.1:12121 but it is uncomfortable to use. A native support would be much better and more reliable.

According to pySerial docs, it should be easy to add a support for remote modems. We only have to replace the serial.Serial() construction self.serial = serial.Serial(port=self.port, baudrate=self.baudrate, timeout=self.timeout,*self.com_args,**self.com_kwargs) in serial_comms.py connect() method with the alternative serial_for_url() function, which takes a lot more types of connections.

Before editing the rest of the code like adding params to modem() init functions and propagation of the needed settings to connect() method, let's resolve this:

I've successfully replaced the serial.Serial() with something like this self.serial = serial.serial_for_url(self.port, baudrate = self.baudrate, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, rtscts = False, xonxoff = False) and it connects to locally connected modem as usual.

But I have trouble when I fill in an URL pointing to a remote modem self.serial = serial.serial_for_url("socket://192.168.5.1:12121", baudrate = self.baudrate, bytesize = serial.EIGHTBITS, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, rtscts = False, xonxoff = False)

The connection timeouts because of modem not responding. The same code is working fine outside of the python-gsmmodem project. It seems it is a buffer issue or something like that. When I add printing of all the connection output, it does not output anything until I hit Ctrl+C. Then it outputs the last X lines of serial communication. Strange.

Any ideas how to debug?

mmmcorpsvit commented 5 years ago

but in this case you need know port and must have static IP i think need bridge for insert/delete com device detect and proxy via websocket send/receive workflow for remote control. If you wish we can cooperate in closed repository for work in this direct. My Skype: mmm_ogame p.s. sorry my poor english