首先拿到wifi模块先给它连上网络,然后就可以开始通信了。使用ESP-01S和python建立客户端服务端,使用qt建立一个界面,有两个lineEdit和一个pushButton在第一个lineEdit输入1到16,在第二个输入150到600,wifi模块可以接收到这两个数字,并且控制16路舵机控制板控制相应的角度。这里也是编译成功。Arduino的代码有简单的示例,下面是python
from PyQt5 import QtCore, QtGui, QtWidgets, uic
import sys,requests,time,socket
# 服务器参数
host = '192.168.130.79' # 服务器IP地址
port = 80 # 服务器端口号
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((host, port))
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(390, 210, 93, 28))
self.pushButton.setObjectName("pushButton")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(200, 140, 113, 21))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(360, 140, 113, 21))
self.lineEdit_2.setObjectName("lineEdit_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "确认"))
form_class=uic.loadUiType("untitled.ui")[0]
class pWindow(QtWidgets.QMainWindow,form_class):
def __init__(self,parent=None):
QtWidgets.QMainWindow.__init__(self,parent)
self.setupUi(self)
self.pushButton.clicked.connect(self.a)
def a(self):
a=self.lineEdit.text()+self.lineEdit_2.text()
client_socket.send(a.encode())
time.sleep(0.01)
app=QtWidgets.QApplication(sys.argv)
window=pWindow()
window.show()
app.exec_()
window.setWindowTitle("serve")
client_socket.close()
|