pySerial – login prompt being written to buffer when writting a message to tty serial


I am trying to use a GSM modem on a RPi4 to do a simple TCP connection to a remote server. I have this working, but when I go to write a message to the server, the login prompt for the pi is included in the byte stream sent to the server.

My objective is to have only what my code sends to be sent to the server 🙂

My relevant python3 code is:

ser = serial.Serial('/dev/ttyS0', 115200)
ser.write(b'GET / HTTP/1.1rn')

And what I receive on the server is:

connection from ('x.x.x.x', yyyyy)
received b'rnrn>garage logi'
received b'n: Password: GET'
received b' / HTTP/1.1rrn'
no more data from ('x.x.x.x', yyyyy)

Can someone help me understand where this received b'rnrn>garage logi'... is being injected into the write buffer of the serial connection?

I have tried using ser.reset_input_buffer() and ser.reset_output_buffer() but no changes. I have increased, removed, etc the sleeps. No changes ever.

Asked By: shiznatix



The problem was that the serial port had a login shell attached to it by the Raspberry Pi. I disabled this login from raspi-config and that resolved the issue.

Answered By: shiznatix
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.