This commit is contained in:
Татьяна Фарбер 2026-03-09 14:13:34 +04:00
parent a7a2dcbc7a
commit f9d39e533e
2 changed files with 43 additions and 52 deletions

View File

@ -1,5 +1,9 @@
# Бродильная камера на ESP 8266 # Бродильная камера на ESP 8266
# Формат передачи данных
## Необходимые детали ## Необходимые детали
1. Wemos D1 Mini 1. Wemos D1 Mini

View File

@ -1,70 +1,69 @@
timing = 5000 -- Sending timer local t = require("DS1820")
timing = 60000 -- Sending timer
srv = nil -- TCP client srv = nil -- TCP client
uid = '' -- MAC UID uid = '' -- MAC UID
dhtpin = 1 -- DHT11 pin dhtpin_room = 1 -- DHT11 room pin
sda, scl = 3, 4 -- BME280 pins dhtpin_cellar = 2 -- DHT11 cellar pin
alt = 320 -- altitude of the measurement place dhtpin_weather = 5 -- DHT11 weather pin
ds_pin = 6
local results = {} -- DS1822 results
-- Weather vars -- Weather vars
T = - 300 -- BME temp TB_room = - 300 -- DHT temp
P = - 300 -- BME pressure TH_room = - 300 -- DHT humidity
curAlt = - 300 -- BME altitude TB_cellar = - 300 -- DHT temp
TB = - 300 -- DHT temp TH_cellar = - 300 -- DHT humidity
TH = - 300 -- DHT humidity TB_weather = - 300 -- DHT temp
UF = 0 -- UF index TH_weather = - 300 -- DHT humidity
-- Read the solar sensor -- Read DS1822
function adc_read() local function readout(temp)
UF = adc.read(0) for addr, temp in pairs(temp) do
print('UF index: '..UF) local uid = string.format('%s',('%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X'):format(addr:byte(1,8)))
results[uid] = temp
print(uid,temp)
end
end end
-- Read the BME280 sensor local function read_sensors()
t:read_temp(readout, ds_pin, t.C)
function bme_read()
T, P, H, QNH = bme280.read(alt)
local Tsgn = (T < 0 and -1 or 1); T = Tsgn*T
print(string.format("T=%s%d.%02d", Tsgn<0 and "-" or "", T/100, T%100))
print(string.format("QFE=%d.%03d", P/1000, P%1000))
print(string.format("QNH=%d.%03d", QNH/1000, QNH%1000))
P = bme280.baro()
curAlt = bme280.altitude(P, QNH)
local curAltsgn = (curAlt < 0 and -1 or 1); curAlt = curAltsgn*curAlt
print(string.format("altitude=%s%d.%02d", curAltsgn<0 and "-" or "", curAlt/100, curAlt%100))
end end
-- Read the DHT11 sensor -- Read the DHT11 sensor
function dht_read() local function dht_read(dhtpin)
status, temp, humi, temp_dec, humi_dec = dht.read(dhtpin) local status, temp, humi, temp_dec, humi_dec = dht.read(dhtpin)
if status == dht.OK then if status == dht.OK then
TB = temp
TH = humi
print("DHT Temperature:"..temp..";".."Humidity:"..humi) print("DHT Temperature:"..temp..";".."Humidity:"..humi)
return {['temp'] = temp, ['humi'] = humi}
elseif status == dht.ERROR_CHECKSUM then elseif status == dht.ERROR_CHECKSUM then
print( "DHT Checksum error." ) print( "DHT Checksum error." )
elseif status == dht.ERROR_TIMEOUT then elseif status == dht.ERROR_TIMEOUT then
print( "DHT timed out." ) print( "DHT timed out." )
end end
return {}
end end
-- Prepare data for TCP server -- Data for TCP server
function data_out() function data_out()
read_sensors()
local pack = {} local pack = {}
pack['id'] = uid pack['id'] = uid
pack['bme'] = {['temp'] = T,['press'] = P,['alt'] = curAlt} pack['room'] = dht_read(dhtpin_room)
pack['dht'] = {['temp'] = TB,['humi'] = TH} pack['cellar'] = dht_read(dhtpin_cellar)
pack['uf'] = UF pack['weather'] = dht_read(dhtpin_weather)
pack['sensors'] = results
return encoder.toBase64(sjson.encode(pack)) return encoder.toBase64(sjson.encode(pack))
end end
-- Exchange data with server -- Exchange data with server
function tcp() local function send()
srv:connect(4999,"braga.ulgrad.ru") srv:connect(4999,"chan.ulgrad.ru")
srv:on("connection", function(sck, c) srv:on("connection", function(sck, c)
print('connection') print('connection')
sck:send(data_out().."\r\n") sck:send(data_out().."\r\n")
@ -100,30 +99,18 @@ function on_connect()
end end
end end
-- Setup ADC
if adc.force_init_mode(adc.INIT_ADC)
then
node.restart()
return -- don't bother continuing, the restart is scheduled
end
-- Setup sensors -- Setup sensors
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
bme280.setup() bme280.setup()
-- Setup timers -- Setup timers
tcptimer = tmr.create() tcptimer = tmr.create()
tcptimer:register(12000, tmr.ALARM_AUTO,tcp) tcptimer:register(timing, tmr.ALARM_AUTO,send)
inittimer = tmr.create() inittimer = tmr.create()
inittimer:register(5000, tmr.ALARM_SINGLE, function() inittimer:register(5000, tmr.ALARM_SINGLE, function()
adc_read() enduser_setup.start('chan',on_connect)
bme_read()
dht_read()
enduser_setup.start('meteo',on_connect)
end) end)
inittimer:start() inittimer:start()