help on udp response analysis - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: help on udp response analysis (/thread-15763.html) |
help on udp response analysis - 4u2fast - Jan-30-2019 Hi, i'm new on python and need some help on best practise for the below: I have a device working with ESP32 with a Gui for Android but i need to control the device from my raspberry pi in general i'm sending a udp string to the device in order to get back the status and then take action to control here the script to request the status # Echo client program import socket ON = "mobile\03\04\01\r\n" STATUS = "mobile\01\r\n" HOST = '192.168.0.20' # The remote host PORT = 4000 # The same port as used by the server sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.connect((HOST, PORT)) sock.sendall(STATUS) data = sock.recv(1024) print('Received', repr(data))the output looks like that now i need to analyze the output in order to map the status for example\x03\\x01\ represents Parameter#03 with value=01 what is the best approach to get this done ? i tried to load it into array but without success :-( best would be to get an output as followed Parameter01=Value01 Parameter02=Value02 Parameter03=Value03 Parameter04=Value04 . . . Thanks in advance Thomas The Parameters starts at x03 not at 01 ! RE: help on udp response analysis - 4u2fast - Feb-01-2019 no answer :-( ok, i have done some modification and for the begining i want to analyze only 3 fields from the output string main issue now is to manipulate the ouput in order to use them afterwards like '\x01' should be translated to 1 (need to strip the unrelevant chars) any idea ? tried a lot but without success :-( thanks Thomas # Echo client program import socket import re #ON = "mobile\03\04\01\r\n" STATUS = "mobile\01\r\n" HOST = '192.168.0.20' # The remote host PORT = 4000 # The same port as used by the server sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.connect((HOST, PORT)) sock.sendall(STATUS) data = sock.recv(2048) ONOFF = data[7] # 0=OFF,1=ON SPEED = data[19] # 0=LOW,1=MED,2=HIGH MODE = data[23] # 0=VENTILATE,1=RECOVERY,2=INTAKE print(r'Received', repr(data)) print('POWER', (ONOFF)) print('SPEED', (SPEED)) print('MODE', (MODE))
|