I´m just a beginner with the ESP and LUA-programming, but also in progromming in general, so please excuse in case my questions are too stupid
At the momemt I´m struggeling with the second value/connection i try to set up to write from DS18B20 into the sql database. For 1 value this works perfect, but the second "loop" doesn´t work. Do you have a hint how to do?
Thank you very much in advance!
print("DS18B20 Reading")
function read_temp(sensorPin)
sensor = require("ds18b20")
-- Sensor Initialisation
sensor.setup(sensorPin)
-- read and print temperature
temperatur = sensor.read()
t1 = temperatur/10000
t2 = temperatur % 10000
return temperatur,t1,t2
end
--- read temp and send data to volkszähler
function sendData()
read_temp(4)
read_temp(4)
t3 = t1
t4 = t2
read_temp(5)
read_temp(5)
sensor = nil
ds18b20 = nil
package.loaded["ds18b20"]=nil
print("Temp:"..t3 .. ".".. t4 .." C\n")
print("Temp:"..t1 .. ".".. t2 .." C\n")
-- conection to volkszaehler
print("Sending data to Volkszaehler")
print("First Sensor")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,"192.168.7.76")
conn:send("GET /middleware.php/data/12c56460-6f6e-11e5-a954-efa410011295.json?operation=add&value=".. t3 ..".".. t4 .." HTTP/1.1\r\n")
conn:send("Host: 192.168.7.76\r\n")
conn:send("Connection: keep-alive\r\nAccept: */*\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
---connection to volkszaehler for second sensor
print("Second Sensor")
conn:on("receive", function(conn, payload) print(payload) end)
conn:connect(80,"192.168.7.76")
conn:send("GET /middleware.php/data/2405f8e0-6f6e-11e5-86c4-317c1c0df60c.json?operation=add&value=".. t1 ..".".. t2 .." HTTP/1.1\r\n")
conn:send("Host: 192.168.7.76\r\n")
conn:send("Connection: keep-alive\r\nAccept: */*\r\n")
conn:send("\r\n")
conn:on("sent",function(conn)
print("Closing connection")
conn:close()
end)
conn:on("disconnection", function(conn)
print("Got disconnection...")
end)
end
-- send data every X ms to volkszaehler
tmr.alarm(0, 30000, 1, function() sendData() end )