mirror of
https://bitbucket.org/myhomie/myhomie_app.git
synced 2025-12-06 00:51:19 +00:00
Add online and secured mqtt connexion
This commit is contained in:
parent
67ff05e28b
commit
d4ed804624
@ -66,16 +66,20 @@ class MyHomePage extends StatefulWidget {
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
final MqttServerClient client = MqttServerClient.withPort('192.168.31.140', 'flutter_client00', 1883); //192.168.31.140
|
||||
//final MqttServerClient client = MqttServerClient.withPort('192.168.31.140', 'flutter_client00', 1883);
|
||||
final MqttServerClient client = MqttServerClient.withPort('myhomie.be', 'flutter_client00', 1883); // TODO ONLINE
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
|
||||
const pubTopic = 'topic/test';
|
||||
final builder = MqttClientPayloadBuilder();
|
||||
builder.addString('Hello MQTT');
|
||||
client.publishMessage(pubTopic, MqttQos.atLeastOnce, builder.payload);
|
||||
print("client.connectionStatus !!! ==" + client.connectionStatus.toString());
|
||||
if (client.connectionStatus.state == MqttConnectionState.connected) {
|
||||
const pubTopic = 'topic/test';
|
||||
final builder = MqttClientPayloadBuilder();
|
||||
builder.addString('Hello MQTT');
|
||||
client.publishMessage(pubTopic, MqttQos.atLeastOnce, builder.payload);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -127,8 +131,8 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
//client.securityContext = context;
|
||||
|
||||
final connMessage = MqttConnectMessage()
|
||||
/*.authenticateAs('thomas', 'MyCore,1')
|
||||
.keepAliveFor(60)
|
||||
.authenticateAs('thomas', 'MyCore,1') // TODO ONLINE
|
||||
/*.keepAliveFor(60)
|
||||
.withWillTopic('willtopic')
|
||||
.withWillMessage('Will message')*/
|
||||
.withClientIdentifier("TESSST")
|
||||
@ -136,6 +140,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
//.withWillQos(MqttQos.atLeastOnce);
|
||||
//client.secure = true;
|
||||
client.connectionMessage = connMessage;
|
||||
client.autoReconnect = true;
|
||||
try {
|
||||
await client.connect();
|
||||
} catch (e) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user