mirror of
https://github.com/meshtastic/meshtastic.git
synced 2024-12-26 22:19:46 -08:00
Merge pull request #951 from GUVWAF/JSONdownlink
Update MQTT JSON downlink according to new requirements
This commit is contained in:
commit
230196acd5
|
@ -268,7 +268,7 @@ First, create an input text helper entity. The preferred way to configure an inp
|
|||
|
||||
### Create a Send Message Automation
|
||||
|
||||
This automation will check the send box for changes. After typing a message, either hit enter or click off the box and the automation will send a text string in JSON to the mqtt broker. Make sure to update the channel name and device ID in the example below.
|
||||
This automation will check the send box for changes. After typing a message, either hit enter or click off the box and the automation will send a text string in JSON to the mqtt broker. Make sure to call your channel "mqtt" and to update the device ID and `from` field in the example below.
|
||||
|
||||
```yaml
|
||||
- alias: Meshtastic - Send Automation
|
||||
|
@ -288,9 +288,9 @@ This automation will check the send box for changes. After typing a message, ei
|
|||
data:
|
||||
qos: 0
|
||||
retain: false
|
||||
topic: msh/2/json/LongFast/!67ea9400
|
||||
topic: msh/2/json/mqtt/!67ea9400
|
||||
payload: >-
|
||||
{"channel":"0","sender":"broker","type":"sendtext","payload":"{{
|
||||
{"from":1743426560,"type":"sendtext","payload":"{{
|
||||
states('input_text.meshtastic_send_box') }}"}
|
||||
- delay:
|
||||
hours: 0
|
||||
|
|
|
@ -96,11 +96,14 @@ The `from` field can thus be used as a stable identifier for a specific node. N
|
|||
|
||||
If the message received contains valid JSON in the payload, the JSON is deserialized and added as a JSON object rather than a string containing the serialized JSON.
|
||||
|
||||
**Sent messages** will be checked if the MQTT payload contains a valid JSON-encoded envelope:
|
||||
|
||||
#### JSON downlink to instruct a node to send a message
|
||||
You can also send a JSON message to the topic `msh/2/json/mqtt/` to instruct a gateway node to send a message to the mesh. Note that the channel **must** be called "mqtt". The JSON message should contain the following fields:
|
||||
|
||||
```json
|
||||
{
|
||||
"sender": "SENDER",
|
||||
"from": <node number>,
|
||||
"type": "type",
|
||||
"payload": {
|
||||
"key":"value"
|
||||
...
|
||||
|
@ -108,7 +111,10 @@ If the message received contains valid JSON in the payload, the JSON is deserial
|
|||
}
|
||||
```
|
||||
|
||||
`sender` and `payload` fields are required for a valid envelope. If a valid MQTT message is found, the message is sent over the radio as a message of type `TEXT_MESSAGE_APP` with the serialized `payload` value in the message payload.
|
||||
`from` and `payload` fields are required for a valid envelope (note that in firmware <2.2.20 a field `sender` was required, but this is no longer the case). The `from` field should be equal to the node number of the node that will transmit the message. Optionally, you can specify a destination by setting the `to` field to the node number of the destination. If the `to` field is not set, the message will be broadcast to all nodes on the mesh.
|
||||
|
||||
Currently two types of messages are supported: `"sendtext"` and `"sendposition"`.
|
||||
For the type `sendtext`, the `payload` should be a string containing the text to send. For the type `sendposition`, the payload should be an object with the fields `latitude_i`, `longitude_i`, `altitude` (optional) and `time` (optional).
|
||||
|
||||
### Basic Configuration
|
||||
|
||||
|
|
|
@ -54,13 +54,13 @@ The JSON output only publishes the following subset of the messages on a Meshtas
|
|||
> Protobufs are mesh native.
|
||||
|
||||
#### 1. Using JSON-encoded messages
|
||||
Make sure that option *JSON Output Enabled* is set in MQTT module options.
|
||||
Make sure that option *JSON Output Enabled* is set in MQTT module options and your channel is called "mqtt".
|
||||
|
||||
Below is a valid JSON envelope for information sent by MQTT to a device for broadcast onto the mesh.
|
||||
|
||||
```json
|
||||
{
|
||||
"sender":"whatever you want to be the SENDER",
|
||||
"from":<node number of the transmitter>,
|
||||
"type":"sendtext",
|
||||
"payload": text or a json object go here
|
||||
}
|
||||
|
@ -979,11 +979,11 @@ The flow is:
|
|||
]
|
||||
```
|
||||
|
||||
Sending a position to a device for broadcast to the mesh is much easier with JSON. This introduces a new MQTT Service Envelope type: "sendposition". A valid MQTT envelope and message to broadcast lat, lon, altitude looks like this.
|
||||
Sending a position to a device for broadcast to the mesh is much easier with JSON. It requires a channel called "mqtt". This introduces a new MQTT Service Envelope type: "sendposition". A valid MQTT envelope and message to broadcast lat, lon, altitude (optional) and time (optional) looks like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"sender": "someSender",
|
||||
"from": 2130636288,
|
||||
"type": "sendposition",
|
||||
"payload": {
|
||||
"latitude_i": 399600000,
|
||||
|
|
Loading…
Reference in a new issue