@Dnpwwo
I have a question. My hardware sends to me commands like those:
Code: Select all
"message" : "2020-12-01 20:43:28.294 (Sterownik) AT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nO=1,0,1,1,0,0,0\r\nI=1,0,0,1,0,0,0\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\nAT+Time=-1,-1,-1,-1\r\n"
and I wanted to pull out command "I=1,0,0,1,0,0,0\r\n" from this string to know which input was turned on.
I wrote code in onMessage to parse that:
Code: Select all
def onMessage(Connection, Data):
global SerialConn
SerialConn = Connection
strData = Data.decode("utf-8", "ignore")
LogMessage(strData)
pozycja=strData.find('I')
strData=(strData[pozycja:len(strData)])
pozycja1=strData.find('\r')
strData=(strData[0:pozycja1])
strData=strData.replace(",", "")
for char in strData:
if char in " I=OPSL":
strData = strData.replace(char,'')
for i in range(1,len(strData)):
if strData[i]=='1':
Devices[i].Update(nValue=1, sValue=str(0), SignalLevel=0, Image=8)
if strData[i]=='0':
Devices[i].Update(nValue=0, sValue=str(0), SignalLevel=0, Image=8)
return
Can you tell me is that correct way to achieve that? For example if my hardware sends me a command and second input will be "1": "I=1,0,1,0,0,0,0" I want to change unit==2 device.