Open leon-thomm opened 2 years ago
Example will be in the repo
MqttServerClient mqttclient = MqttServerClient.withPort(address, 'iot_device', 1883); // 1883 standard port for Mqtt
void connected() {
print("Connected");
}
mqttclient.onConnected = connected;
final connMessage = MqttConnectMessage()
.authenticateAs('username', 'password')
.withWillTopic('willtopic')
.withWillMessage('Will message')
.startClean()
.withWillQos(MqttQos.atLeastOnce);
mqttclient.keepAlivePeriod = 60;
mqttclient.connectionMessage = connMessage;
try {
await mqttclient.connect();
print("Connected to Mqtt Server");
} catch (e) {
print('Error Connecting');
}
const pubTopic = 'topic/test';
final builder = MqttClientPayloadBuilder();
String data2SendStr = "";
builder.addString(data2SendStr);
mqttclient.publishMessage(pubTopic, MqttQos.atLeastOnce, builder.payload!);
[
{
"time": 5555,
"temp": 26.0,
"light": 512,
"x": 512,
"y": 512,
"z": 512
},
{
"time": 6666,
"temp": 26.0,
"light": 512,
"x": 512,
"y": 512,
"z": 512
}
]
[
{
"time": 5555,
"temp": 26.0,
"light": 512,
"acc": [<x>, <y>, <z>, <g_res>],
"gyro": [<pitch>, <yaw>, <roll>]
},
...
]
g_res
is the resulting g force; already computed on the WeMOS
I couldn't get the app to publish arbitrary packets to the cloud. I've currently pushed my changes into a41e79c9c075bcf075aa75ad46631ecb7d4bc26b, which i'll work on after the checkin.
https://pub.dev/packages/mqtt_client