スタートガイド
インストール手順と、このプラグインの完全なMarkdownガイドを含むセットアッププロンプトをコピーします。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-mqtt`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/mqtt/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
インストール
「インストール」セクションAIアシストによるセットアップでプラグインをインストールできます。以下のコマンドを使用して、お使いのAIツールに Capgo のスキルを追加してください:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins次に、以下のプロンプトを使用します:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-mqtt` plugin in my project.手動セットアップを希望する場合は、以下のコマンドを実行してプラグインをインストールし、下記のプラットフォーム別の手順に従ってください:
npm install @capgo/capacitor-mqttnpx cap syncインポート
「インポート」セクションimport { MqttBridge } from '@capgo/capacitor-mqtt';クイックスタート
「クイックスタート」セクションTLSで接続し、自動再接続を有効にした後、バックエンドがパブリッシュするテレメトリトピックを購読します。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.connect({ serverURI: 'ssl://broker.example.com', port: 8883, clientId: 'cap-app-1', username: 'device-user', password: 'device-secret', setCleanSession: true, connectionTimeout: 30, keepAliveInterval: 60, setAutomaticReconnect: true,});await MqttBridge.subscribe({ topic: 'devices/telemetry', qos: 1 });よくある落とし穴
「よくある落とし穴」セクション- TLS: 一致
serverURIブローカーの要件に合わせたスキーム。 - バックグラウンド: AndroidがWebViewをサスペンドした後に再接続します。
- QoS: 高いQoSは、モバイル回線でのバッテリー消費を増加させます。
API の概要
「API 概要」セクションconnect
「connect」セクション現在のコントラクトのソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.connect({ serverURI: 'https://example.com', port: 8080, clientId: 'client-id-123', username: 'username', password: 'password', setCleanSession: true, connectionTimeout: 1000, keepAliveInterval: 1000, setAutomaticReconnect: true,});console.log(result);disconnect
「disconnect」セクション現在のコントラクトのソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.disconnect();console.log(result);subscribe
「subscribe」セクション現在のコントラクトのソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.subscribe({ topic: 'topic', qos: 1,});console.log(result);publish
「publish」セクション現在のコントラクトのソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.publish({ topic: 'topic', payload: 'payload', qos: 1, retained: true,});console.log(result);型リファレンス
「型リファレンス」セクションonConnectionLostListener
「onConnectionLostListener」セクションexport type onConnectionLostListener = (x: { connectionStatus: string; reasonCode: number; message: string }) => void;onConnectCompleteListener
「onConnectCompleteListener」セクションexport type onConnectCompleteListener = (x: { reconnected: boolean; serverURI: string }) => void;onMessageArrivedListener
「onMessageArrivedListener」セクションexport type onMessageArrivedListener = (x: { topic: string; message: string }) => void;Source of Truth
「Source Of Truth」セクションこのページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。
Getting Startedの続きを進める
「Getting Started からの続き」セクション使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-mqtt の使用方法 「@capgo/capacitor-mqtt の使用方法」のネイティブ機能については、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。