Having problem detecting valid MQTT event on PicoW

Issue #328 resolved
Simon Walters created an issue

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)

  1. Bernat Romagosa

    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?

  2. Simon Walters 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.

  3. Bernat Romagosa

    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?

  4. Bernat Romagosa

    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? :)

  5. Simon Walters 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 :)

  6. John Maloney 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:

    scriptImage110315.png

    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.

  7. Simon Walters reporter

    I’m glad there is a logical (pun intended) explanation as to why not(lastEvent) didn’t work :)

  8. Log in to comment