当前位置:网站首页>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
边栏推荐
- 消息队列之监控退款任务批处理过程
- LeetCode 454. Add four numbers II
- 构建外部模块(Building External Modules)
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
- Share the method of how to preview PSD format and PSD file thumbnail plug-in [easy to understand]
- Is it safe for Huatai Securities to open an account online?
- S7-1500plc simulation
- [Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4
- Dataset partitioning script for classification tasks
- CAD如何設置標注小數比特
猜你喜欢

Prepare for the Blue Bridge Cup Day10__ PWM control light brightness

Software project management 9.2 Software project configuration management process

使用set_handler过滤掉特定的SystemC Wraning &Error Message

LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制

Exposure: a white box photo post processing framework reading notes

Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation

Message queue monitoring refund task batch process
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6](/img/0e/0900e386f3baeaa506cc2c1696e22a.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 6

Uniapp uses uni upgrade Center

Joint Time-Frequency and Time Domain Learning for Speech Enhancement
随机推荐
博途V15添加GSD文件
easyexcel的使用
Deep understanding of grpc part1
Use set_ Handler filters out specific SystemC wrapping & error messages
Le semester manquant
91. (cesium chapter) cesium rocket launch simulation
Value/set in redis
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
Uniapp uses uni upgrade Center
[classic example] classic list questions @ list
耐克如何常年霸榜第一名?最新財報答案來了
Binary stack (I) - principle and C implementation
Chen Gong: Micro service, is it still so pure?
如何看懂开发的查询语句
Emotion analysis based on IMDB comment data set
I'm in Zhongshan. Where is a better place to open an account? Is it actually safe to open an account online?
Value/hush in redis
Consolidate -c operator
Dlhsoft Kanban, Kanban component of WPF
Redis启动与库进入