Bien refactorisé mon projet mesure température. Cela ne fonctionne pas encore :-(
This commit is contained in:
32
Temp_DS18B20/temp_zf/0_get_temp.lua
Normal file
32
Temp_DS18B20/temp_zf/0_get_temp.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
-- Lit le capteur de température solaire en fonction de son field qui se trouve dans les secrets !
|
||||
print("\n 0_get_temp.lua zf190617.1252 \n")
|
||||
|
||||
-- lecture: https://thingspeak.com/channels/802784/private_show
|
||||
-- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/
|
||||
|
||||
local ow_pin = 3
|
||||
ds18b20.setup(ow_pin)
|
||||
|
||||
function get_temp()
|
||||
ds18b20.read(
|
||||
function(ind,rom,res,temp,tdec,par)
|
||||
print(ind, temp, zfield)
|
||||
if zfield == 1 then
|
||||
ztemp1 = temp
|
||||
elseif zfield == 2 then
|
||||
ztemp2 = temp
|
||||
elseif zfield == 3 then
|
||||
ztemp3 = temp
|
||||
zurl=hub_url.."field3="..tostring(ztemp3)
|
||||
send_temp()
|
||||
end
|
||||
print(ztemp1, ztemp2, ztemp3)
|
||||
end,{})
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
get_temp()
|
||||
|
||||
]]
|
||||
|
||||
25
Temp_DS18B20/temp_zf/0_send_temp.lua
Normal file
25
Temp_DS18B20/temp_zf/0_send_temp.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
-- Petit script pour envoyer les valeurs de température sur un serveur WEB via un HTTP GET
|
||||
print("\n 0_send_temp.lua zf190727.1331 \n")
|
||||
|
||||
function send_temp()
|
||||
print("send_web_temp: ")
|
||||
print(zurl)
|
||||
|
||||
http.get(zurl, nil, function(code, data)
|
||||
-- print("toto")
|
||||
if (code < 0) then
|
||||
print("HTTP request failed")
|
||||
print("zuzu", code, data)
|
||||
else
|
||||
print(code, data)
|
||||
end
|
||||
-- print("tutu")
|
||||
end)
|
||||
-- print("titi")
|
||||
end
|
||||
|
||||
--[[
|
||||
|
||||
send_temp()
|
||||
|
||||
]]
|
||||
@@ -1,35 +0,0 @@
|
||||
-- Petit script pour envoyer les valeurs de température sur un serveur WEB via un HTTP GET
|
||||
print("\n send_web_temp.lua zf190726.1931 \n")
|
||||
|
||||
function send_temp(zserver)
|
||||
print("send_web_temp: ")
|
||||
|
||||
ztemp1=11 ztemp2=12 ztemp3=13
|
||||
|
||||
zurl=zserver.."field1="..tostring(ztemp1).."&field2="..tostring(ztemp2).."&field3="..tostring(ztemp3)
|
||||
print(zurl)
|
||||
|
||||
--[[
|
||||
http.get(zurl, nil, function(code, data)
|
||||
print("toto")
|
||||
if (code < 0) then
|
||||
print("tutu")
|
||||
print("HTTP request failed")
|
||||
print("zuzu", code, data)
|
||||
else
|
||||
print("titi")
|
||||
print(code, data)
|
||||
end
|
||||
end)
|
||||
]]
|
||||
|
||||
end
|
||||
|
||||
--disp_send()
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
send_temp(concentrator_url)
|
||||
|
||||
]]
|
||||
@@ -1,43 +0,0 @@
|
||||
-- programme pour faire un test depuis de le webide
|
||||
|
||||
function a2()
|
||||
print("\n a2.lua zf190617.1128 \n")
|
||||
|
||||
end
|
||||
|
||||
a2()
|
||||
|
||||
-- Lit les capteurs de température solaire et envoie les mesures sur ThingSpeak
|
||||
-- zf190617.1134
|
||||
|
||||
-- lecture: https://thingspeak.com/channels/802784/private_show
|
||||
|
||||
-- source: https://nodemcu.readthedocs.io/en/master/modules/ds18b20/
|
||||
|
||||
|
||||
local ow_pin = 3
|
||||
ds18b20.setup(ow_pin)
|
||||
|
||||
print("toto182538")
|
||||
|
||||
ztemp1=0 ztemp2=0 ztemp3=0
|
||||
|
||||
-- read all sensors and print all measurement results
|
||||
ds18b20.read(
|
||||
function(ind,rom,res,temp,tdec,par)
|
||||
-- print(ind,string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")),res,temp,tdec,par)
|
||||
print(ind,temp)
|
||||
if ind == 1 then
|
||||
ztemp1 = temp
|
||||
-- elseif ind == 2 then
|
||||
-- ztemp2 = temp
|
||||
-- elseif ind == 3 then
|
||||
-- ztemp3 = temp
|
||||
--C'est la fin de lecture, on envoie les mesures à ThingSpeak
|
||||
print(ztemp1,ztemp2,ztemp3)
|
||||
disp_send()
|
||||
end
|
||||
end,{})
|
||||
|
||||
print("tutu152603")
|
||||
|
||||
@@ -7,12 +7,18 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>API HUB Temp 190727.0948</h1>
|
||||
<h1>API HUB Temp 190727.1321</h1>
|
||||
<br>
|
||||
|
||||
<%
|
||||
--ztemp1 = 0 ztemp2 = 0 ztemp3 = 0
|
||||
|
||||
if (vars ~= nil) then
|
||||
zout("<br>vars: "..vars.."<br>")
|
||||
for k, v in string.gmatch(vars, "(%w+)=(%w+%p+%w+)&*") do
|
||||
_GET[k] = v
|
||||
zout(k..": "..v.."<br>")
|
||||
end
|
||||
end
|
||||
|
||||
if (_GET.field1 ~= nil) then
|
||||
ztemp1 = _GET.field1
|
||||
zout("<br>temp1: "..ztemp1.."°C")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
-- Scripts à charger après le boot pour démarrer son appli
|
||||
|
||||
print("\n boot.lua zf190727.0902 \n")
|
||||
print("\n boot.lua zf190727.1329 \n")
|
||||
|
||||
function heartbeat()
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
@@ -26,12 +26,8 @@ f= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f= "a3.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "a4.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
--f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "a_no_linear.lua" if file.exists(f) then dofile(f) end
|
||||
f= "0_get_temp.lua" if file.exists(f) then dofile(f) end
|
||||
f= "0_send_temp.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f=nil
|
||||
--heartbeat=nil
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf181119.0014 \n")
|
||||
print("\n wifi_info.lua zf190727.1220 \n")
|
||||
|
||||
local zmodewifi=wifi.getmode()
|
||||
|
||||
@@ -10,10 +10,11 @@ if zmodewifi == wifi.NULLMODE then
|
||||
elseif zmodewifi == wifi.STATION then
|
||||
print("WIFI mode CLI")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
do
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
|
||||
end
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
elseif zmodewifi == wifi.SOFTAP then
|
||||
print("WIFI mode AP")
|
||||
print("AP MAC:\n",wifi.ap.getmac())
|
||||
@@ -22,10 +23,11 @@ elseif zmodewifi == wifi.SOFTAP then
|
||||
elseif zmodewifi == wifi.STATIONAP then
|
||||
print("WIFI mode CLI+AP")
|
||||
print("Connected IP:\n",wifi.sta.getip())
|
||||
do
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false")))
|
||||
end
|
||||
print("AP MAC: "..wifi.ap.getmac())
|
||||
print("AP IP: "..wifi.ap.getip())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
print("AP MAC: ", wifi.ap.getmac())
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user