Seems like it is working a treat.
Sending Data to emoncms.
http://emoncms.org/rmtucker
Explore... Chat... Share...
-- Measure wind speed and post data to thingspeak.com
-- by William H. McClintic
cnt=0
rp=0
pin=4
du=0
st=0
ws=0
gpio.mode(pin,gpio.INPUT)
function onStart()
if cnt == 0 then st=tmr.now()
end
rp=gpio.read(pin)
--print(rp)
cnt=cnt+1
if cnt == 10 then et=tmr.now()
du=et-st
ws=(60-(du/30000))
ws=ws/2
if ws<1 then ws=0
end
print("Wind Speed mph is "..ws)
cnt=0
du=0
st=0
et=0
end
end
gpio.mode(pin,gpio.INT)
gpio.trig(pin, 'down', onStart)
--- Get wind speed and send data to thingspeak.com
function sendData()
-- conection to thingspeak.com
print("Sending data to thingspeak.com")
conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload) print(payload) end)
-- api.thingspeak.com 184.106.153.149
conn:connect(80,'184.106.153.149')
conn:send("GET /update?key=YOURAPIKEYHERE&field1="..(ws).." HTTP/1.1\r\n")
conn:send("Host: api.thingspeak.com\r\n")
conn:send("Accept: */*\r\n")
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\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 thing speak 10,000 = 10 seconds
tmr.alarm(0, 60000, 1, function() sendData() end
)--init.lua
print("Setting up WIFI...")
wifi.setmode(wifi.STATION)
--modify according your wireless router settings
wifi.sta.config("YOURSSID","YOURPASSWORD")
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip()== nil then
print("IP unavaiable, Waiting...")
else
tmr.stop(1)
print("Config done, IP is "..wifi.sta.getip())
dofile("SendWind.lua")
end
end)
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[…]