저는 이제 ESP8266MOD 무선 랜 칩으로 MQTT 클라이언트를 이식하는 C# .net Xamarin 개발자입니다.NodeMCU ESP8266MOD Esplorer MQTT 간단한 MQTT by foobarflies
아무리해도 나는 파일, gpio, http, i2c, mqtt, 그물, 노드, tmr, uart, wifi와 함께 fightanic에서 사용자 정의 NodeMCU 빌드를 번쩍 내 버렸습니다. 나는 simple MQTT project by foorbarflies을 팔로우하고있다. 내가 갓 플래시 칩에 다음 파일을 업로드 한
: 나는 명령 dofile("test.lua");
내가 얻을 보내
-- file : config.lua
local module = {}
module.SSID = {}
module.SSID["xxxxx xxxxxxx"] = "xxxxxxxxxxxxxxxxx"
module.HOST = "mqtt.xxxxxxxxxxx.com"
module.PORT = 1883
module.ID = node.chipid()
module.ENDPOINT = "nodemcu/"
return module
-- file: setup.lua
local module = {}
local function wifi_wait_ip()
if wifi.sta.getip()== nil then
print("IP unavailable, Waiting...")
else
tmr.stop(1)
print("\n====================================")
print("ESP8266 mode is: " .. wifi.getmode())
print("MAC address is: " .. wifi.ap.getmac())
print("IP is "..wifi.sta.getip())
print("====================================")
app.start()
end
end
local function wifi_start(list_aps)
if list_aps then
for key,value in pairs(list_aps) do
if config.SSID and config.SSID[key] then
wifi.setmode(wifi.STATION);
wifi.sta.config(key,config.SSID[key])
wifi.sta.connect()
print("Connecting to " .. key .. " ...")
--config.SSID = nil -- can save memory
tmr.alarm(1, 2500, 1, wifi_wait_ip)
end
end
else
print("Error getting AP list")
end
end
function module.start()
print("Configuring Wifi ...")
wifi.setmode(wifi.STATION);
wifi.sta.getap(wifi_start)
end
return module
-- file : application.lua
local module = {}
m = nil
-- Sends a simple ping to the broker
local function send_ping()
m:publish(config.ENDPOINT .. "ping","id=" .. config.ID,0,0)
end
-- Sends my id to the broker for registration
local function register_myself()
m:subscribe(config.ENDPOINT .. config.ID,0,function(conn)
print("Successfully subscribed to data endpoint")
end)
end
local function mqtt_start()
m = mqtt.Client(config.ID, 120)
-- register message callback beforehand
m:on("message", function(conn, topic, data)
if data ~= nil then
print(topic .. ": " .. data)
-- do something, we have received a message
end
end)
-- Connect to broker
m:connect(config.HOST, config.PORT, 0, 1, function(con)
register_myself()
-- And then pings each 1000 milliseconds
tmr.stop(6)
tmr.alarm(6, 1000, 1, send_ping)
end)
end
function module.start()
mqtt_start()
end
return module
-- file : test.lua
app = require("application")
config = require("config")
setup = require("setup")
setup.start()
.......
"ping"또는 "successfully subscribed"와 같이 application.lua에서 문자열의 일부를 볼 수 있지만 아무것도 얻지 못하는 것 같습니다. 그것은 application.lua가 실행되지 않는 것과 같습니다.
도움을 주시면 감사하겠습니다. 미리 감사드립니다.
은 - 마크
업데이트
본인은 연결 객체를 구축하기 전에 직접 문자열을 추가하고 지금 작업 연결 개체에 잠기는 것 같다 있도록 인쇄.
ESP8266/NodeMCU 관련 질문에 대해 투표를 한 사용자에게는 다음과 같은 질문이 있습니다. 질문에 대한 기술을 이해하지 못한다고해서 문제가 해결되었다는 의미는 아닙니다. IoT는 사실이며 NodeMCU & Lua는 주제에 관한 섹션입니다. –