Update page 'Message Queue Endpoint'
This commit is contained in:
parent
91d42601bf
commit
0a5517d7e7
@ -58,30 +58,29 @@ First, we will create a MQTT client to connect to the FarmMaps MQTT broker:
|
|||||||
from farmmaps import mqtt
|
from farmmaps import mqtt
|
||||||
|
|
||||||
#MQTT connection settings
|
#MQTT connection settings
|
||||||
CLIENT_ID = 'trekkerdata'
|
CLIENT_ID = '<your client id>'
|
||||||
USER = "trekkerdata"
|
USER = "<your username>"
|
||||||
PWD = "<your password here>"
|
PWD = "<your password here>"
|
||||||
HOST = "farmmaps.awtest.nl"
|
HOST = "farmmaps.awacc.nl"
|
||||||
PORT = 1883
|
PORT = 1883
|
||||||
KEEPALIVE = 60
|
KEEPALIVE = 60
|
||||||
TOPIC = "trekkerdata/sensors"
|
TOPIC = "<company-name>/<topic-name>"
|
||||||
|
|
||||||
#set up MQTT client
|
#set up MQTT client
|
||||||
mqtt_client = mqtt.create_client(CLIENT_ID, USER, PWD, HOST, PORT, KEEPALIVE)
|
mqtt_client = mqtt.create_client(CLIENT_ID, USER, PWD, HOST, PORT, KEEPALIVE)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Preparing your data as a protobuf message
|
||||||
### Example: Pushing Live Tractor Data
|
|
||||||
To create messages and connect to the broker we will need the following settings:
|
|
||||||
|
|
||||||
|
|
||||||
#### Preparing your data as a protobuf message
|
|
||||||
Farmmaps uses protobuf to specify a structure for the messages published in MQTT.
|
Farmmaps uses protobuf to specify a structure for the messages published in MQTT.
|
||||||
Protobuf provides a fast way of serializing and unserializing objects, reducing bandwith usage.
|
|
||||||
More information on protobuf can be found at [Google Developer Documentation](https://developers.google.com/protocol-buffers/docs/overview).
|
More information on protobuf can be found at [Google Developer Documentation](https://developers.google.com/protocol-buffers/docs/overview).
|
||||||
Python objects can easily be converted to protobuf messages and back (when recieving messages from the broker).
|
Python objects can easily be converted to protobuf messages and back (when recieving messages from the broker).
|
||||||
|
|
||||||
The message structure for the data can be found in `farmmaps/farmmaps.proto`, and is shown below:
|
The message structure for the data can be found in `farmmaps/farmmaps.proto`, and is shown below.
|
||||||
|
The main message is the Datapoint object, containing time, location, machine-id and a reference to metadata.
|
||||||
|
Then, there is a `sensors` parameter, which holds a dictionary of `SensorType` objects.
|
||||||
|
Each `SensorType` holds a key and a value, where the key identifies the Sensortype, and the value is the value of the sensor.
|
||||||
|
Finally, there's an optional `metadata_url` parameter that specifies where FarmMaps can get metadata.
|
||||||
|
This is data that specifies how the values for each sensortype are to be interpreted.
|
||||||
|
|
||||||
```
|
```
|
||||||
syntax = "proto2";
|
syntax = "proto2";
|
||||||
@ -154,6 +153,8 @@ for key, value in sensordata.items():
|
|||||||
In case you want to modify the structure of the object, the `.proto` can be modified, and the python module needs to be regenerated.
|
In case you want to modify the structure of the object, the `.proto` can be modified, and the python module needs to be regenerated.
|
||||||
For now, we'll stick with the pregenerated protobuf class: `
|
For now, we'll stick with the pregenerated protobuf class: `
|
||||||
|
|
||||||
|
### Example: Pushing Live Tractor Data
|
||||||
|
To create messages and connect to the broker we will need the following settings:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user