メインコンテンツへスキップ

スタートガイド

GitHub

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-mqtt
npx 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は、モバイル回線でのバッテリー消費を増加させます。

現在のコントラクトのソース定義を参照してください。

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);

現在のコントラクトのソース定義を参照してください。

import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.disconnect();
console.log(result);

現在のコントラクトのソース定義を参照してください。

import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.subscribe({
topic: 'topic',
qos: 1,
});
console.log(result);

現在のコントラクトのソース定義を参照してください。

import { MqttBridge } from '@capgo/capacitor-mqtt';
const result = await MqttBridge.publish({
topic: 'topic',
payload: 'payload',
qos: 1,
retained: true,
});
console.log(result);
export type onConnectionLostListener = (x: { connectionStatus: string; reasonCode: number; message: string }) => void;
export type onConnectCompleteListener = (x: { reconnected: boolean; serverURI: string }) => void;
export type onMessageArrivedListener = (x: { topic: string; message: string }) => void;

このページはプラグインの src/definitions.tsから生成されています。upstream で公開 API が変更されたら、再度 sync を実行してください。

Getting Startedの続きを進める

「Getting Started からの続き」セクション

使用している場合 スタートガイド ダッシュボードと API の運用を計画するには、これを次と連携させます @capgo/capacitor-mqtt の使用方法 「@capgo/capacitor-mqtt の使用方法」のネイティブ機能については、 API の概要 「API の概要」の実装の詳細については、 はじめに 「はじめに」における実装の詳細については、 API キー および「API Keys」の実装の詳細については、 デバイス 実装の詳細については Devices を参照してください。