当前位置:网站首页>Onenet Internet of things platform - mqtts product equipment connected to the platform
Onenet Internet of things platform - mqtts product equipment connected to the platform
2022-07-01 12:05:00 【Rain cloud 21】
MQTT.fx Make device access :MQTT client 1.7.1 download
One 、 Generate token
Use MQTT.fx Make device access , Generate token Need to use product ID、 Equipment name And equipment key
1、 In the product overview product ID

2、 In the device list Equipment name

3、 In the equipment details key

4、 Generate token
Generate... Based on this information token, Generate token Of java The code is as follows :
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
public class TokenUtils {
public static String assembleToken(String version, String resourceName, String expirationTime,
String signatureMethod, String accessKey)
throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
StringBuilder sb = new StringBuilder();
String res = URLEncoder.encode(resourceName, "UTF-8");
String sig = URLEncoder.encode(generatorSignature(version, resourceName, expirationTime
, accessKey, signatureMethod), "UTF-8");
sb.append("version=")
.append(version)
.append("&res=")
.append(res)
.append("&et=")
.append(expirationTime)
.append("&method=")
.append(signatureMethod)
.append("&sign=")
.append(sig);
return sb.toString();
}
public static String generatorSignature(String version, String resourceName, String expirationTime,
String accessKey, String signatureMethod) throws NoSuchAlgorithmException,
InvalidKeyException {
String encryptText = expirationTime + "\n" + signatureMethod + "\n" + resourceName + "\n" + version;
String signature;
byte[] bytes = HmacEncrypt(encryptText, accessKey, signatureMethod);
signature = Base64.getEncoder().encodeToString(bytes);
return signature;
}
public static byte[] HmacEncrypt(String data, String key, String signatureMethod)
throws NoSuchAlgorithmException, InvalidKeyException {
// Construct a key according to the given byte array , The second parameter specifies the name of a key algorithm
SecretKeySpec signinKey = null;
signinKey = new SecretKeySpec(Base64.getDecoder().decode(key),
"Hmac" + signatureMethod.toUpperCase());
// Generate a specified Mac Algorithm Of Mac object
Mac mac = null;
mac = Mac.getInstance("Hmac" + signatureMethod.toUpperCase());
// Initialize with the given key Mac object
mac.init(signinKey);
// complete Mac operation
return mac.doFinal(data.getBytes());
}
public enum SignatureMethod {
SHA1, MD5, SHA256;
}
public static void main(String[] args) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {
// Parameter group version number , Currently only supported "2018-10-31"
String version = "2018-10-31";
// product id
String productId = "480701";
// Equipment name
String deviceName = "yuyun-test";
// equipment key
String accessKey = "jZLOJzdXrR091nb6+V5KersX2U0JkNlCrR/0ezhzKyA=";
String resourceName = String.format("products/%s/devices/%s", productId, deviceName);
String expirationTime = System.currentTimeMillis() / 1000 + 100 * 24 * 60 * 60 + "";
String signatureMethod = SignatureMethod.SHA1.name().toLowerCase();
String token = assembleToken(version, resourceName, expirationTime, signatureMethod, accessKey);
System.out.println("Authorization:" + token);
}
}
Generated after run token:
version=2018-10-31&res=products%2F480701%2Fdevices%2Fyuyun-test&et=1648354863&method=sha1&sign=Nyg9dc6wLOfp4WdProtID68jlL0%3D
Two 、MQTT.fx Client configuration
Open client

1、 Configuration parameters
| Broker Address | Broker Port | Client ID | User Name | Password | explain |
|---|---|---|---|---|---|
| 183.230.40.16 mqttstls.heclouds.com | 8883 | Equipment name | product ID | The previous generation token | Encryption interface |
| 183.230.40.96 mqtts.heclouds.com | 1883 | Equipment name | product ID | The previous generation token | Unencrypted interface |
Pictured :

2、SSL/TLS Encryption Settings
If the connection address is :183.230.40.16:8883 or mqttstls.heclouds.com:8883, It needs to be done SSL/TLS Encryption Settings
Download the certificate : Certificate address Official document certificate location
choice CA certificate file, Import the extracted Certificate

3、 ... and 、 Device to connect
Click the profile selection arrow , Select the configuration MQTTS Device access

Click on Connect, Make device access , There is a green ball in the upper right corner , Successful connection

here onenet The device in the platform console is “ On-line ” state

So the connection is successful
边栏推荐
- 内核同步机制
- Value/sortedset in redis
- redis中value/String
- 邻接矩阵无向图(一) - 基本概念与C语言
- Joint Time-Frequency and Time Domain Learning for Speech Enhancement
- ABBIRB120工业机器人机械零点位置
- 91.(cesium篇)cesium火箭发射模拟
- Neo4j 中文开发者月刊 - 202206期
- 我在中山,到哪里开户比较好?实际上网上开户安全么?
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
猜你喜欢

谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征

使用set_handler过滤掉特定的SystemC Wraning &Error Message
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3](/img/ea/c5e8d12007873385fa0d197fa62fd2.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 3

GID:旷视提出全方位的检测模型知识蒸馏 | CVPR 2021

Redis的攻击手法

91.(cesium篇)cesium火箭發射模擬

How to understand the developed query statements
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7](/img/41/e3ecbd49e4bfeab6c6e7d8733fe33a.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 7
![[Maui] add click events for label, image and other controls](/img/d6/7ac9632681c970ed99c9e4d3934ddc.jpg)
[Maui] add click events for label, image and other controls

基于IMDB评论数据集的情感分析
随机推荐
博途V15添加GSD文件
用于分类任务的数据集划分脚本
Comment Nike a - t - il dominé la première place toute l'année? Voici les derniers résultats financiers.
陈珙:微服务,它还那么纯粹吗?
Istio, ebpf and rsocket Broker: in depth study of service grid
Build yocto system offline for i.mx8mmini development board
Value/string in redis
Unity xlua co process packaging
Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
Explore the contour detection function findcontours() of OpenCV in detail with practical examples, and thoroughly understand the real role and meaning of each parameter and mode
Self organization is the two-way rush of managers and members
[Maui] add click events for label, image and other controls
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
【单片机】【数码管】数码管显示
S7-1500plc simulation
CPI tutorial - asynchronous interface creation and use
LeetCode 454. 四数相加 II
easyexcel的使用
Adjacency matrix undirected graph (I) - basic concepts and C language
GID: open vision proposes a comprehensive detection model knowledge distillation | CVPR 2021