Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

AWS IOT: LWT with JSON

Hi there
Greetings from Bangkok!
I'm in a bit of a struggle with my MQTT LWT. If set to the following, AWS simply closes the connection:
["mqtt.will_message", "{\"state\": { \"reported\" : { \"online\" : 0 } } }"]
If I omit the qotes things are working fine:
["mqtt.will_message", "{state: { reported : { online : 0 } } }"]
Obviously this cannot be the solution as it isn't valid JSON anymore.
Is the escape sequence for " wrong? Or do I miss anything else?
Thanks for your help!

Comments

  • SergeySergey Dublin, Ireland
    edited February 7

    Just use single quotes in yaml:

      ["mqtt.will_message", '{"foo":1}'],
    

    Or, you can always change the config dynamically:

    mos config-set mqtt.will_message='{"a":1}'
    

    Could you share what project you're working on, please?

  • thanks, Sergey!
    with single quotes it works perfectly fine.

  • hmm, while the problem of slammed connections is gone, it's still behaving strangely (or more likely, I'm still trying to do something stupid :-) )

    in conf_schema.yaml:

    ["mqtt.will_message", '{"state":{"reported":{"online":0}}}'],

    after boot:

    >mos config-get mqtt.will_message

    {"state":{"reported":{"online":0}}}

    so far so good, let's kill the device..

    Message as received by AWS:

    {\"state\":{\"reported\":{\"online\":0}}}

    why??

    back on the console:

    mos config-set mqtt.will_message='{"state":{"reported":{"online":0}}}'

    mos config-get mqtt.will_message

    '{state:{reported:{online:0}}}'

    no more double-quotes?

    Message as received by AWS:
    '{state:{reported:{online:0}}}'

    Any ideas?

  • I'm still stuck. Has anyone of you managed to configure a valid JSON MQTT "last will and testament" message? Would appreciate your help :-)

  • SergeySergey Dublin, Ireland

    Looks like a config parsing bug on our side - no unescape is done.
    Bear with us, will come back with the fix shortly.

  • SergeySergey Dublin, Ireland

    Update your firmware, should work now.
    Let me know how it goes please

  • Thanks, Sergey
    The LWT looks fine now.

Sign In or Register to comment.