|
| 1 | +package cn.cuiot.dmp.device.bussiness; |
| 2 | + |
| 3 | +import cn.cuiot.dmp.device.util.MqttUtil; |
| 4 | +import lombok.extern.slf4j.Slf4j; |
| 5 | +import org.eclipse.paho.client.mqttv3.MqttException; |
| 6 | + |
| 7 | +public class AuthCommonTest { |
| 8 | + public static void main(String[] args) { |
| 9 | + // 设备1 |
| 10 | + //用户填写,10-48位字母数字"-" |
| 11 | +/* String deviceId1 = "zhiyangji01"; |
| 12 | + //平台新建设备后生成 |
| 13 | + String deviceKey1 = "SFIefovTnfRPiV6"; |
| 14 | + //平台新建设备后生成 |
| 15 | + String deviceSecret1 = "D3DE73DA544E82753C034D22B7CACAE4"; |
| 16 | + //平台新建产品时生成 |
| 17 | + String productKey1 = "cu59flm720qarrke"; |
| 18 | + //平台服务地址 格式: "dmp-mqtt.cuiot.cn:1883" |
| 19 | +
|
| 20 | + // 设备2 |
| 21 | + //用户填写,10-48位字母数字"-" |
| 22 | + String deviceId2 = "xuetangyi01"; |
| 23 | + //平台新建设备后生成 |
| 24 | + String deviceKey2 = "P8948q8ma0kPY5r"; |
| 25 | + //平台新建设备后生成 |
| 26 | + String deviceSecret2 = "9217E1574B1F8AC82BC45147E629217D"; |
| 27 | + //平台新建产品时生成 |
| 28 | + String productKey2 = "cu697dfal4iwbzND"; |
| 29 | + //平台服务地址 格式: "dmp-mqtt.cuiot.cn:1883"*/ |
| 30 | + |
| 31 | + // 设备3 |
| 32 | + //用户填写,10-48位字母数字"-" |
| 33 | + String deviceId3 = "xueyayi01"; |
| 34 | + //平台新建设备后生成 |
| 35 | + String deviceKey3 = "mMKjziAOo1q3ehQ"; |
| 36 | + //平台新建设备后生成 |
| 37 | + String deviceSecret3 = "A7810D47B3E985ACFEE50B097FE1FD29"; |
| 38 | + //平台新建产品时生成 |
| 39 | + String productKey3 = "cu1gqwdbkr9mqxz3"; |
| 40 | + //平台服务地址 格式: "dmp-mqtt.cuiot.cn:1883" |
| 41 | + |
| 42 | +/* // 设备4 |
| 43 | + //用户填写,10-48位字母数字"-" |
| 44 | + String deviceId4 = "huxiji01"; |
| 45 | + //平台新建设备后生成 |
| 46 | + String deviceKey4 = "Jw7Zwy7ifUAwG9U"; |
| 47 | + //平台新建设备后生成 |
| 48 | + String deviceSecret4 = "947B4C03228AF433352E8EB87E3D3831"; |
| 49 | + //平台新建产品时生成 |
| 50 | + String productKey4 = "cu1caux4y0ynyavT"; |
| 51 | + //平台服务地址 格式: "dmp-mqtt.cuiot.cn:1883"*/ |
| 52 | + |
| 53 | + // 设备5 |
| 54 | + //用户填写,10-48位字母数字"-" |
| 55 | + String deviceId5 = "xueyangyi01"; |
| 56 | + //平台新建设备后生成 |
| 57 | + String deviceKey5 = "YPBQ5eOpi5pvwTs"; |
| 58 | + //平台新建设备后生成 |
| 59 | + String deviceSecret5 = "7D9FBDEF9AFDF087E5836C2EB2C0FAC7"; |
| 60 | + //平台新建产品时生成 |
| 61 | + String productKey5 = "cu1gwpy8r7t14vbo"; |
| 62 | + //平台服务地址 格式: "dmp-mqtt.cuiot.cn:1883" |
| 63 | + |
| 64 | + String host = "tcp://dmp-mqtt.cuiot.cn:1883"; |
| 65 | + //工具类 |
| 66 | + MqttUtil mqttUtil = new MqttUtil(); |
| 67 | + try { |
| 68 | +/* //初始化 |
| 69 | + mqttUtil.connectClient(host, deviceId1 + "|" + productKey1 + "|0|0|0", deviceKey1 + "|" + productKey1, |
| 70 | + mqttUtil.generatePassword(deviceId1, deviceKey1, productKey1, deviceSecret1)); |
| 71 | + //订阅 |
| 72 | + mqttUtil.sub(productKey1,deviceKey1); |
| 73 | +
|
| 74 | + //初始化 |
| 75 | + mqttUtil.connectClient(host, deviceId2 + "|" + productKey2 + "|0|0|0", deviceKey2 + "|" + productKey2, |
| 76 | + mqttUtil.generatePassword(deviceId2, deviceKey2, productKey2, deviceSecret2)); |
| 77 | + //订阅 |
| 78 | + mqttUtil.sub(productKey2,deviceKey2);*/ |
| 79 | + |
| 80 | + |
| 81 | + //初始化 |
| 82 | + mqttUtil.connectClient(host, deviceId3 + "|" + productKey3 + "|0|0|0", deviceKey3 + "|" + productKey3, |
| 83 | + mqttUtil.generatePassword(deviceId3, deviceKey3, productKey3, deviceSecret3)); |
| 84 | + //订阅 |
| 85 | + mqttUtil.sub(productKey3, deviceKey3); |
| 86 | + |
| 87 | + |
| 88 | +/* //初始化 |
| 89 | + mqttUtil.connectClient(host, deviceId4 + "|" + productKey4 + "|0|0|0", deviceKey4 + "|" + productKey4, |
| 90 | + mqttUtil.generatePassword(deviceId4, deviceKey4, productKey4, deviceSecret4)); |
| 91 | + //订阅 |
| 92 | + mqttUtil.sub(productKey4,deviceKey4);*/ |
| 93 | + |
| 94 | + |
| 95 | + /* //初始化 |
| 96 | + mqttUtil.connectClient(host, deviceId5 + "|" + productKey5 + "|0|0|0", deviceKey5 + "|" + productKey5, |
| 97 | + mqttUtil.generatePassword(deviceId5, deviceKey5, productKey5, deviceSecret5)); |
| 98 | + //订阅 |
| 99 | + mqttUtil.sub(productKey5,deviceKey5);*/ |
| 100 | + |
| 101 | + |
| 102 | + } catch (MqttException e) { |
| 103 | + System.out.println("!!! Reason Code is: " + e.getReasonCode()); |
| 104 | + System.out.println("!!! Message is: " + e.getMessage()); |
| 105 | + System.out.println("!!! Exception is: " + e); |
| 106 | + e.printStackTrace(); |
| 107 | + } |
| 108 | + } |
| 109 | +} |
0 commit comments