Client and Server Together with Python

Hello to all,
I'm working on a physics project that plans to study the precession and nodule motion of a gyroscope. I intend to do this with two mpu6050 sensors that are connected respectively to two ESP8266 modules. From the Ide di arduino I set a pair as a client and the other as a server (access point). With Python I would like to read data from both client and server at the same time. Unfortunately, I can now read only the data from the client.

Could someone help me to understand how to implement a code that is good for both the client and the server?

Thank you very much

What is the Python code running on?

How is the Python code communicating with the client?

I would have expected that it would be more natural for the Python program to communicate with the ESP8266 that is the server.

Another option might be to use Python to create the server and have both ESP8266s configured as clients.

...R

This is the Python code works as client.

Do u think it could possible to add the part relative to the server?
"
import numpy # Import numpy
import matplotlib.pyplot as plt #import matplotlib library
import socket
import time
import matplotlib.pyplot as plt
from sensor_stream import SensorStream
from data_parser import DataParser

AcZ_normal=[]
AcY_normal=[]
AcX_normal=[]

def main():

threshold = 60
second_threshold = 10
stream = SensorStream()
CONTINUOUS_INCREMENT = False

TCP_IP = '192.168.4.1'
TCP_PORT = 80
BUFFER_SIZE = 1024
frequenz = 0.05

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))

parser = DataParser(acc_unit=1, gy_unit=1)
cnt=0
mov = 0
rotating = False
file1 = open ("Accel_pedana.txt ","w")
elapsed=0
start=time.time()
while True:
raw_bytestream = s.recv(BUFFER_SIZE)

parser.parse_data(raw_bytestream, stream)

x,y,z,gX,gY,gZ = stream.getValues()

AcZ_normal=((z-80)*9.81/16384)
AcY_normal=((y-50)*9.81/16384)
AcX_normal=((x-50)*9.81/16384)
elapsed=time.time()-start
file1.write ("\n %f %f %f %0.02f \n" %( AcZ_normal, AcY_normal, AcX_normal,elapsed))
cnt=cnt+1
time.sleep(frequenz)
print cnt
if (cnt>150):
break
file1. close ()
s.close()

if name == "main":
main()
"

Giancarlo_Physics:
This is the Python code works as client.

That is confusing because in your Original Post you say your Python program can only communicate with the ESP8266 that acts as a client. That suggests to me that the Python program is acting as a server.

More generally I have no idea how to answer your question in Reply #2 because I have no idea what the Python program needs to communicate with. We need to see both sides of the problem.

I suggest you create the simplest possible system that just transmits "hello world" when requested and get that working before adding in your project code.

...R