Webportal v2

embedded apps

API Reference - MQTT.publish

Availability: SDK only.
Required Privacy: Location
Operations:

This API allows publish data to your offboard system.

Input Parameter
Param name Description Type Unit/Values Example Required
message

Data message to send.

any

n/a

my data true
subtopic

Name of the subtopic.

string

n/a

SectionA false
Output Data
Data name Description Type Unit/Values Example
messageId

Identifier of the message sent.

int

n/a

42
Code Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
webportal.set(
    /* api name */
    "MQTT.publish",
    /* parameters */
     { 
      "message": "my data",
      "subtopic": "SectionA"
        }
  )
  /* callback for `REPLY` messages */
  .then((message) => {
    if (message.status === 200) {
      /* handle `REPLY` success */
    }
    else { /* handle `REPLY` error */ }
  })
1
2
3
4
5
6
7
8
9
{
  "id": "7372c16f-5f2f-42c9-84a7-5490e35f1be0", 
  "type": "SET", 
  "api": "MQTT.publish",
  "params":  { 
    "message": "my data",
    "subtopic": "SectionA"
  }
}
1
2
3
4
5
6
7
8
9
10
// --- format of the `REPLY` message ---

{
  "id": "7372c16f-5f2f-42c9-84a7-5490e35f1be0",
  "type": "REPLY",
  "api": "MQTT.publish",
  "status": 200,
  "statusText": "OK", 
  "data": 42
}

false

This API allows publish data to your offboard system.

Input Parameter
No input params
Output Data
Data name Description Type Unit/Values Example
messageId

Identifier of the message sent.

int

n/a

42
status

Delivery status.

string

- delivered

- notDelivered
delivered
Code Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
webportal.subscribe(
    /* api name */
    "MQTT.publish",
    /* parameters */
     null,
    /* callback for `NOTIFY` messages */
    async (notifyMessage) => {
      if (notifyMessage.status === 200) {
        /* handle `NOTIFY` response */
      }
      else { /*  handle `NOTIFY` error  */ }
    }
  )
  /* callback for `REPLY` messages */
  .then((message) => {
    if (message.status === 200) {
      /* handle `REPLY` success */
    }
    else { /* handle `REPLY` error */ }
  })
1
2
3
4
5
6
{
  "id": "7372c16f-5f2f-42c9-84a7-5490e35f1be0", 
  "type": "SUBSCRIBE", 
  "api": "MQTT.publish",
  "params":  null
}
1
2
3
4
5
6
7
8
9
10
11
// --- format of the `REPLY` message ---
// type: acknowledge the status of the subscription
// reception: only once after the subscription request
// contains outputed data: no
{
  "id": "7372c16f-5f2f-42c9-84a7-5490e35f1be0",
  "type": "REPLY",
  "status": 200,
  "statusText": "OK"
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// --- format of the `NOTIFY` message ---
// type: event message about the subscription
// reception: each time the conditions of the subscription are met
// contains outputed data: yes
{
  "id": "7372c16f-5f2f-42c9-84a7-5490e35f1be0",
  "type": "NOTIFY",
  "api": "MQTT.publish",
  "status": 200,
  "statusText": "OK", 
  "data":  { 
    "messageId": 42,
    "status": "delivered"
  } 
}