@ainiteam/quick-iot-device-sdk
v1.0.3-alpha.4
Published
quick-iot-device-sdk
Downloads
27
Maintainers
Readme
quick-iot-device-sdk
demo
import iot from "./iot";
import { Packet } from "mqtt";
import { IConnectResult, IMessageResult } from "./types";
//MQTT 连接参数
const config: IOTConfig = {
productKey: "productKey",
deviceName: "deviceName",
clientOptions: {
host: "mqttHostUrl",
port: "port",
protocol: "mqtt",
clientId: "clientId",
username: "username",
password: "password",
},
};
const device = iot.createDeviceInstance(config);
device.online();
device.on("connect", (res: IConnectResult) => {
console.log("connect success.", res);
});
device.on("message", (topic: string, payload: Buffer, res: IMessageResult) => {
console.log("message:", {
topic,
payload: payload.toString(),
res,
});
setTimeout(() => {
device.postProps(
{ CurrentHumidity: 15, CurrentTemperature: 34 },
(packet?: Packet) => {
console.log("postProps", packet);
}
);
}, 1000 * 3);
});