本地搭建MQTT服务器并进行设备控制(ESP32+MicroPython)

【Android】MQTT入门——服务器部署与客户端搭建 MQTT(Message Queuing Telemetry Transport)是一种基于发布/订阅模式的轻量级消息传输协议,专门针对低带宽、和不稳定网络环境的物联网应用而设计,它可以用极少的代码为互联网设备提供实时可靠的消息服务。 阅读详情

本文用到的设备为esp32,固件是micropython。

1.mqtt服务端

我下的是开源版,下载 EMQX 开源版,免安装,以mac为例,下载解压后直接启动。

./emqx/bin/emqx start

若提示权限问题: sudo xattr -r -d com.apple.quarantine ./emqx

启动后,打开浏览器http://localhost:18083/ 进行登陆,用户名:admin, 密码:public

2.mqtt客户端(可选)

客户端用的是:MQTTX:全功能 MQTT 客户端工具

安装后打开,新建连接,配置如下:

host为你的本机ip地址,port固定1883,其他的随便填。

3.设备连接mqtt服务器

在设备上新建以下两个文件:

(1)umqttsimple.py

try:
    import usocket as socket
except:
    import socket
import ustruct as struct
from ubinascii import hexlify

class MQTTException(Exception):
    pass

class MQTTClient:

    def __init__(self, client_id, server, port=0, user=None, password=None, keepalive=0,
                 ssl=False, ssl_params={}):
        if port == 0:
            port = 8883 if ssl else 1883
        self.client_id = client_id
        self.sock = None
        self.server = server
        self.port = port
        self.ssl = ssl
        self.ssl_params = ssl_params
        self.pid = 0
        self.cb = None
        self.user = user
        self.pswd = password
        self.keepalive = keepalive
        self.lw_topic = None
        self.lw_msg = None
        self.lw_qos = 0
        self.lw_retain = False

    def _send_str(self, s):
        self.so
ESP32+MicroPython实战:5分钟搞定MQTT本地服务器搭建与设备控制 本文详细介绍了如何使用ESP32开发板和MicroPython快速搭建本地MQTT服务器并实现设备控制。通过EMQX开源MQTT broker的部署、ESP32的WiFi连接配置以及MQTTX客户端的测试,读者可以在5分钟内完成物联网设备通信的基础搭建。文章还提供了进阶优化方案和常见问题排查指南,帮助开发者快速掌握MQTT协议在物联网中的应用。 阅读详情

相关推荐

MQTT (EMQX)服务器搭建教程

本文将以 EMQ X v4.3.10(开源版)为例,介绍 EMQ X 在 Docker、Kubernetes、Windows 和 Linux 上的安装方法以及常见问题,为大家利用 MQTT 消息服务器快速搭建物联网平台提供帮助。

weixin_46545987的博客 6782

【MQTT】在ESP32平台上用microPython实现MQTT通信

想要搭建MQTT服务器,请参考 ☞☞ 搭建MQTT服务器篇 服务器平台:Ubuntu20.04 + mosquitto 硬件平台:ESP32开发板 MQTT客户端:mosquitto、 通信猫、 mqttfx等等 开发平台:Thoony 3.2 先看下 microPython 支持哪些模块吧: >>> help('modules') __main__ gc ubinascii upysh _boot

slimmm的博客 1万+

基于ESP8266的MicroPython连接MQTT服务器

基于ESP8266的MicroPython连接MQTT服务器,小白也能构建自己的智能家居。

zhuwade的博客 8343

Micropython开发esp32入门笔记--MQTT篇

MQTT协议是轻量、简单、开放和易于实现的,这些特点使它适用范围非常广泛。在很多情况下,包括受限的环境中,如:机器与机器(M2M)通信和物联网(IoT)。其在,通过卫星链路通信传感器、偶尔拨号的医疗设备、智能家居、及一些小型化设备中已广泛使用。

m0_55202222的博客 4390

20-MicroPython+ESP32实现MQTT通信

通过本实验,学会了使用MicroPython编程语言控制ESP32模块进行MQTT的消息的订阅与发布。

weixin_42255154的博客 2652

用ESP32制作一款智能的Wi-Fi插座,mqtt接入OneNet云平台

基于ESP32的一款Wi-Fi插座1.什么是Wi-Fi插座2.为什么要做一个Wi-Fi插座3.各种物联网插座控制方式对比4.智能Wi-Fi插座硬件部分设计5.智能Wi-Fi插座软件部分设计 1.什么是Wi-Fi插座   Wi-Fi插座,顾名思义,便是利用家庭中的WiFi网络,让您的智能手机或平板电脑等在联网条件下,能通过App或网页操作打开或者关闭指定的电器。作为功能,一方面我们出门在外便可以控制...

daihaojuzi的博客 1万+

微信小程序通过mqtt控制esp32

微信小程序通过巴法云的mqtt控制esp32设备

ling913的专栏 1723

MicroPython ESP32 MQTT发布者工程实现详解

MQTT是一种轻量级物联网消息传输协议,基于发布/订阅模型实现设备与云平台间的异步通信。其核心原理包括TCP连接建立、CONNECT/PUBLISH报文编码、心跳保活(keepalive)机制及主题(Topic)路由规则。在资源受限的嵌入式场景中,MQTT凭借低带宽占用和高可扩展性成为ESP32等MCU接入IoT系统的关键技术。典型应用涵盖传感器数据上报、远程设备控制与边缘消息总线构建。本文以MicroPython为开发环境,深入解析Wi-Fi连接管理、MQTT客户端封装、定时发布调度与LED状态反馈等工程

weixin_34456923的博客 705

基于MicroPython的ESP32与微信小程序MQTT通信实战

本文详细介绍了基于MicroPython的ESP32与微信小程序通过MQTT协议实现远程控制的完整实战方案。项目利用巴法云作为免费MQTT服务器,提供了从设备端编程、小程序开发到通信调试的全流程指南,帮助开发者快速构建低成本、易上手的物联网应用,如智能开关、传感器监控等。

week9的博客 632

搭建自己的MQTT服务器、实现设备上云(Windows+EMQX)

手把手教你搭建自己的私有MQTT服务器,目前各大IOT平台开始进行收费模式。这篇文章介绍如何在Windows下部署EMQX,配置EMQX,完成MQTT客户端接入实现数据通信,数据转发,设备上云。EMQX是一款大规模可弹性伸缩的云原生分布式物联网MQTT消息服务器。

4万+

Apollo学习笔记(4)坐标系

百度Apollo项目用到了多种坐标系,其中帮助文档提及的坐标系包括: 全球地理坐标系(The Global Geographic coordinate system ) 局部坐标系—东-北-天坐标(The Local Frame – East-North-Up,ENU) 车身坐标系—右-前-天坐标(The Vehicle Frame —Right-Forward-Up,RFU) 车身坐标系—前-左-天坐标(The Vehicle Frame —Front-Left-Up,FLU) 还有一种Frenet坐标

qq_24649627的博客 5798

vTaskStartScheduler()详解

是启动 FreeRTOS 实时内核的“扳机”。在调用它之前,你只是创建了一些任务结构,但它们都处于“待命”状态,系统仍然在按传统的裸机前后台方式运行。调用这个函数后,FreeRTOS 内核会接管系统的控制权,开始根据优先级调度你创建的任务,多任务环境才真正开始。关键点:它没有参数。它的所有行为都由中的配置宏控制。它通常不会返回。一旦调用,除非没有任务可以运行(或者你显式地停止了调度器),否则程序流永远不会回到main()函数中调用它的下一行。是一个没有参数但行为由精密控制的函数。

Shylock_Mister的博客 1592

计算机考研常见面试题

写在前面 本人参加20考研,由于复试没有具体要求会问哪几门课,所以我就找了网上一些常见的计算机专业的面试题,整理如下 主要结构: 数据库 软件工程 操作系统 计算机组成原理 计算机网络 数据结构 C++ Java 数据库 1、数据:数据库中存储的基本对象。 数据库:长期存储在计算机内的、有组织的、可共享的数据集合。 数据库管理系统:专门用于建立和管理数据库的一套软件。对外部程序提供访问数据库的方法,对内进行数据管理。 数据库系统:与和数据库相关的整个系统,一般由数据库、数据库管理系统、应用程序、数

qq_38841618的博客 2万+

深信服桌面云实战:从零部署到高效运维的关键配置指南

本文提供了一份深信服桌面云从零部署到高效运维的实战指南。内容涵盖项目启动阶段的资源、网络与存储规划,详细演示了VMP与VDC平台的安装与对接,并深入讲解了制作虚拟机模板、配置用户体系、优化终端策略等核心步骤。最后,分享了包括CPU公平分配、智能调度在内的关键性能调优与高阶运维技巧,旨在帮助管理员构建稳定、高效的云桌面环境。

blockchain9miner的博客 450

手把手教你:如何为自制的STM32H7飞控板适配PX4固件(基于NuttX)

本文详细介绍了如何为自制的STM32H7飞控板适配PX4固件,基于NuttX系统进行移植。从硬件设计规范到软件环境配置,再到PX4固件的移植与调试,提供了完整的实战指南。特别分享了如何复用FMU-v6u参考设计以节省开发时间,并解决了常见问题,帮助开发者快速实现高性能飞控系统的搭建。

weixin_27697385的博客 475

解决rt-thread上使用SPI+DMA

首先阐述下遇到的问题 使用SPI读取icm20602数据,读取频率为1000hz,使用stm32f407主控,发现CPU占用率达到了70%,将此线程注释掉后CPU占用率掉到25%,看来这里要着重优化,便萌生了使用DMA的想法。 使用SPI+DMA要进行的配置 1.开启RTT设备驱动。点击自己的工程 ->RT-Thread Setting2.在board.hzhong3.在board.c文件里加入以下函数,此函数受设备框架调用 void HAL_SPI_MspInit(SPI_HandleTypeDef

响望的博客 8082

别只会‘pip install’了!当Python报错找不到‘pkg_resources’时,你的setuptools可能出大问题

本文深入解析Python开发中常见的`ModuleNotFoundError: No module named 'pkg_resources'`错误,揭示其背后的setuptools依赖问题。通过系统化的诊断与修复指南,帮助开发者理解Python包管理机制,并提供从基础到高级的解决方案,确保pip和setuptools的正常运行。

weixin_42523711的博客 432

[SoC]SoC验证中bootcode与firmware相关验证经验总结

本文总结了SoC验证中bootcode和firmware的验证经验。重点介绍了两种数据加载方法:1)使用Verilog系统函数$readmemh/$readmemb直接写入ROM/ARAM,需注意文件路径、格式和斜杠方向;2)通过Memory Hierarchy在initial块中操作,需要添加适当延时并注意路径拼接。文章还提供了在testcase phase中先读取数据到HASH再写入SRAM的示例,并强调加载后需使能edc_bypass以避免ECC错误。验证过程中需特别注意文件位置、格式要求及路径处理等

元直的博客 2496

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

上一篇: 微信小程序通过mqtt控制esp32
下一篇: python安装pyqt5失败
ling913
博客等级 码龄15年 115粉丝 41原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值