当前位置:网站首页>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
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1
- Build yocto system offline for i.mx8mmini development board
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6
- 研发效能度量框架解读
- [Maui] add click events for label, image and other controls
- 构建外部模块(Building External Modules)
- Virtualenv+pipenv virtual environment management
- 技术分享 | MySQL:从库复制半个事务会怎么样?
- The Missing Semester
- 内核同步机制
猜你喜欢

Mechanism and type of CPU context switch

Comment Cao définit la décimale de dimension

Exploration and practice of inress in kubernetes

Build yocto system offline for i.mx8mmini development board

91. (chapitre Cesium) simulation de lancement de fusées cesium

redis配置环境变量

Consolidate -c operator

二叉堆(一) - 原理与C实现

Chen Gong: Micro service, is it still so pure?
![[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1](/img/be/1194125442aaa2d7cc20b6a4a6762a.jpg)
[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1
随机推荐
Exploration and practice of inress in kubernetes
Dataset partitioning script for classification tasks
C serialization simple experiment
Exposure: a white box photo post processing framework reading notes
uniapp 使用 uni-upgrade-center
Want to ask, is there a discount for opening a securities account? Is it safe to open a mobile account?
Building external modules
Acly and metabolic diseases
CAD如何设置标注小数位
Huawei HMS core joins hands with hypergraph to inject new momentum into 3D GIS
Message queue monitoring refund task batch process
The Missing Semester
Emotion analysis based on IMDB comment data set
强大、好用、适合程序员/软件开发者的专业编辑器/笔记软件综合评测和全面推荐
邻接矩阵无向图(一) - 基本概念与C语言
Joint Time-Frequency and Time Domain Learning for Speech Enhancement
Brief explanation of the working principle, usage scenarios and importance of fingerprint browser
MQ prevent message loss and repeated consumption
Neo4j 中文开发者月刊 - 202206期
NOV Schedule for . Net to display and organize appointments and recurring events