MQTTの始め方
インストール手順とこのプラグインのフル マークダウン ガイドを含むセットアップ プロンプトをコピーします。
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-Assisted Setupを使用してプラグインをインストールできます。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.Manual Setupを使用する場合は、以下のコマンドを実行してプラグインをインストールし、以下のプラットフォーム固有の指示に従ってください。
bun add @capgo/capacitor-mqttbunx cap syncインポート
「インポート」のセクションimport { MqttBridge } from '@capgo/capacitor-mqtt';API オーバービュー
API オーバービューのセクションconnect
接続のセクション現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.connect({} as { serverURI: string; port: number; clientId: string; username: string; password: string; setCleanSession: boolean; connectionTimeout: number; keepAliveInterval: number; setAutomaticReconnect: boolean; setLastWill?: { willTopic: string; willPayload: string; willQoS: number; setRetained: boolean; }; });disconnect
切断のセクション現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.disconnect();subscribe
サブスクライブのセクション現在の契約のソース定義を参照してください。
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.subscribe({} as { topic: string; qos: number });publish
Section titled “publish”See the source definitions for the current contract.
import { MqttBridge } from '@capgo/capacitor-mqtt';
await MqttBridge.publish({} as { topic: string; payload: string; qos: number; retained: boolean });Type Reference
Section titled “Type Reference”onConnectionLostListener
Section titled “onConnectionLostListener”export type onConnectionLostListener = (x: { connectionStatus: string; reasonCode: number; message: string }) => void;onConnectCompleteListener
Section titled “onConnectCompleteListener”export type onConnectCompleteListener = (x: { reconnected: boolean; serverURI: string }) => void;onMessageArrivedListener
Section titled “onMessageArrivedListener”export type onMessageArrivedListener = (x: { topic: string; message: string }) => void;Source Of Truth
「ソース オブ トゥルース」このページはプラグインから生成されています。 src/definitions.ts.再度、パブリック API がアップストリームで変更されたときは、再度同期を実行してください。
「Getting Started」から続けてください。
「Getting Started」から続けてください。「Getting Started」を使用してダッシュボードと __CAPGO_KEEP_0__ の作業を計画している場合、__CAPGO_KEEP_0__ を使用して接続してください。 「@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-mqtt」を使用して、@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-mqtt のネイティブ機能を使用します。 「@API/__CAPGO_KEEP_1__-mqtt」 「@capgo/capacitor-mqtt」の実装詳細については、「capgo Overview」を参照してください。 for the native capability in Using @capgo/capacitor-mqtt, 「API Overview」 「API Overview」 概要 概要の実装詳細について API キー 概要の実装詳細について、API キー、 デバイス 概要の実装詳細についてデバイス