How can i limit with python, to just check for the first 10 characters of a message to trigger a text DAT?

Hey, i’m using pick up sensors that send me a message to trigger a code inside a udpin_callbacks. The problem is that the sensors are not in python, and i think that it sending me a larger message that i cannot see, so my conditionals are not working in a normal way.

So first i wanna check if i just select the first 10 characters of the message to run My script.

IMG-20231210-WA0000

How can i tell TD to just check for “U_X111A[0]” or maybe "F_X112A[3]"and not more than this 10 characters of the messages. All sensors send me a similar message.

Thanks!

you can use

text = op(''udpin_5001').row(1)
textRedux = text[:10]
if textRedux == 'xxxxx':
   print('xxx')
elif textRedux == 'yyyyy':
   print('yyy')

Row() returns a list of cells, not a list of strings, so checking the list of cells against your list of strings will always fail.
you either do a hard check (which might be more efficient) using

op('udpin')[ 1, 0].val == "myString" 

Or you use a list comprehension to convert your list if cells to a list of strings, but then i would use a set instead.

Edit: why are you checking against the cell anyway? Just use the message argumentt hat gets passed!

def onReceive(dat, rowIndex, message, bytes, peer) :
    if message == "myString": doSomething()
1 Like