【问题标题】:Transfer RSSI data from ESP8266 to PC将 RSSI 数据从 ESP8266 传输到 PC
【发布时间】:2016-10-01 17:03:56
【问题描述】:

我想将 RSSI 测量从 ESP8266 传输到 PC,然后我将在 C 平台和简单的 IPS(室内定位系统)中使用此测量。 我该如何进行此数据传输? 我试图通过 TCP 传输这些数据。但是如何在 TCP 服务器中写入 RSSI 值?例如下面的代码写“你好nodeMCU。我可以在TCP服务器上实时打印这样的RSSI值吗?我的意思是ESP会得到RSSI然后发送到TCP服务器。谢谢你的帮助?

print(wifi.setmode(wifi.STATION))
print(wifi.sta.config("SSid","password"))
print(wifi.sta.getip())
print('\nAll About Circuits main.lua\n')
tmr.alarm(0, 1000, 1, function()
    if wifi.sta.getip() == nil then
        print("Connecting to AP...\n")
    else
        ip, nm, gw=wifi.sta.getip()
        print("IP Info: \nIP Address: ",ip)
        print("Netmask: ",nm)
        print("Gateway Addr: ",gw,'\n')
        tmr.stop(0)
    end
end)

-- Start a simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload)
        print(payload)
        conn:send("Hello, NodeMCU!!! ")
    end)
    conn:on("sent",function(conn) conn:close() end)
end)

【问题讨论】:

    标签: lua esp8266 nodemcu


    【解决方案1】:

    主要问题是:您的服务器在哪里?您发布的代码在 ESP8266 上启动了一个服务器。但是,根据您的描述,我了解到您希望在 PC 上运行服务器并从设备向其发送数据?

    您从 All About Circuits 复制的服务器代码中存在潜在的内存泄漏(关闭的向上值)。试试这个:

    srv=net.createServer(net.TCP)
    srv:listen(80,function(conn)
        conn:on("receive",function(sck,payload)
            print(payload)
            sck:send("Hello, NodeMCU!!! ")
        end)
        conn:on("sent",function(sck) sck:close() end)
    end)
    

    但是如果服务器在您的 PC 上并且假设它是 HTTP 服务器,您应该像这样使用NodeMCU HTTP module

    • 开始一个新的计时器
    • 在每个间隔读取RSSI
    • 向服务器发送 HTTP POST

    这是代码

    -- replace interval, server address, headers and body of course
    tmr.alarm(1, 5000, 1, function()
        local rssi = wifi.sta.getrssi()
        http.post('http://httpbin.org/post',
            'Content-Type: application/json\r\n',
            '{"rssi":"'..rssi..'"}',
            function(code, data)
                if (code < 0) then
                    print("HTTP request failed")
                else
                    print(code, data)
                end
            end)
    end)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多