Please Log in or Create an account to join the conversation.
Dennis wrote: First of all, nice to hear you got it working.
Regarding "christmas": do you have easyIoT open on more than one device?
If I have easyIoT opened on smartphone and pc at the same time, and change dimmer value, it sometimes goes crazy with the LEDs for me too. But the node itself is not the problem, it is more like if easyIoT is going into some kind of race condition, and values start changing rapidly and endlessly in the easyIoT console. It will never recover by itself from this state. If I restart easyIoT server, everythings fine again...
Yes V0.7b2 running on Raspberry B+As long as I just open easyIoT one one device, everything is fine. I think this is a bug in easyIoT, since automation is strictly triggered by events, which happen on server only (at least this is my understanding). If I trigger an event on one client by changing dimmer value, it should change the GUI of other clients to display the changed value, but no other events *should* be triggered subsequently from other clients because of GUI changes!
But obviously, something changes the modules values from more than one location (read: from the clients), which induces said "loop frenzy" or christmas behavior when >1 client ist connected to easyIoT server.
Which easyIoT build are you using, 0.7b2 beta? And running on windows or raspberry?
Ok perfect...The LUA script does not recognize anything - it just receives commands for gpio0 or 2 over wifi, and executes them. No matter what you connect to the gpio.
Ok or we can use more than 1 module !!!And yes, DHT11/22 and also BMP180 should work too, I'm waiting for shipments from china so I can develop something in this direction!
See here whats possible with nodeMCU's stock LUA modules:
github.com/nodemcu/nodemcu-firmware/tree/master/lua_modules
But, if we connect two sensors, then we have no more gpio's left for dimming and switching... so I just ordered some bigger ESP modules with more (hopefully all?) gpio's broken out, for testing. We'll see.
The lua DHT11 script is a good find! I've found something similar for ds18b20 here: vaasa.hacklab.fi/2015/01/12/esp8266-ds18b20-thingspeak-nodemcu/
Seems like nodeMCU community is growing quickly.
regards
Please Log in or Create an account to join the conversation.
------------------------------------------------------------------------------
-- DHT11/22 query module
--
-- LICENCE: http://opensource.org/licenses/MIT
-- Vladimir Dronnikov <dronnikov@gmail.com>
--
-- Example:
-- print("DHT11", dofile("dht22.lua").read(4))
-- print("DHT22", dofile("dht22.lua").read(4, true))
-- NB: the very first read sometimes fails
------------------------------------------------------------------------------
local M
do
-- cache
local gpio = gpio
local val = gpio.read
local waitus = tmr.delay
--
local read = function(pin, dht22)
-- wait for pin value
local w = function(v)
local c = 255
while c > 0 and val(pin) ~= v do c = c - 1 end
return c
end
-- NB: we preallocate incoming data buffer
-- or precise timing in reader gets broken
local b = { 0, 0, 0, 0, 0 }
-- kick the device
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
gpio.write(pin, 1)
waitus(10)
gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, 0)
waitus(20000)
gpio.write(pin, 1)
gpio.mode(pin, gpio.INPUT, gpio.PULLUP)
-- wait for device presense
if w(0) == 0 or w(1) == 0 or w(0) == 0 then
return nil, 0
end
-- receive 5 octets of data, msb first
for i = 1, 5 do
local x = 0
for j = 1, 8 do
x = x + x
if w(1) == 0 then return nil, 1 end
-- 70us for 1, 27 us for 0
waitus(30)
if val(pin) == 1 then
x = x + 1
if w(0) == 0 then return nil, 2 end
end
end
b[i] = x
end
-- check crc. NB: calculating in receiver loop breaks timings
local crc = 0
for i = 1, 4 do
crc = (crc + b[i]) % 256
end
if crc ~= b[5] then return nil, 3 end
-- convert
local t, h
-- DHT22: values in tenths of unit, temperature can be negative
if dht22 then
h = (b[1] * 256 + b[2])
t = (b[3] * 256 + b[4])
if t > 0x8000 then t = -(t - 0x8000) end
-- DHT11: no negative temperatures, only integers
-- NB: return in 0.1 Celsius
else
h = (10 * b[1])
t = (10 * b[3])
end
return t
end
-- expose interface
M = {
read = read,
}
end
return M
--
--print("init")
--dofile("dht22.lua").read(4)
--tmr.delay(1000000)
--print("read")
--myval = dofile("dht22.lua").read(4)
--print(myval)
--
pwm.setup(3, 1000, 000)
pwm.start(3)
LED1_current=000
LED1_target=000
SWITCH1_state = 0
Fadetime1=1000
Stepcounter1=0
PosStepcounter1=0
DimTimer1=0
wifi.setmode(wifi.STATION)
wifi.sta.config("SSID","PASS")
srv=net.createServer(net.TCP)
srv:listen(43333,function(conn)
conn:on("receive",function(conn,payload)
print("Input: "..payload)
if string.find(payload,"GETTEMP") then
print("Received temperature request")
--print("init")
dofile("dht22.lua").read(4)
tmr.delay(1000000)
print("read")
myval = (dofile("dht22.lua").read(4)/10)
print(myval)
conn:send(myval)
elseif string.find(payload,"SWITCH1") then
SWITCH1_state=tonumber(string.sub(payload, 9) )
print("Received SWITCH1 target Value: "..SWITCH1_state)
if SWITCH1_state == 1 then
pwm.setduty(3, 1023)
LED1_current = 1023
elseif SWITCH1_state == 0 then
pwm.setduty(3, 0)
LED1_current = 0
end
elseif string.find(payload,"LED1") then
LED1_target=tonumber(string.sub(payload, 13) )
print("Received LED1 Target Value: "..LED1_target)
Stepcounter1=(LED1_target)-(LED1_current)
if (Stepcounter1) < 0 then
PosStepcounter1=(Stepcounter1)*-1
else PosStepcounter1=(Stepcounter1)
end
if (PosStepcounter1) == 0 then
PosStepcounter1=(PosStepcounter1)+1
else PosStepcounter1=(PosStepcounter1)
end
DimTimer1=(Fadetime1)/(PosStepcounter1)
if (DimTimer1) == 0 then
DimTimer1=(DimTimer1)+1
else DimTimer1=(DimTimer1)
end
print (Fadetime1)
print (Stepcounter1)
print (PosStepcounter1)
print (DimTimer1)
print (LED1_current)
print (LED1_target)
tmr.alarm(0, (DimTimer1), 1, function()
if LED1_current < LED1_target then
LED1_current = (LED1_current + 1)
pwm.setduty(3, LED1_current)
elseif LED1_current > LED1_target then
LED1_current = (LED1_current - 1)
pwm.setduty(3, LED1_current)
elseif LED1_current == LED1_target then tmr.stop(0)
end end )
end
end)
end)
print ("easyIoT dimmer/switch/temperature sensor for nodeMCU")
print ("Based on QuinLED_ESP8266_V0.4")
Please Log in or Create an account to join the conversation.
2) firmware start and restart in loop (need to reflash module)
obviously tested with 0.9.4 and 0.9.5....
Please Log in or Create an account to join the conversation.
First of all, nice to hear you got it working.
Regarding "christmas": do you have easyIoT open on more than one device?
If I have easyIoT opened on smartphone and pc at the same time, and change dimmer value, it sometimes goes crazy with the LEDs for me too. But the node itself is not the problem, it is more like if easyIoT is going into some kind of race condition, and values start changing rapidly and endlessly in the easyIoT console. It will never recover by itself from this state. If I restart easyIoT server, everythings fine again...
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.