EasyIoT 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...
This is EasyIoT server beta 7 issue. Sometimes Dimmer control on virtual driver is going in loop and change values. It helps only if you restart server. I will fix that in final release.
Please Log in or Create an account to join the conversation.
ModuleHelper.SetProperty(m.Domain, m.Address, "Sensor.DimmerLevel", (Convert.ToInt32(p.Value)*100).ToString());
EventHelper.SetEvent(m.Domain, m.Address, "Sensor.DimmerLevel");
Please Log in or Create an account to join the conversation.
cdj wrote: Thanks a lot, tomorrow I try everything. But I think that optimal is to have TEMP AND HUM together... Suppose that in automation we can do a GETHUM request or something similar, but how to combine lua? We need two files dht22, one for temp and one for HUM???
Thanks again!
------------------------------------------------------------------------------
-- 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, hum)
-- 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
if hum then
return h
else
return t --, h
end
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","PASSWORD")
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,false,false)
tmr.delay(1000000)
print("read")
myval = (dofile("dht22.lua").read(4,false,false)/10)
print(myval)
conn:send(myval)
elseif string.find(payload,"GETHUM") then
print("Received humidity request")
--print("init")
dofile("dht22.lua").read(4,false,true)
tmr.delay(1000000)
print("read")
myval = (dofile("dht22.lua").read(4,false,true)/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")
const String ESP8266_IP_ADDRESS = "192.168.119.58";
const String NODE_ADDRESS = "N6S0";
/*
This code is running one time when program is enabled
*/
public void Setup()
{
}
/*
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
*/
public void Run()
{
String response = QueryServer("GETHUM");
Console.WriteLine(response);
ModuleHelper.SetProperty("Virtual", NODE_ADDRESS, "Sensor.Humidity", response.ToString());
EventHelper.SetEvent("Virtual", NODE_ADDRESS, "Sensor.Humidity");
}
private static string QueryServer(String message)
{
try
{
Console.WriteLine("TCP client command: " + message + "\r\n");
Int32 port = 43333;
System.Net.Sockets.TcpClient client = new System.Net.Sockets.TcpClient( ESP8266_IP_ADDRESS, port);
Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
System.Net.Sockets.NetworkStream stream = client.GetStream();
stream.Write(data, 0, data.Length);
data = new Byte[256];
String responseData = String.Empty;
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
// Close everything.
stream.Close();
client.Close();
return responseData;
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace + "\r\n");
}
return "0.00";
}
Please Log in or Create an account to join the conversation.
Dennis wrote: Thanks.
With the replaced HA.WebApp.js, the dimmer wheel position is not updated anymore on the other clients (purely graphical problem; dimmer works).
Also, when I call now in automation code
ModuleHelper.SetProperty(m.Domain, m.Address, "Sensor.DimmerLevel", (Convert.ToInt32(p.Value)*100).ToString()); EventHelper.SetEvent(m.Domain, m.Address, "Sensor.DimmerLevel");
Then the wheel positions don't get updated anymore on the other clients (but the displayed numeric value is updated fine everywhere). Is there some helper method to *visually update* a module after setting its properties in code?
regards
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
If I update position, then event to send value is triggered again - this is why sometimes it goes in loop. So I've removed position update. I don't know better method to disable event when value is updated.
Please Log in or Create an account to join the conversation.