I would use the adc input of my ESP-07 but I do not know how to program, if someone just help me ?
Thank you
Explore... Chat... Share...
-- On appelle le fichier ds18b20 uploadé plus tôt
require('ds18b20')
gpio0 = adc.read(0) -- Le gpio sur lequel est connecté la patte donnée du ds18b20
server_ip = "192.168.0.101" -- L'ip du serveur Jeedom
server_port = 80 -- Le port sur lequel vous voulez que votre serveur web écoute
api_key = "ZRN0DiluYXCLg4JZmUDHH6F9Z9Zt"
id_capteur = "11" -- A remplacer par votre id
-- Creation d'une fonction qui va récupérer la température
function gettemp(gpio)
pin = gpio
ds18b20.setup(pin)
t1=ds18b20.read()
return t1
end
-- Creation d'une fonction qui va préparer la requete a envoyer à Jeedom pour mettre notre capteur virtuel à jour.
function build_post_request(path, key, valueValue)
payload = key .. "=" .. tostring(valueValue)
return "POST " .. path .. " HTTP/1.1\r\n" ..
"Host: " .. server_ip .. "\r\n" ..
"Connection: close\r\n" ..
"Content-Type: application/x-www-form-urlencoded\r\n" ..
"Content-Length: " .. string.len(payload) .. "\r\n" ..
"\r\n" .. payload
end
-- Création de la fonction qui envoit la requête à Jeedom
function send_temperature(valueValue)
temp=gettemp(gpio0)
block = true
sk = net.createConnection(net.TCP, 0)
sk:on("connection", function(sck)
request = build_post_request("http://192.168.0.101/core/api/jeeApi.php?apikey=ZRN0DiluYXCLg4JZmUDHH6F9Z9Zt&type=httpRemoteEvent&eqId=11&value=valueValue" )
sk:send(request, function()
sk:close()
block = false
end)
end)
sk:connect(server_port, server_ip)
end
-- Configuration du serveur web
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
-- On décompose les url reçu et on place chaque bout dans des variables.
conn:on("receive", function(client,request)
local buf = "";
temp=gettemp(gpio0)
-- On définit l'aspect graphique de la page, le code HTML
buf = buf.."<p>Il fait "..temp.." °C.";
-- Cloture de la session
client:send(buf);
client:close();
collectgarbage();
end)
end)
-- On définit une boucle qui execute la fonction send_temperature(temp) toutes les minutes (60s)
tmr.alarm(0, 60000, 1, function() send_temperature(temp) end )
--------------------------------------------------------------------------------
-- DS18B20 one wire module for NODEMCU
-- NODEMCU TEAM
-- LICENCE: http://opensource.org/licenses/MIT
-- Vowstar <vowstar@nodemcu.com>
-- 2015/02/14 sza2 <sza2trash@gmail.com> Fix for negative values
--------------------------------------------------------------------------------
-- Set module name as parameter of require
local modname = ...
local M = {}
_G[modname] = M
--------------------------------------------------------------------------------
-- Local used variables
--------------------------------------------------------------------------------
-- DS18B20 dq pin
local pin = nil
-- DS18B20 default pin
local defaultPin = 9
--------------------------------------------------------------------------------
-- Local used modules
--------------------------------------------------------------------------------
-- Table module
local table = table
-- String module
local string = string
-- One wire module
local ow = ow
-- Timer module
local tmr = tmr
-- Limited to local environment
setfenv(1,M)
--------------------------------------------------------------------------------
-- Implementation
--------------------------------------------------------------------------------
C = 0
F = 1
K = 2
function setup(dq)
pin = dq
if(pin == nil) then
pin = defaultPin
end
ow.setup(pin)
end
function addrs()
setup(pin)
tbl = {}
ow.reset_search(pin)
repeat
addr = ow.search(pin)
if(addr ~= nil) then
table.insert(tbl, addr)
end
tmr.wdclr()
until (addr == nil)
ow.reset_search(pin)
return tbl
end
function readNumber(addr, unit)
result = nil
setup(pin)
flag = false
if(addr == nil) then
ow.reset_search(pin)
count = 0
repeat
count = count + 1
addr = ow.search(pin)
tmr.wdclr()
until((addr ~= nil) or (count > 100))
ow.reset_search(pin)
end
if(addr == nil) then
return result
end
crc = ow.crc8(string.sub(addr,1,7))
if (crc == addr:byte(8)) then
if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then
-- print("Device is a DS18S20 family device.")
ow.reset(pin)
ow.select(pin, addr)
ow.write(pin, 0x44, 1)
-- tmr.delay(1000000)
present = ow.reset(pin)
ow.select(pin, addr)
ow.write(pin,0xBE,1)
-- print("P="..present)
data = nil
data = string.char(ow.read(pin))
for i = 1, 8 do
data = data .. string.char(ow.read(pin))
end
-- print(data:byte(1,9))
crc = ow.crc8(string.sub(data,1,8))
-- print("CRC="..crc)
if (crc == data:byte(9)) then
t = (data:byte(1) + data:byte(2) * 256)
if (t > 32767) then
t = t - 65536
end
if(unit == nil or unit == C) then
t = t * 625
elseif(unit == F) then
t = t * 1125 + 320000
elseif(unit == K) then
t = t * 625 + 2731500
else
return nil
end
t = t / 10000
-- print("Temperature="..t1.."."..t2.." Centigrade")
-- result = t1.."."..t2
return t
end
tmr.wdclr()
else
-- print("Device family is not recognized.")
end
else
-- print("CRC is not valid!")
end
return result
end
function read(addr, unit)
t = readNumber(addr, unit)
if (t == nil) then
return nil
else
return t
end
end
-- Return module table
return M
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]