diff --git a/init.lua b/init.lua index 4e84667..95e4efb 100644 --- a/init.lua +++ b/init.lua @@ -1,11 +1,11 @@ -local t = require("DS1820") -timing = 60000 -- Sending timer -srv = nil -- TCP client -uid = '' -- MAC UID -dhtpin_room = 1 -- DHT11 room pin -dhtpin_cellar = 2 -- DHT11 cellar pin -dhtpin_weather = 5 -- DHT11 weather pin -ds_pin = 6 +local t = require("ds18b20") +local timing = 60000 -- Sending timer +local srv = nil -- TCP client +local uid = '' -- MAC UID +local dhtpin_room = 1 -- DHT11 room pin +local dhtpin_cellar = 2 -- DHT11 cellar pin +local dhtpin_weather = 5 -- DHT11 weather pin +local ds_pin = 6 local results = {} -- DS1822 results @@ -64,44 +64,39 @@ local function send() end) end --- On Internet connect - -function on_connect() - -- Generate UID from MAC address - uid = string.gsub(wifi.ap.getmac(),':','') - print("Connected to wifi as: " .. wifi.sta.getip()) - ssid,password,bssid_set,bssid = wifi.sta.getconfig() - sensor_start() - print( - "\nCurrent Station configuration:" - .."\nSSID : "..ssid - .."\nPassword : "..password - .."\nBSSID_set : "..bssid_set - .."\nBSSID: "..bssid - .."\nUID:"..uid - .."\nClient IP:"..wifi.sta.getip().."\n" - ) - srv = net.createConnection(net.TCP, 0) - if srv then - print('TCP Connection start') - tcptimer:start() - else - print('Error connect to TCP') +local function connect_wifi() + if wifi.sta.getip() == nil then + print("Connect to Wi-fi.") + else + print("Success") + print("IP: " .. wifi.sta.getip()) + wifitimer:stop() + uid = string.gsub(wifi.ap.getmac(),':','') + srv = net.createConnection(net.TCP, 0) + if srv then + print('TCP Connection start') + tcptimer:start() + else + print('Error connect to TCP') + end end end --- Setup sensors +wifi.setmode(wifi.STATION) -bme280.setup() +station_cfg = {} +station_cfg.ssid = "ASUS" +station_cfg.pwd = "0" +station_cfg.save = true + +wifi.sta.config(station_cfg) -- Setup timers tcptimer = tmr.create() tcptimer:register(timing, tmr.ALARM_AUTO,send) - -inittimer = tmr.create() -inittimer:register(5000, tmr.ALARM_SINGLE, function() - enduser_setup.start('chan',on_connect) -end) -inittimer:start() +wifitimer = tmr.create() +wifitimer:register(1000, tmr.ALARM_AUTO,connect_wifi) + +wifitimer:start() diff --git a/nodemcu-release-11-modules-2026-03-12-15-31-50-integer.bin b/nodemcu-release-11-modules-2026-03-12-15-31-50-integer.bin new file mode 100644 index 0000000..e550c85 Binary files /dev/null and b/nodemcu-release-11-modules-2026-03-12-15-31-50-integer.bin differ diff --git a/tests/client.lua b/tests/client.lua index bf5b094..8ea343e 100644 --- a/tests/client.lua +++ b/tests/client.lua @@ -8,12 +8,14 @@ tcp:connect(host, port); local pack = {} pack['id'] = 'test' -pack['room'] = {['temp'] = 12,['humi'] = 67} -pack['cellar'] = {['temp'] = 14,['humi'] = 77} -pack['weather'] = {['temp'] = 0,['humi'] = 57} +pack['room'] = {['temp'] = 12,['warm'] = 67} +pack['cellar'] = {['temp'] = 14,['warm'] = 77} +pack['weather'] = {['temp'] = 0,['warm'] = 57} pack['sensors'] = {['28:61:64:34:80:10:F4:39'] = 18,['28:61:64:35:18:1E:74:EB'] = 17,['28:61:64:35:18:3C:3D:61'] = 19} ---tcp:send(base64.encode(json.encode(pack))) +print(base64.encode(json.encode(pack))) + +tcp:send(base64.encode(json.encode(pack))) tcp:send('test')