- changed title to Having problem detecting valid MQTT event on PicoW
Having problem detecting valid MQTT event on PicoW
I tried using not (lastEvent) but that didn’t work - the say was still executed every loop iteration (It says false)
So I tried doing a comparison of lastEvent <> false - that didn’t work either
So, ended up testing the length for non-zero and that worked
But, I feel the 1st one should have worked
PEBKAC or something else :)
Simon
Comments (11)
-
reporter -
This sounds like a type issue. In MicroBlocks you can only broadcast strings, but you’re comparing a message against a boolean.
Can you test whether my hypothesis is right?
-
reporter I'm out and about but I'm not broadcasting the message, it's being received as MQTT message inside a loop. The say block outputs the text false when no message to process but looking for that text or Boolean false doesn't seem to work.
-
Interesting. That text may contain some hidden character that you’re not seeing. Can you maybe print the unicodes for the message and see if there’s anything weird in there?
-
reporter I'll try that out when I get home
-
reporter So adding this in when length = 0 gives [0 item list]
-
Yes, when
length == 0
that makes perfect sense. My hunch was that the non-empty message would contain some other hidden character. That is, maybe'false'
is not just'false'
but maybe'false\n'
, for example. That would cause your(message) == 'false'
comparison to fail.Do I make sense? :)
-
reporter What you say makes sense :)
My issue was that the say block outputs false but testing for false doen't work
I think lastEvent must always be a list and is zero length when no message available.
I think there might be an issue with the say block reporting false instead of
[image: image.png]
But, I'll just carry on testing for length=0 and sleep well at night :)
-
repo owner Sorry for the slow response. I've been away from email for the holidays.
You just need to compare with boolean value false, not with string false:
The "not" version that you tried first doesn't work because MicroBlocks only considers the boolean value "true" to be true; any other value is considered "false" (i.e. not true). That is in contrast to some programming languages that consider any value that is not false, zero, or NULL/Undefined to be true. Thus "not" of any value except the boolean true (including lists, numbers, and strings) is always true.
-
reporter I’m glad there is a logical (pun intended) explanation as to why not(lastEvent) didn’t work :)
-
repo owner - changed status to resolved
- Log in to comment