ESP8266TCP Client 断开自动重连AD采集Word下载.docx
- 文档编号:17058055
- 上传时间:2022-11-28
- 格式:DOCX
- 页数:13
- 大小:1.12MB
ESP8266TCP Client 断开自动重连AD采集Word下载.docx
《ESP8266TCP Client 断开自动重连AD采集Word下载.docx》由会员分享,可在线阅读,更多相关《ESP8266TCP Client 断开自动重连AD采集Word下载.docx(13页珍藏版)》请在冰豆网上搜索。
end)
tmr.alarm(1,3000,0,function()
dofile("
Client.lua"
)
新建了一个Client.lua
wifi.setmode(wifi.STATIONAP)
cfg={}
cfg.ssid="
Hellow8266"
cfg.pwd="
11223344"
wifi.ap.config(cfg)
apcfg={}
apcfg.ssid="
qqqqq"
apcfg.pwd="
wifi.sta.config(apcfg)
wifi.sta.autoconnect
(1)
ClientConnectedFlage=0
TcpConnect=nil
tmr.alarm(1,1000,1,function()
ifClientConnectedFlage==0then
Client=net.createConnection(net.TCP,0)
Client:
connect(8080,"
192.168.1.103"
on("
receive"
function(Client,data)
uart.write(0,data)
end)
connection"
function(sck,c)
ClientConnectedFlage=1
TcpConnect=Client
print("
LinkOK"
tmr.stop
(1)
disconnection"
ClientConnectedFlage=0
TcpConnect=nil
tmr.start
(1)
LinkError"
end
uart.on("
data"
0,function(data)
ifTcpConnect~=nilthen
TcpConnect:
send(data)
end,0)
printip=0
wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED,function(T)
printip=0
wifi.eventmon.register(wifi.eventmon.STA_GOT_IP,function(T)
ifprintip==0then
+IP"
..T.IP)
printip=1
现在测试
现在创建服务器
发送数据测试
现在断开连接
第一次没有截到网络调试助手的图,模块就连接上了,,所以又断开了一次
现在就用这个读取AD的电压值
命令和回复呢咱就这样规定
现在的init.lua
ifadc.force_init_mode(adc.INIT_ADC)then
node.restart()
return
end
现在的Client.lua
ReadAd(data)
functionReadAd(data)
ifdata=="
++MD9"
then
ad=adc.read(0)
send("
++MDAD="
..ad)
对了测试的电压是0-1V
然后分辨率是
1024
我现在接到3.3上
如果数据向加CRC校验,看这篇文章的最后
五,ESP8266TCP服务器多连接
TCP就说道这里
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- ESP8266TCP Client 断开自动重连AD采集 断开 自动 AD 采集