Using MQTT to Upload Images to OneNET

Using MQTT to Upload Images to OneNET

In recent days, I have been preparing for the follow-up IoT STM32 development and practical demonstrations, as well as writing mini-programs, so I haven’t had time to update the articles on my public account.

Actually, I originally planned to wrap up the series of articles about the IoT platform with the last one. However, a fan on Bilibili messaged me asking if I could record a tutorial on uploading images using MQTT, so today I organized my thoughts and wrote a tool to demonstrate the implementation.

1

First, I will demonstrate using the tool I developed to upload an example. I created a product and device based on the MQTT protocol, and entered the data stream page, which currently has no data.

Using MQTT to Upload Images to OneNET

Click the button indicated by the arrow.

Using MQTT to Upload Images to OneNET

Enter the relevant information, then click the “Connect” button.

Using MQTT to Upload Images to OneNET

Click the button indicated by the arrow, and select an image file.

Using MQTT to Upload Images to OneNET

Then click the “Upload Image” button.

Using MQTT to Upload Images to OneNET

The tool indicates that the data stream upload was successful.

Using MQTT to Upload Images to OneNET

We return to the OneNET data stream display page and can see that an image has indeed been uploaded.

Using MQTT to Upload Images to OneNET

Next, I will explain the implementation thought process.

2

I will first assume that you already know how to upload data points using MQTT in JSON format. If not, please take a look at this article “OneNET IoT MQTT Protocol Access (Part 2) — Uploading Data Points”.

What you need to do is first download the document indicated by the arrow.

Using MQTT to Upload Images to OneNET

Then, according to what is described in section 5.2.1 of the document, construct a payload array with a data type of 2.

Then use your own MQTT program to publish a message with the topic “$dp” and the content as the payload array.

To accommodate different programming languages of users, I added a feature to my tool.

Using MQTT to Upload Images to OneNET

After importing the image, you can click the “Bin” button indicated by the arrow to generate the binary data corresponding to the payload.

Using MQTT to Upload Images to OneNET

This way, when you are programming, you can compare whether the payload data generated by your own program is consistent. Of course, you can also directly use my tool to generate the binary file, then load this file into a byte array in your programming language, and send this array directly to OneNET to test the process.

3

Recently, my child has been particularly clingy. Every time he sees me with my computer at home, he says, “Dad, don’t work, play with me,” so I haven’t had time to record videos or write articles after work.

If you have any questions, you can join QQ group 940556740 and ask me directly in the group.

While writing this article, I received an invitation for the internal test of WeChat’s video account feature. I haven’t thought of a short video content idea yet, maybe it will be a VLOG. If possible, everyone can follow and support me, thank you.

Using MQTT to Upload Images to OneNET

【Related Articles】

1. IoT Knowledge Demystification

2. China Mobile OneNET Platform HTTP Protocol Access

3. China Mobile OneNET Platform MQTT Protocol Access (Part 1)

“4. China Mobile OneNET Platform MQTT Protocol Access (Part 2)”

“5. China Mobile OneNET Platform Android Support”

“Extra Chapter: Lua Script Programming Demystification”

“6. OneNET IoT TCP Transparent Transmission Access and Custom Lua Parsing Script”

“7. OneNET IoT EDP Access and Protocol Format Explanation”

“8. OneNET Using HTTP Push”

Leave a Comment