Jump to content

Json struct in MQTT


pascal

Recommended Posts

Hi,

I want to communicate with a IoT trough MQTT. I managed to send simple JSON commands, but i'm looking how to configure more difficult JSON structs...

I want to send this telegram to my IoT device, but I don't have any idea how to setup my json struct....

has to look like this.....

{

    "FountainSchema": {

        "enable_pump_1": true,

        "startclock_pump_1": "08:30:00",

        "stopclock_pump_1": "14:00:00",

        "enable_remote_frequency": false,

        "remote_frequency": 32.8

    }

}

I know I can make a struct like this :

enable_pump_1 = BIT

startclock_pump_1 = ascii[8]

stopclock_pump_1 = ascii[8]

enable_remote_frequency = BIT

remùote_frequency= BIT

 

but how do I get the tag FountainSchema into my json struct ?

like I want to receive some publications made from my IoT device :

{

  "metrics" : [ {

    "name" : "response",

    "tags" : {

      "organization_id" : 1,

      "company_id" : 1,

      "tasktype_id" : 91,

      "service_id" : 77,

      "project_id" : 501,

      "task_id" : 1659,

      "property_id" : 111,

      "propertytype_id" : 999

    },

    "fields" : {

      "measurement" : "switch_pump_1",

      "value" : 5,

      "type" : "switch"

    },

    "timestamp" : "2024-02-14T14:45:16.000Z"

  } ]

}

how and where do I program my JSON struct  I want to publish or to subscribe ?

 

Link to comment
Share on other sites

Hi,

There's no yet support for a nested STRUCT over JSON, if the structure is not too complex, you can try maybe (never tried) to build an ASCII buffer having the entire JSON and publish as a RAW type.

Need to try that.

Message composer feature might make your life easier, building the structure once and setting the values of the tags to get the buffer that will have the exact JSON structure..

Link to comment
Share on other sites

Hi Ivgeny,

Thanks for your reply. Indeed, I think I have, like you said, to use the message composer for publishing nested structs in JSON and send them as raw data.

I only have 1 question about the message composer -> you can scan a message, but what with receiving a variable as ascii, but the length of the ascii can be different...

the ascii variable in JSON is always between "", but I don't see how to program this. I thought the ascii variable has a fixed length in message composer ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.