Arduino, python, pyserial and socket

I am trying to write a simple web server in Arduino to test some things, but I could not find my Arduino with Ethernet on it.

β€œDon't worry,” I thought, β€œI'll just write a socket server in python that acts as a proxy for a serial connection.”

import socket import serial host = '' port = 8001 buffSize= 1024 serverSocket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) serverSocket.bind((host, port)) serverSocket.listen(1) ser = serial.Serial('COM3', 115200, timeout=None, dsrdtr =False,rtscts =False,xonxoff =False) print "Listening..." send = "" while 1: conn, remoteAddr = serverSocket.accept() print "Connection...." data = conn.recv(buffSize) print "Recieved" ser.write("%s\n"%data) print "Sent" print "Attempting to get reply" while ser.inWaiting()>0: conn.send( ser.read()) conn.close() serverSocket.close() 

However, no matter what I try, it seems that the connection made by the browser is reset randomly, and I get a few lines of data. And the script resets the Arduino every time it connects or disconnects from the serial port. I tried using RealTerm and I got the correct answer, but python and serialness are just a mess.

Can anybody help me?

+4
source share
1 answer

Use the tcp_serial_redirect.py script in the PySerial documentation. Anything you need.

-1
source

All Articles