so here goes on an explanation
the data after the event.. the stuff between those curly brackets { } that is the payload. now a payload can have { } or this [ ] or ' ' or " " or nothing at all to define the beginning and end of it
if there is nothing to define it then it is usually a number or a float (number with a decimal)
if you see the single or double quotes then it is a string (literal text)
if you square brackets then it is a list
and the curly brackets are a dictionary
so as an example if your payload is
and you want to pick out a specific character in that string you would do
this will print a d into the log. this is because the index begins with 0. so if you wanted to print the p in sample you would use 13 in place of the 2
now this is going to spin ya about a little but a string is technically a list it is a list of single characters where as a list can have strings, numbers floats dictionaries, basically any python object. but the information is accessed the same way
now a dictionary which is what i used as the container for the payload data is the exact same as a real dictionary. with words and definitions. in python the word is called a key and the definition is called a value. but when you look in a dictionary you look it up by the word. so we are going to do the same we want the definition/value for the word/key temperature. now we know this word is in there because we can see it when it is printed. but you may not always be able to print it or see everything contained in it when it is printed. or it may be there one time and not another
so what we would do for that is
Code: Select all
if 'temperature' in eg.event.payload:
print eg.event.payload['temperature']
this check to see if it is in there and if so then to print the value for it. this stops all that ugly red from appearing.
the things you edited in the TextControl.py file are dictionaries. the : separates the key from the value