最好的电子音响科技diy制作网站

haoDIY_音响电子电脑科技DIY小制作发明

当前位置: 主页 > 电子DIY > 综合DIY >

用ESP8266改造LM8562数字钟互联网校时,比GPS省电,比NTP简单,(2)

时间:2017-05-27 21:09来源:数码之家 作者:maidoo 点击:
function constructConnection() if bConnected == false then socket = nil socket = net.createConnection(net.TCP, 0) socket:on(connection, function(sck, response) bConnected = true sentCnt = sentCnt + 1
  • function constructConnection()
  •     if bConnected == false then
  •         socket = nil
  •         socket = net.createConnection(net.TCP, 0)
  •         socket:on("connection", function(sck, response)
  •             bConnected = true
  •             sentCnt = sentCnt + 1
  •             print("\r\n#### Conneted!\t\t&socket:", socket)
  •             socket:send(httpPKG)
  •         end)
  •         socket:on("disconnection", function(sck, response)
  •             bConnected = false
  •             socket:close()
  •             socket = nil
  •             print("#### Socket disconneted, @Count=" .. sentCnt ..", Heap=" .. node.heap())
  •         end)
  •         socket:on("receive", function(sck, response)
  •             --print("[Recv] " .. response)
  •             hh = nil
  •             curGMT = string.sub(response,string.find(response,"Date: "),string.find(response,"Date: ")+35)
  •             -- print(curGMT)    -- Date: Sat, 23 Jan 2016 09:10:20 GMT
  •             hh,mm,ss = string.match(curGMT, "(%d+)%d*:(%d+)%d*:(%d+)%d* GMT")
  •             if hh ~= nil then
  •                 print("#### Get Internet time from " .. host, (hh+tzone)%24, mm, ss)
  •                 --刚上电需要校准一次,之后仅在半夜12点到1点之间执行校准,这样按钮的次数少
  •                 if (calibratedAfterPowerOn == false) or (hh + tzone == 24) then
  •                     calibratedAfterPowerOn = true
  •                     adjustClock(hh+tzone, mm)
  •                 end
  •             end
  •         end)
  •         socket:connect(port, host)
  •     end
  • end
  • -- +++++++++++++++++++++++++++++++
  • constructConnection()
  • tmr.alarm(tmrCycled,3660000,1,function() constructConnection() end)


  • 用ESP8266改造LM8562数字钟互联网校时,比GPS省电,比NTP简单,

     
    (责任编辑:admin)
    织梦二维码生成器
    顶一下
    (0)
    0%
    踩一下
    (0)
    0%
    相关文章
    ------分隔线----------------------------
    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    评价:
    表情:
    用户名: 验证码:点击我更换图片
    栏目列表
    推荐内容