为了验证 AIR700 IPV6 ,特别新建向NodeRed Tcp发送的工程。
Air700发送TCP数据源码如下:
--[[
IPv6客户端演示, 仅EC618系列支持, 例如Air780E/Air600E/Air780UG/Air700E
]]
-- LuaTools需要PROJECT和VERSION这两个信息
PROJECT = "IPV6_SendDate_Nodered_TCP"
VERSION = "1.0.0"
log.info("main", PROJECT, VERSION)
-- 一定要添加sys.lua !!!!
sys = require("sys")
libnet = require "libnet"
local netc
-- 演示task
sys.taskInit(function()
-- 仅EC618系列支持, 例如Air780E/Air600E/Air780UG/Air700E
if rtos.bsp() ~= "EC618" then
while 1 do
log.info("ipv6", "only Air780E/Air600E/Air780UG/Air700E supported")
sys.wait(1000)
end
end
-- 启用IPv6, 默认关闭状态,必须在驻网前开启
-- 注意, 启用IPv6, 联网速度会慢2~3秒
mobile.ipv6(true)
log.info("ipv6", "等待联网")
sys.waitUntil("IP_READY")
log.info("ipv6", "联网完成")
sys.wait(100)
socket.setDNS(nil, 1, "119.29.29.29")
socket.setDNS(nil, 2, "114.114.114.114")
end)
sys.taskInit(function()
sys.waitUntil("IP_READY")
local dName = "D2_TASK"
netc = socket.create(nil, dName)
local succ=socket.config(netc)
log.info("socket.congfig",succ )
local succ1, result = socket.connect(netc, "www.yourUrl.top",12300,true)
log.info("socket.connect",succ1)
log.info("IPV6", "ip", socket.localIP())
sys.wait(2000)
local cnt=0
local strCnt
while true do
cnt=cnt+1
strCnt="From Air700 No."..cnt.." Messages."
local succ1, full, result1 = socket.tx(netc, strCnt)
-- local succ1, full, result1 = socket.tx(netc, strCnt, "www.yourUrl.top", 12300 )
--TCP应用则忽略 --端口--TCP应用则忽略
log.info("socket.SEND",strCnt)
sys.wait(6000)
end
end)
-- 用户代码已结束---------------------------------------------
-- 结尾总是这一句
sys.run()
-- sys.run()之后后面不要加任何语句!!!!!
代码中注意点:
1 socket.connect(netc, "www.yourUrl.top",12300,true)
socket.connect函数的need_ipv6_dns必须设置成true,以便开启IPV6.
2 socket.tx(netc, strCnt, "www.yourUrl.top",12300 ) 函数中的域名和端口号可以忽略。
3 行号52 sys.wait(2000)延时不能少,可保证NodeRed收到第一条数据
NodeRed代码
[
{
"id": "f6f2187d.f17ca8",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": ""
},
{
"id": "4ba8347f531551e7",
"type": "debug",
"z": "f6f2187d.f17ca8",
"name": "debug 2",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 240,
"wires": []
},
{
"id": "5d8b8559cac5fb20",
"type": "tcp in",
"z": "f6f2187d.f17ca8",
"name": "",
"server": "server",
"host": "",
"port": "2300",
"datamode": "stream",
"datatype": "utf8",
"newline": "",
"topic": "",
"trim": false,
"base64": false,
"tls": "",
"x": 280,
"y": 240,
"wires": [
[
"4ba8347f531551e7"
]
]
}
]