In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article focuses on "how to implement the device registration process and send messages through the MQTT connection cloud", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement the device registration process and send messages through the MQTT connection to the cloud.
A few days ago, when I was studying the access to things, I suddenly thought, when we have a large number of devices waiting to access the Internet of things, is there a faster way to deal with it than burning unique usernames and passwords to the devices one by one? Later, after reading some tutorials and sharing on the Internet, I found that it is possible to burn the default connection information (object model) for initialization to all devices at the beginning, and then report the device ID to generate a new unique device shadow (object shadow) with the help of cloud service (CFC function) when the device is connected to the Internet for the first time. Then disconnect the initialization connection, connect the newly generated object shadow, and begin to work normally. The general diagram is as follows:
It's a pity that I don't have so many devices around me now. After thinking for a long time, I found that WeChat Mini Programs can be used to simulate the device side; as long as the device ID reported each time is different, it can be identified as a different device. So it took me a few days to make a WeChat Mini Programs, so I'll share it with you today! The main functions are as follows: 1. On the Mini Program simulation device, https connects with the CFC function calculation (code will be shared) set in advance in Baidu Yuntiangong to complete the initialization process of the new device and create the shadow of the new device. two。 Send information to a new or existing device created through a MQTT connection. 3. A message list is set up to store messages that users have sent on Mini Program in the past for users to view.
[code]
WeChat Mini Programs source code warehouse github: https://github.com/Lizxxxx/Wechat-connect-BaiduIoT
The CFC function calculates the related code github: https://github.com/Lizxxxx/createDevice-CFC-BaiduIoT (just download the zip file directly)
[developed by WeChat Mini Programs]
It was my first time to contact WeChat Mini Programs, and when I was developing, I found that due to the restrictions of Mini Program, only licensed domain names are allowed to connect through encryption protocols (https or wss), so our MQTT connection to the cloud is achieved through MQTT over wss. You can borrow the open source library directly by using MQTT in Mini Program. Here I use the following open source library: https://github.com/mqttjs/MQTT.js, you can refer to it.
[CFC function calculation-new device initialization]
Before using Mini Program, we need to configure the code for function calculation in the cloud.
First of all, just download the zip file in the github link above me. Then in Baidu Yuntiangong control personal console interface open CFC function calculation, create a function. Here our demo is python, so select python and upload the zip package directly. Remember to configure the environment variables! As shown in the following figure, first add your own AK and SK for your Baidu cloud account, and click to view how to obtain AK/SK (https://cloud.baidu.com/doc/Reference/s/9jwvz2egb/)
Then add the default device description and scheme ID. How to get scheme ID: open the list of object models in the object access project, select the object model that the shadow of the equipment you are about to build later, and open its details page. As shown in the following figure, the red circle is schemaID.
Be careful! Here in the CFC function code I set up a whitelist verification to check the device identity! You can modify this as needed.
After setting up the function code, because WeChat Mini Programs connects the function through https, we need to configure http trigger. Click the new trigger on the trigger page, select the type of http trigger, and enter url as you like. You only need to select (POST,PUT,GET) for the http method here. For convenience, choose not to verify. After the configuration is complete, copy the generated URL path! This is the address that we need to use later so that we can connect through https and use the function!
[Demo]
Here is a brief introduction to this WeChat Mini Programs. UI is relatively simple, please don't mind!
On the home page, if you are connecting an existing device, enter the information to connect directly; if you create a new device, click the new device below.
Enter information to register the new device.
The registration information will be returned after the new device is registered. Remember to save it.
We need a connector shadow before sending a message.
Note here that if it is the first time to send a message to the topic, it is best to subscribe to the topic before sending the message. And custom messages must be entered according to the format; the sending format of the message can be modified as needed in the code.
It is convenient to subscribe to topics, and it is good to return to send messages after subscription.
Enter the message according to the format and then send it. After the message is successfully sent, you can see the format of the message after it is encapsulated.
Go to the message list and you can see the message you just sent. Then choose to return to the home page or continue to send the message.
At this point, I believe you have a deeper understanding of "how to implement the device registration process and send messages through the MQTT connection cloud". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.