1.0.3-alpha.4 • Published 2 years ago

@ainiteam/quick-iot-device-sdk v1.0.3-alpha.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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);
});
1.0.3-alpha.4

2 years ago

1.0.3-alpha.3

2 years ago

1.0.3-alpha.2

2 years ago

1.0.3-alpha.1

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.1-alpha.3

2 years ago

1.0.1-alpha.2

2 years ago

1.0.1-alpha.1

2 years ago

1.0.0

2 years ago