I'm in trouble with the data received via serial interface .
I wrote a python code to receive some data by serial interface and apparently all work fine , until I try to verify with a simple "if" the string received is what i expect .
The code receive data from serial interface and via PuTTy I've cheched that what I receive is what I expect to receive "connecting\r\n", but then when I try to check if I've received the right info, the program seems don't work properly , and I don't understand where is the problems because the case seems to me quite simple .
Any idea ?
Thanks a lot since now .... Bob
Code: Select all
while True:
if uart.any():
data_read=uart.readline()
if data_read!="":
print(data_read) # b'connecting\r\n' is what appear in PuTTY
uart.write(data_read+"\r\n") # b'connecting\r\n' is what I send back and receive the sender.
# Until above line all seems to be ok., but the next line don't works.
if data_read=="connecting\r\n": # <---- THIS[b] IF[/b] SEEMS NOT DETECT WHAT IS INSIDE THE data_read
print("CONNECTED")
send_setting()
## else:
## z1=data_read[0]
## s1=data_read[1]
## hr_start_z1=data_read[2]
## min_start_z1=data_read[3]
## hr_stop_z1=data_read[4]
## min_stop_z1=data_read[5]
## lu_z1=data_read[6]
## ma_z1=data_read[7]
## me_z1=data_read[8]
## gi_z1=data_read[9]
## ve_z1=data_read[10]
## sa_z1=data_read[11]
## do_z1=data_read[12]
## soglia1=data_read[13]
## z2=data_read[14]
## s2=data_read[15]
## hr_start_z2=data_read[16]
## min_start_z2=data_read[17]
## hr_stop_z2=data_read[18]
## min_stop_z2=data_read[19]
## lu_z2=data_read[20]
## ma_z2=data_read[21]
## me_z2=data_read[22]
## gi_z2=data_read[23]
## ve_z2=data_read[24]
## sa_z2=data_read[25]
## do_z2=data_read[26]
## soglia2=data_read[27]
time_stamp=rtc.datetime()
hr_curr=time_stamp[4]
min_curr=time_stamp[5]
day_curr=time_stamp[3]