|
@@ -1,8 +1,39 @@
|
|
|
-import { McBarChart, Options } from '@mcui/mccharts'
|
|
|
+import { McBarChart, McLineChart, Options } from '@mcui/mccharts'
|
|
|
+import BusinessConstant, { DeviceType } from '../common/constants/BusinessConstant'
|
|
|
+import MesAioRequest from '../common/util/request/MesAioRequest'
|
|
|
import TimeUtil from '../Common/util/TimeUtil'
|
|
|
+import RequestParamModel from '../viewmodel/warehouse/RequestParamModel'
|
|
|
+import {
|
|
|
+ MqttAsync,
|
|
|
+ MqttConnectOptions,
|
|
|
+ MqttSubscribeOptions,
|
|
|
+ MqttPublishOptions,
|
|
|
+ MqttResponse,
|
|
|
+ MqttMessage,
|
|
|
+ MqttClient,
|
|
|
+} from '@ohos/mqtt';
|
|
|
+import MqttUploadData from '../viewmodel/mqtt/MqttUploadData'
|
|
|
+import TempHumiditySensor from '../viewmodel/device/TempHumiditySensor'
|
|
|
+import MqttDataItem from '../viewmodel/mqtt/MqttDataItem'
|
|
|
+import MqttCmdData from '../viewmodel/mqtt/MqttCmdData'
|
|
|
|
|
|
@Component
|
|
|
export struct WorkshopView {
|
|
|
+ private mqttAsyncClient: MqttClient | null = null;
|
|
|
+ // Set Client Configuration
|
|
|
+ @State subscribeTopic: string = BusinessConstant.mqttSubscribeTopic;
|
|
|
+ @State publishTopic: string = BusinessConstant.mqttPublishTopic;
|
|
|
+ @State payload: string = '';
|
|
|
+ @State url: string = BusinessConstant.mqttUrl;
|
|
|
+ @State clientId: string = BusinessConstant.mqttClientId;
|
|
|
+ @State userName: string = BusinessConstant.mqttUserName;
|
|
|
+ @State password: string = BusinessConstant.mqttPassword;
|
|
|
+ @State connectedCount: number = 0;
|
|
|
+ // @State isConnect: boolean = false;
|
|
|
+ @State isPromise: boolean = false;
|
|
|
+
|
|
|
+
|
|
|
+ @State stations: StationRelateInfo[] = []
|
|
|
|
|
|
@State deviceArray: DeviceInfo[] = [
|
|
|
{deviceName: "高低温试验箱",
|
|
@@ -77,7 +108,9 @@ export struct WorkshopView {
|
|
|
// 设备离线数
|
|
|
@State deviceOfflineNum:number = 0
|
|
|
// 工作状态(1:开工 0:停工)
|
|
|
- @State workStatus:number = 1
|
|
|
+ @State workStatus:number = 0
|
|
|
+
|
|
|
+ @State tempHumiditySensor: TempHumiditySensor = {OnlineStatus: 0}
|
|
|
|
|
|
@State defOption: Options = new Options({
|
|
|
legend: {
|
|
@@ -117,7 +150,7 @@ export struct WorkshopView {
|
|
|
]
|
|
|
})
|
|
|
|
|
|
- aboutToAppear(): void {
|
|
|
+ async aboutToAppear() {
|
|
|
if (this.deviceArray && this.deviceArray.length > 0) {
|
|
|
for (const element of this.deviceArray) {
|
|
|
if (element && element.onlineStatus! === 1) {
|
|
@@ -127,6 +160,15 @@ export struct WorkshopView {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ await this.createClient();
|
|
|
+ await this.connect();
|
|
|
+ await this.subscribe();
|
|
|
+
|
|
|
+ this.stations = await MesAioRequest.post("/api/v1/test/queryStationRelateInfo", {} as RequestParamModel)
|
|
|
+
|
|
|
+ if (this.stations && this.stations.length > 0) {
|
|
|
+ this.deviceOnlineNum = this.stations.length
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
build() {
|
|
@@ -177,7 +219,7 @@ export struct WorkshopView {
|
|
|
// 车间名称
|
|
|
Row() {
|
|
|
Row().width('2.2%')
|
|
|
- Text('2楼车间数字孪生')
|
|
|
+ Text('1楼车间数字孪生')
|
|
|
.fontSize($r('app.float.fontSize_6_4'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
@@ -205,10 +247,11 @@ export struct WorkshopView {
|
|
|
.justifyContent(FlexAlign.Start)
|
|
|
|
|
|
List({space: '2%'}) {
|
|
|
- ForEach(this.deviceArray, (item: DeviceInfo, index: number) => {
|
|
|
+ ForEach(this.stations, (item: StationRelateInfo, index: number) => {
|
|
|
ListItem() {
|
|
|
Stack() {
|
|
|
- Image(item.onlineStatus! === 1 ? $r('app.media.workshop_device_online') : $r('app.media.workshop_device_offline'))
|
|
|
+ // Image(item.onlineStatus! === 1 ? $r('app.media.workshop_device_online') : $r('app.media.workshop_device_offline'))
|
|
|
+ Image(this.deviceArray[0]?.onlineStatus! === 1 ? $r('app.media.workshop_device_online') : $r('app.media.workshop_device_offline'))
|
|
|
.width('100%')
|
|
|
.height('100%')
|
|
|
.borderRadius($r('app.float.fontSize_6_4'))
|
|
@@ -217,12 +260,12 @@ export struct WorkshopView {
|
|
|
Circle()
|
|
|
.width($r('app.float.virtualSize_4_8'))
|
|
|
.height($r('app.float.virtualSize_4_8'))
|
|
|
- .fill(item.onlineStatus! === 1 ? $r('app.color.30D158') : $r('app.color.60FFFFFF'))
|
|
|
- Text(item.deviceName)
|
|
|
+ .fill(this.deviceArray[0]?.onlineStatus! === 1 ? $r('app.color.30D158') : $r('app.color.60FFFFFF'))
|
|
|
+ Text(item.stationName)
|
|
|
.fontSize($r('app.float.virtualSize_6_4'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
|
- .opacity(item.onlineStatus! === 1 ? 1 : 0.6)
|
|
|
+ .opacity(this.deviceArray[0]?.onlineStatus! === 1 ? 1 : 0.6)
|
|
|
}
|
|
|
.width('86%')
|
|
|
.height('24%')
|
|
@@ -242,7 +285,7 @@ export struct WorkshopView {
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
- Text(item.currentProduct)
|
|
|
+ Text(this.deviceArray[0]?.currentProduct)
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -253,7 +296,7 @@ export struct WorkshopView {
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
- Text(item.commissionNum)
|
|
|
+ Text(this.deviceArray[0]?.commissionNum)
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -270,13 +313,13 @@ export struct WorkshopView {
|
|
|
Column() {
|
|
|
Row().height('5%')
|
|
|
Row() {
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[0]?.attributeName! ? item.deviceAttributes[0].attributeName : '')
|
|
|
+ Text(this.deviceArray[1]?.deviceAttributes && this.deviceArray[1]?.deviceAttributes[0]?.attributeName! ? this.deviceArray[1]?.deviceAttributes[0].attributeName : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
.maxLines(1)
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[0]?.attributeValue! ? item.deviceAttributes[0].attributeValue : '')
|
|
|
+ Text(item.loginUserName ? item.loginUserName : '张光明')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.30D158'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -286,13 +329,13 @@ export struct WorkshopView {
|
|
|
.height('22%')
|
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
|
Row() {
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[1]?.attributeName! ? item.deviceAttributes[1].attributeName : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[1]?.attributeName! ?this.deviceArray[0]?.deviceAttributes[1].attributeName : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
.maxLines(1)
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[1]?.attributeValue! ? item.deviceAttributes[1].attributeValue : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[1]?.attributeValue! ? this.deviceArray[0]?.deviceAttributes[1].attributeValue : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.30D158'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -302,13 +345,13 @@ export struct WorkshopView {
|
|
|
.height('22%')
|
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
|
Row() {
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[2]?.attributeName! ? item.deviceAttributes[2].attributeName : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[2]?.attributeName! ? this.deviceArray[0]?.deviceAttributes[2].attributeName : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
.maxLines(1)
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[2]?.attributeValue! ? item.deviceAttributes[2].attributeValue : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[2]?.attributeValue! ? this.deviceArray[0]?.deviceAttributes[2].attributeValue : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.30D158'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -318,13 +361,13 @@ export struct WorkshopView {
|
|
|
.height('22%')
|
|
|
.justifyContent(FlexAlign.SpaceBetween)
|
|
|
Row() {
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[3]?.attributeName! ? item.deviceAttributes[3].attributeName : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[3]?.attributeName! ? this.deviceArray[0]?.deviceAttributes[3].attributeName : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.FFFFFF'))
|
|
|
.fontWeight(FontWeight.Regular)
|
|
|
.opacity(0.6)
|
|
|
.maxLines(1)
|
|
|
- Text(item?.deviceAttributes && item?.deviceAttributes[3]?.attributeValue! ? item.deviceAttributes[3].attributeValue : '')
|
|
|
+ Text(this.deviceArray[0]?.deviceAttributes && this.deviceArray[0]?.deviceAttributes[3]?.attributeValue! ? this.deviceArray[0]?.deviceAttributes[3].attributeValue : '')
|
|
|
.fontSize($r('app.float.fontSize_4_8'))
|
|
|
.fontColor($r('app.color.30D158'))
|
|
|
.fontWeight(FontWeight.Bold)
|
|
@@ -384,11 +427,11 @@ export struct WorkshopView {
|
|
|
.opacity(0.9)
|
|
|
Blank()
|
|
|
Column() {
|
|
|
- Text('25℃')
|
|
|
+ Text((this.tempHumiditySensor?.OnlineStatus! === 1 && this.tempHumiditySensor?.Temperature) ? this.tempHumiditySensor.Temperature / 10 + '℃' : '-')
|
|
|
.fontSize($r('app.float.fontSize_9_6'))
|
|
|
.fontColor($r('app.color.000000'))
|
|
|
.opacity(0.9)
|
|
|
- Text('50%')
|
|
|
+ Text((this.tempHumiditySensor?.OnlineStatus! === 1 && this.tempHumiditySensor?.Humidity) ? this.tempHumiditySensor.Humidity / 10 + '%' : '-')
|
|
|
.fontSize($r('app.float.fontSize_9_6'))
|
|
|
.fontColor($r('app.color.000000'))
|
|
|
.opacity(0.9)
|
|
@@ -445,6 +488,15 @@ export struct WorkshopView {
|
|
|
.backgroundColor($r('app.color.10FFFFFF'))
|
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
|
.onClick(()=>{
|
|
|
+ let item: MqttDataItem = {
|
|
|
+ tag: 'LED3Control',
|
|
|
+ value: 0
|
|
|
+ }
|
|
|
+ let mqttData: MqttCmdData = {
|
|
|
+ w: [item]
|
|
|
+ }
|
|
|
+ this.payload = JSON.stringify(mqttData)
|
|
|
+ this.publish()
|
|
|
this.workStatus = 1
|
|
|
})
|
|
|
// 一键停工
|
|
@@ -471,6 +523,15 @@ export struct WorkshopView {
|
|
|
.backgroundColor($r('app.color.10FFFFFF'))
|
|
|
.borderRadius($r('app.float.virtualSize_6_4'))
|
|
|
.onClick(()=>{
|
|
|
+ let item: MqttDataItem = {
|
|
|
+ tag: 'LED3Control',
|
|
|
+ value: 1
|
|
|
+ }
|
|
|
+ let mqttData: MqttCmdData = {
|
|
|
+ w: [item]
|
|
|
+ }
|
|
|
+ this.payload = JSON.stringify(mqttData)
|
|
|
+ this.publish()
|
|
|
this.workStatus = 0
|
|
|
})
|
|
|
|
|
@@ -500,7 +561,7 @@ export struct WorkshopView {
|
|
|
.width('81%')
|
|
|
.justifyContent(FlexAlign.End)
|
|
|
Row() {
|
|
|
- McBarChart({
|
|
|
+ McLineChart({
|
|
|
options: this.defOption
|
|
|
})
|
|
|
.width('100%')
|
|
@@ -524,6 +585,294 @@ export struct WorkshopView {
|
|
|
.width('100%')
|
|
|
.height('100%')
|
|
|
}
|
|
|
+
|
|
|
+ createClient(): undefined | void {
|
|
|
+ console.log("hhtest", '请求连接');
|
|
|
+ if (this.mqttAsyncClient) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mqttAsyncClient = MqttAsync.createMqtt({
|
|
|
+ url: this.url,
|
|
|
+ clientId: this.clientId,
|
|
|
+ persistenceType: 1,
|
|
|
+ });
|
|
|
+ let num = 0
|
|
|
+ while (num < 5) {
|
|
|
+ if (!this.mqttAsyncClient) {
|
|
|
+ this.mqttAsyncClient = MqttAsync.createMqtt({
|
|
|
+ url: this.url,
|
|
|
+ clientId: this.clientId,
|
|
|
+ persistenceType: 1,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ num++
|
|
|
+ }
|
|
|
+ if (!this.mqttAsyncClient) {
|
|
|
+ console.log("hhtest", '创建失败');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.messageArrived()
|
|
|
+ this.connectLost()
|
|
|
+ this.mqttAsyncClient.setMqttTrace(6);
|
|
|
+ // // this.showLog("create client success");
|
|
|
+ }
|
|
|
+
|
|
|
+ async connect(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "connect");
|
|
|
+ // // this.showLog("connect");
|
|
|
+ let options: MqttConnectOptions = {
|
|
|
+ userName: this.userName,
|
|
|
+ password: this.password,
|
|
|
+ cleanSession:false,
|
|
|
+ connectTimeout: 300
|
|
|
+ };
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!(await this.isConnected())) {
|
|
|
+ if (this.isPromise) {
|
|
|
+ this.mqttAsyncClient.connect(options).then((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "connect result:" + JSON.stringify(data));
|
|
|
+ this.connectedCount++;
|
|
|
+ }).catch((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "connect fail result:" + JSON.stringify(data));
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.mqttAsyncClient.connect(options, (err: Error, data: MqttResponse) => {
|
|
|
+ if (!err) {
|
|
|
+ console.info('hhtest', "connect result:" + JSON.stringify(data));
|
|
|
+ if (data.message == "Connect Success") {
|
|
|
+ console.info('hhtest', "connect result connectedCount:");
|
|
|
+ this.connectedCount++;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "connect error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async publish(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "publish");
|
|
|
+ let publishOption: MqttPublishOptions = {
|
|
|
+ topic: this.publishTopic,
|
|
|
+ qos: 1,
|
|
|
+ payload: this.payload
|
|
|
+ }
|
|
|
+ console.log('hhtest', 'publish msg:----------' + JSON.stringify(this.payload))
|
|
|
+ console.log('hhtest', 'publish msg:----------' + JSON.stringify(publishOption))
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (await this.isConnected()) {
|
|
|
+ if (this.isPromise) {
|
|
|
+ this.mqttAsyncClient.publish(publishOption).then((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "publish success result:" + JSON.stringify(data));
|
|
|
+ }).catch((err: MqttResponse) => {
|
|
|
+ console.info('hhtest', "publish fail result:" + JSON.stringify(err));
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.mqttAsyncClient.publish(publishOption, (err: Error, data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "publish response:");
|
|
|
+ if (!err) {
|
|
|
+ console.info('hhtest', "publish result:" + JSON.stringify(data));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "publish error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async subscribe(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "subscribe");
|
|
|
+ let subscribeOption: MqttSubscribeOptions = {
|
|
|
+ topic: this.subscribeTopic,
|
|
|
+ qos: 2
|
|
|
+ }
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ console.info('hhtest', "client not created");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (await this.isConnected()) {
|
|
|
+ if (this.isPromise) {
|
|
|
+ this.mqttAsyncClient.subscribe(subscribeOption).then((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "subscribe success result:" + JSON.stringify(data));
|
|
|
+ }).catch((err: MqttResponse) => {
|
|
|
+ console.info('hhtest', "subscribe fail result:" + JSON.stringify(err));
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.mqttAsyncClient.subscribe(subscribeOption, (err: Error, data: MqttResponse) => {
|
|
|
+ if (!err) {
|
|
|
+ console.info('hhtest', "subscribe result:" + JSON.stringify(data));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "subscribe error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ messageArrived(): undefined | void {
|
|
|
+ console.info('hhtest', "messageArrived");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mqttAsyncClient.messageArrived((err: Error, data: MqttMessage) => {
|
|
|
+ if (!err) {
|
|
|
+ // this.showLog(msg);
|
|
|
+ let dataStr = JSON.stringify(data);
|
|
|
+ console.info('hhtest', "messageArrived message:" + dataStr);
|
|
|
+ if (dataStr.indexOf('Assemble_500W') !== -1) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let updateData: MqttUploadData = JSON.parse(data.payload) as MqttUploadData;
|
|
|
+ if (!updateData || !updateData.d || updateData.d.length <= 0) {
|
|
|
+ console.info('hhtest', "updateData没有解析成功" + JSON.stringify(updateData));
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ let device0: TempHumiditySensor = { Temperature: 0, Humidity: 0, OnlineStatus: 0 }
|
|
|
+ let collectFlag: Array<boolean> = [false]
|
|
|
+
|
|
|
+ for (const element of updateData.d) {
|
|
|
+ if (BusinessConstant.attrMap.has(element.tag)) {
|
|
|
+ let deviceType: string = BusinessConstant.attrMap.get(element.tag) ?? '';
|
|
|
+ switch (deviceType) {
|
|
|
+ case DeviceType.TempHumiditySensor:
|
|
|
+ collectFlag[0] = true
|
|
|
+ if (element.tag! === 'Temperature') {
|
|
|
+ device0.Temperature = element.value
|
|
|
+ } else if (element.tag! === 'Humidity') {
|
|
|
+ device0.Humidity = element.value
|
|
|
+ }
|
|
|
+ device0.OnlineStatus = 1
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (collectFlag[0]) {
|
|
|
+ this.tempHumiditySensor = device0;
|
|
|
+ } else {
|
|
|
+ this.tempHumiditySensor = {
|
|
|
+ OnlineStatus: 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.info('hhtest', "this.tempHumiditySensor" + JSON.stringify(this.tempHumiditySensor));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "messageArrived error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async unsubscribe(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "unsubscribe");
|
|
|
+ let subscribeOption: MqttSubscribeOptions = {
|
|
|
+ topic: this.subscribeTopic,
|
|
|
+ qos: 2
|
|
|
+ }
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (await this.isConnected()) {
|
|
|
+ if (this.isPromise) {
|
|
|
+ this.mqttAsyncClient.unsubscribe(subscribeOption).then((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "unsubscribe success result:" + JSON.stringify(data));
|
|
|
+ }).catch((err: MqttResponse) => {
|
|
|
+ console.info('hhtest', "unsubscribe fail result:" + JSON.stringify(err));
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.mqttAsyncClient.unsubscribe(subscribeOption, (err: Error, data: MqttResponse) => {
|
|
|
+ if (!err) {
|
|
|
+ console.info('hhtest', "unsubscribe result:" + JSON.stringify(data));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "unsubscribe error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async disconnect(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "disconnect");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (await this.isConnected()) {
|
|
|
+ if (this.isPromise) {
|
|
|
+ this.mqttAsyncClient.disconnect().then((data: MqttResponse) => {
|
|
|
+ console.info('hhtest', "disconnect success result:" + JSON.stringify(data));
|
|
|
+ }).catch((err: MqttResponse) => {
|
|
|
+ console.info('hhtest', "disconnect fail result:" + JSON.stringify(err));
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.mqttAsyncClient.disconnect((err: Error, data: MqttResponse) => {
|
|
|
+ if (!err) {
|
|
|
+ console.info('hhtest', "disconnect result:" + JSON.stringify(data));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "disconnect error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ async isConnected(): Promise<undefined | boolean> {
|
|
|
+ console.info('hhtest', "isConnected");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return this.mqttAsyncClient.isConnected().then((data: boolean) => {
|
|
|
+ console.info('hhtest', "isConnected result:" + data);
|
|
|
+ if (!data) {
|
|
|
+ }
|
|
|
+ return data;
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ async reconnect(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "reconnect");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!(await this.isConnected())) {
|
|
|
+ if (this.connectedCount == 0) {
|
|
|
+ console.info('hhtest', "reconnect: client previously not connected");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mqttAsyncClient.reconnect().then((data: boolean) => {
|
|
|
+ console.info('hhtest', "reConnected result:" + data);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ connectLost(): undefined | void {
|
|
|
+ console.info('hhtest', "connectLost");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mqttAsyncClient.connectLost((err: Error, data: MqttResponse) => {
|
|
|
+ if (!err) {
|
|
|
+ this.reconnect();
|
|
|
+ console.info('hhtest', "connect lost cause:" + JSON.stringify(data));
|
|
|
+ } else {
|
|
|
+ console.info('hhtest', "connect lost error:" + JSON.stringify(err));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async destroy(): Promise<undefined | void> {
|
|
|
+ console.info('hhtest', "destroy");
|
|
|
+ if (this.mqttAsyncClient == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.mqttAsyncClient.destroy().then((data: boolean) => {
|
|
|
+ console.info('hhtest', "destroy result:" + data);
|
|
|
+ this.mqttAsyncClient = null;
|
|
|
+ this.connectedCount = 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class DeviceInfo {
|
|
@@ -542,4 +891,12 @@ class DeviceInfo {
|
|
|
class DeviceAttribute {
|
|
|
attributeName?: string
|
|
|
attributeValue?: string
|
|
|
+}
|
|
|
+
|
|
|
+// 工位相关信息
|
|
|
+class StationRelateInfo {
|
|
|
+ // 工位名称
|
|
|
+ stationName?: string
|
|
|
+ // 登录人员名称
|
|
|
+ loginUserName?: string
|
|
|
}
|