An IoT Test Tool : Development Notes


基于Python的 IoT 工具开发记录。

Perform 运行表现

I built an IoT testing tool for work. Can’t share it (company rules), but writing this down so I don’t forget.

Users can retrieve gateway information and send/receive commands. Instead of manually entering the Gateway ID, they can scan a QR code. The tool uses MQTT to transmit commands and data, and by storing information in a class, data management becomes more efficient. For critical commands like ‘delete gateways,’ users must enter a password. The tool automatically updates information upon receiving feedback via the MQTT channel.

This is a test page. I’ve organized gateway test methods into separate classes – selecting different gateway types will run tests against their specific standards.

Built in Python, the tool works on both Windows (as an EXE) and macOS (as an app).

Note 奇奇怪怪的问题


我用python的CV2来扫描二维码(这个操作让整个程序大了一倍…),但是CV2的二维码扫描效果并不算好,速度和识别能力上远不如微信。有个二维码甚至我加上了专门的图像预处理代码, 在肉眼看起来极为清晰的情况下,依然难以识别…

I use python’s CV2 to scan the QR code. (This operation doubles the size of the entire program…) However, the QR code scanning effect of CV2 is not very good. Its speed and recognition ability are far inferior to those of wechat. There is a QR code that I even added with a special image preprocessing code. Even when it looks extremely clear to the naked eye, it is still difficult to recognize…

预处理前/before preprocessing

Python在编译为exe时,会有好些文件问题。

比如在Pycharm内完美运行的程序,死活打包失败,强行用命令行启动才看到报错,原来是文件找不到,最后的解决方法是将所有文件都放同一级目录,且调用的证书文件需要专门在打包命令中指出。

CV2这个神奇的包,pip安装名不一样已经是老生常谈的了,打包也会出错,需要加上’–hidden-import=cv’

最后打包命令要写这么长:

When Python is compiled into an exe file, there are quite a few file issues.

For instance, when a program runs perfectly within Pycharm, no matter how hard it is packaged, it fails. When forcibly started with the command line, an error is seen. It turns out that the file cannot be found. The final solution is to place all the files in the same directory at the same level, and the certificate file called needs to be specifically pointed out in the packaging command.

It has been a common topic that the installation names of pip for this amazing package CV2 are different. Packaging errors can also occur, and ‘– hidder-import =cv’ needs to be added.

Finally, the packaging command should be written this long:

conda activate mqtt-testtool
pyinstaller --noconfirm --onefile --windowed ^
--icon=E:\xxx\MQTT-testtool\favicon.ico ^
--add-data="E:\xxx\MQTT-testtool\certificate1.pem.crt;." ^
--add-data="E:\xxx\MQTT-testtool\certificate2.pem.crt;." ^
--add-data="E:\xxx\MQTT-testtool\certificate3.pem.crt;." ^
--add-data="E:\xxx\MQTT-testtool\key1-ca.pem;." ^
--add-data="E:\xxx\MQTT-testtool\key2-ca.pem;." ^
--add-data="E:\xxx\MQTT-testtool\key3-ca.pem;." ^
--add-data="E:\xxx\MQTT-testtool\private1.pem.key;." ^
--add-data="E:\xxx\MQTT-testtool\private2.pem.key;." ^
--add-data="E:\xxx\MQTT-testtool\private3.pem.key;." ^
--hidden-import=cv2 ^
--exclude-module=macholib ^
E:\xxx\MQTT-testtool\UI.py

更加诡异的问题是,完全相同的代码,在mac会有启动缓慢和重复开启诡异情况,一开始是疯狂开新程序,直到我强行关闭电脑,在加了一堆防重复的操作后,依然会在第一次关闭时,再开一个新的程序(?你这是想干啥)

The even more bizarre problem is that the exact same code on a mac will have a strange situation of slow startup and repeated opening. At first, it would frantically open new programs. Even after I forcibly shut down the computer and added a bunch of anti-repetition operations, it would still open a new program when it was shut down for the first time (? What are you trying to do?


Leave a Reply

Your email address will not be published. Required fields are marked *