MQTT integration

Integrations

Hi all,

I'm trying to create an app in which I can list various devices and realtime receive their messages. I'm trying to do that with the Flespi platform and the MQTT integration.

Does anyone know how to set this up?

What have you tried so far?

I've tried starting with setting up a custom action, but this can't be parsed and I really don't know what to do :).

// Automatic FlutterFlow imports

import '/flutter_flow/flutter_flow_theme.dart';

import '/flutter_flow/flutter_flow_util.dart';

import '/custom_code/actions/index.dart'; // Imports other custom actions

import '/flutter_flow/custom_functions.dart'; // Imports custom functions

import 'package:flutter/material.dart';

// Begin custom action code

// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

// Import the mqtt_client package

import 'package:mqtt_client/mqtt_client.dart' as mqtt;

import 'package:mqtt_client/mqtt_server_client.dart';

// Custom action code

Future mqtt() async {

class MqttService {

final mqtt.MqttServerClient client = mqtt.MqttServerClient('mqtt.flespi.io', 'flutter_client');

bool get

Future<void> connectToMqtt() async {

try {

client.port = 8883; // Use SSL port

client.secure = true; // Enable SSL

client.logging(on: true);

final mqtt.MqttConnectMessage connectMessage = mqtt.MqttConnectMessage()

.authenticateAs('YOUR_FLESPI_TOKEN', '') // Replace with your actual flespi token

.withClientIdentifier('flutter_client')

.keepAliveFor(60)

.startClean()

.withWillQos(mqtt.MqttQos.atLeastOnce);

client.connectionMessage = connectMessage;

await client.connect();

print('MQTT connected!');

// Subscribe to your channel topic after successful connection

const topic = 'flespi/message/gw/channels/YOUR_CHANNEL/+';

client.subscribe(topic, mqtt.MqttQos.atLeastOnce);

} catch (e) {

print('MQTT connection failed: $e');

}

}

}

Did you check FlutterFlow's Documentation for this topic?
Yes
1
1 reply