Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 help on udp response analysis
#1
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

Output:
('Received', "'master\\x03\\x01\\t\\x00\\x0c\\x00\\x13\\x00\\r\\x00\\x1a\\x00\\x04\\x01\\x05\\x00\\x06\\x01\\x08)\\x0e\\x00\\x00\\x00\\x12\\x00\\x14\\x00%\\x00'")
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 !
buran wrote Jan-30-2019, 04:23 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
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))
Output:
python Status_test.py ('Received', '"master\\x03\\x01\\t\\x00\\x0c\\x00\\x13\\x00\\r\\x00\\x1a\\x00\\x04\\x01\\x05\\x00\\x06\\x02\\x08\'\\x0e\\x00\\x00\\x00\\x12\\x00\\x14\\x00%\\x00"') ('POWER', '\x01') ('SPEED', '\x01') ('MODE', '\x02')
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Scapy, creating response for GET request. SyRex1013 4 704 Dec-11-2018, 07:39 AM
Last Post: SyRex1013
  GET Request and JSON response montyonthebonty 9 1,217 Sep-27-2018, 07:28 AM
Last Post: buran
  Sending response delay michalt38 1 824 Feb-13-2018, 03:19 PM
Last Post: sparkz_alot
  Error getting HTTP 200 response with requests.get while wget works fine sonicblind 0 1,798 Oct-18-2017, 02:24 PM
Last Post: sonicblind
  Response [200] little help Blue Dog 10 6,067 Jul-11-2017, 06:42 PM
Last Post: nilamo

Forum Jump:


Users browsing this thread: 1 Guest(s)