- 6-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 5-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 2-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 2-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 3-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 4-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 7-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 4-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 3-STM32物联网开发WIFI(ESP8266)+GPRS(A
- 15-STM32物联网开发WIFI(ESP8266)+GPRS(
https://www.cnblogs.com/yangfengwu/p/10891908.html
视频教程:
https://www.bilibili.com/video/av55663292
请先自行补充基础内容
https://www.cnblogs.com/yangfengwu/p/6921832.html
https://www.cnblogs.com/yangfengwu/category/1383497.html1-3节
这一节的GPRS程序和https://www.cnblogs.com/yangfengwu/p/10875886.html这节的WIFI做相同的功能,整体功能也一样,单片机复位自动升级
现在测试
1,下载GPRS程序 ,主要的GPRS程序就是收到连接TCP指令就去连接TCP,然后透传...
![](https://img.haomeiwen.com/i8454753/b8c393391901663c.gif)
![](https://img.haomeiwen.com/i8454753/34f92c7568765494.gif)
![](https://img.haomeiwen.com/i8454753/851caff4ff86db1e.gif)
require "socket"
module(..., package.seeall)
--串口配置
local globalSendData1 = nil
local globalSendData = nil
local UART_ID = 1 --uart1
local uartReadData = "";
local uartReadDataFlage = false;
local ip=nil
local port=nil
local asyncClient
sys.taskInit(function()
while true do
while not socket.isReady() do sys.wait(1000) end
if port~=nil and ip~=nil then
asyncClient = socket.tcp()
if asyncClient:connect(ip, port) then
uart.write(1,"{\"datemcu\":\"updata\",\"state\":\"ConnectOK\"}")--发送链接成功指令
print("{\"datemcu\":\"updata\",\"state\":\"ConnectOK\"}");
else
uart.write(1,"{\"datemcu\":\"updata\",\"state\":\"ConnectNO\"}")
end
port = nil;
ip=nil;
while asyncClient:asyncSelect(60, "ping") do end--必须有这个,负责TCP的后台运行
asyncClient:close()
end
sys.wait(1000)
end
end)
-- TCP接受到数据,发送串口
sys.subscribe("SOCKET_RECV", function(id)
if asyncClient.id == id then
local data = asyncClient:asyncRecv()
uart.write(1,data)
end
end)
local jsondata,result,errinfo;
--定时器空闲中断检测(串口空闲接收数据)
local TimerFunc4Cnt = 0;
local function TimerFunc4()
if uartReadDataFlage == true then
TimerFunc4Cnt = TimerFunc4Cnt+1;
if TimerFunc4Cnt >= 20 then
TimerFunc4Cnt=0;
uartReadDataFlage = false;
globalSendData = uartReadData;
uartReadData = "";
end
end
if globalSendData ~= nil then
jsondata,result,errinfo = json.decode(globalSendData)--判断是不是json
if result and type(jsondata)=="table" then -- 是json数据
if jsondata["datemcu"] ~= nil and jsondata["datemcu"] =="updata" then
if jsondata["cmd"] ~= nil and jsondata["cmd"] =="ConnectTCP" then
if jsondata["ip"] ~= nil and jsondata["port"] ~=nil then
ip = jsondata["ip"]
port = jsondata["port"]
end
end
end
else
if asyncClient ~=nil then
asyncClient:asyncSend(globalSendData)--TCP发送数据
end
end
globalSendData = nil;
end
end
sys.timerLoopStart(TimerFunc4,10)
--读取串口接收到的数据
local uartdata = ""
local function read()
uartdata = ""
while true do
uartdata = uart.read(UART_ID,"*l",0)
if not uartdata or string.len(uartdata) == 0 then break end
uartReadData = uartReadData..uartdata;
uartReadDataFlage = true
TimerFunc4Cnt = 0;
end
end
uart.on(UART_ID,"receive",read)
--配置并且打开串口
uart.setup(UART_ID,115200,8,uart.PAR_NONE,uart.STOP_1)
![](https://img.haomeiwen.com/i8454753/aa5a12960e669980.gif)
![](https://img.haomeiwen.com/i8454753/03e151e027893b01.gif)
![](https://img.haomeiwen.com/i8454753/f24f91c194c0bc37.gif)
![](https://img.haomeiwen.com/i8454753/e138cb416134c20f.png)
后期文章改动,根据文章标题查找
![](https://img.haomeiwen.com/i8454753/76574df7c0269b4d.png)
![](https://img.haomeiwen.com/i8454753/d39b919f34adb743.png)
下载单片机IAP程序
![](https://img.haomeiwen.com/i8454753/4275c864386ea1bf.png)
云端的还是这个
![](https://img.haomeiwen.com/i8454753/4d69c820ea4796b6.png)
测试
![](https://img.haomeiwen.com/i8454753/f5c9ca9b976618a5.png)
![](https://img.haomeiwen.com/i8454753/5117841c787e3ed1.png)
![](https://img.haomeiwen.com/i8454753/b4c37be7430d34ee.png)
![](https://img.haomeiwen.com/i8454753/61bb022b2a9395b8.png)
修改云端版本,复位下单片机
![](https://img.haomeiwen.com/i8454753/3ef0f3cee2619a7c.png)
网友评论