nodeMCU wifi透傳到串列埠 支援hex

billnie發表於2018-06-08

測試從wifi傳資料到串列埠

cnt = 0

cl = net.createConnection(net.TCP, 0)
cl:connect(8080, "192.168.1.102")
cl:on("receive", function(sck, c) 
  --  print(c) 
    uart.write(0, c);
    end)
cl:on("disconnection", function(sck, c) print("disconnection!") end)
cl:on("sent", function(c) 
    if cnt ~= 10 then
        cl:send(cnt)
        cnt = cnt + 1
    end 
end)

cl = net.createConnection(net.TCP, 0)
cl:connect(8080, "192.168.1.102")
cl:on("receive", function(sck, c) 
    uart.write(0, c);
    end)
cl:on("disconnection", function(sck, c) print("disconnection!") end)
cl:on("sent", function(c) 
end)

uart.on("data", 1,
  function(data)
    cl:send(data)
    if data=="quit"then
      uart.on("data") -- unregister callback function
    end

end, 0)

相關文章