QuinLED via ESP Easy?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

QuinLED via ESP Easy?

#1 Post by mkotek » 18 Jan 2016, 22:01

Has anyone tried to recreate Quindor's QuinLED dimmer via ESP Eaysy?
If you do not know Quindor's excellent and small solution, please check at:
http://blog.quindorian.org/2015/04/esp8 ... x.html?m=1.

I have working modules, but I do not like lua scripts on my modules and I find them hard to maintain, so would be interested in recreation of the idea using ESP Easy. I have purchased the PCBs, so I am not eager to drop the desing and build something different, although I plan to join ESP-12F to Quindor's module.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

cherowley
Normal user
Posts: 125
Joined: 14 Jan 2016, 09:39

Re: QuinLED via ESP Easy?

#2 Post by cherowley » 19 Jan 2016, 16:23

Hi!

What software will you be using to control the modules? Domoticz?

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: QuinLED via ESP Easy?

#3 Post by mkotek » 19 Jan 2016, 18:42

cherowley wrote:Hi!
What software will you be using to control the modules? Domoticz?
Yes, that is what I am doing now with original scripts.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

superczar
New user
Posts: 2
Joined: 21 Jan 2016, 08:12

Re: QuinLED via ESP Easy?

#4 Post by superczar » 21 Jan 2016, 16:23

+1 to that
I too would be very interested in seeing this
Having discrete lua scripts for specific tasks is quite a clunky method IMO

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: QuinLED via ESP Easy?

#5 Post by mkotek » 21 Jan 2016, 16:46

Glad to hear, I am not the only one looking for simplicity.
We could possibly move the logic of driving PWM on specific bebaviour in Domoticz to tasks as specificplugin, because logic stays constant - all that is being sent to ESP is change in PWM pulse depending on the Dimmer setting in controller. Everything else is already in place. And of course having as great firmware as EASY ESP (now with OTA) across house is a plus.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

cherowley
Normal user
Posts: 125
Joined: 14 Jan 2016, 09:39

Re: QuinLED via ESP Easy?

#6 Post by cherowley » 21 Jan 2016, 17:11

How about setting up a virtual dimmer switch in domoticz called "Dimmer Strip Test" then using a lua script?

Something like this:

commandArray = {};
IP = '192.168.2.161';
Port = '80';
GPIO = 4;

DomDevice = 'Dimmer Strip Test'
print("ESPEasy Dimmer Strip Test Script")

function send(msg)
runcommand = "echo "..msg .."| telnet "..IP.." "..Port.." "
print (runcommand)
os.execute(runcommand)
end

if devicechanged[DomDevice] then
if(devicechanged[DomDevice]=='Off') then
print("Turning OFF" .. DomDevice)
send("control?cmd=PWM," .. tostring(GPIO) .. ",0")
elseif (devicechanged[DomDevice]=='On') then
print("Turning On with value : " .. tostring(uservariables['HoldDimmer1']))
otherdevices_svalues[DomDevice] = tostring(uservariables['HoldDimmer1'])
send("control?cmd=PWM," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables['HoldDimmer1']*32)))
else
print("Value sent from domoticz is : " .. otherdevices_svalues[DomDevice])
uservariables['HoldDimmer1'] = otherdevices_svalues[DomDevice]
send("control?cmd=PWM," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables['HoldDimmer1']*32)))
commandArray['Variable:HoldDimmer1'] = uservariables['HoldDimmer1']
end
end;
return commandArray

You'll have to create an user variable called "HoldDimmer1" via the ui as domoticz virtual dimmer is bugged in not sending value when on is clicked.

Also I have NOT tested this code as at work so doubt the telnet sending the control?cmd etc will work - prob have to change to doing a proper http thing...

Assumes ip of esp chip is 192.168.2.161 and led is hooked up to gpio 4....

I don't think you can get the pwm level from espeasy so no way to check actual live value on esp chip?

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: QuinLED via ESP Easy?

#7 Post by mkotek » 21 Jan 2016, 19:16

Interesting idea. It might work as what you have written is adaptation of Quindor's script for EASY ESP. What I meant initially was moving the handling of the dimmer command onto plugin in tasks and getting rid of LUE script on controller as well, but your idea is also nice and does not require anything else on EASY ESP side.
Thank you, will test soon.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: QuinLED via ESP Easy?

#8 Post by mkotek » 25 Jan 2016, 00:43

I have modified the script slightly, so it returns the result, if the ESP is active and sends via curl not telnet:

Code: Select all

commandArray = {}

DomDevice = 'Dimmer Strip Test'
IP = 'espip'
Port = '80'
GPIO = 4

function os.capture(cmd, raw)
  local f = assert(io.popen(cmd, 'r'))
  local s = assert(f:read('*a'))
  f:close()
  if raw then return s end
  s = string.gsub(s, '^%s+', '')
  s = string.gsub(s, '%s+$', '')
  s = string.gsub(s, '[\n\r]+', ' ')
  return s
end

function send(msg) 
	runcommand = "curl http://"..(IP)..":"..(Port).."/"..(msg)..""
	print (runcommand)
	print(os.capture(runcommand))
end

if devicechanged[DomDevice] then
	print("ESPEasy Dimmer Strip Test Script")

	if(devicechanged[DomDevice]=='Off') then 
		print("Turning OFF " .. DomDevice)
		send("control?cmd=PWM," .. tostring(GPIO) .. ",0") 
	elseif (devicechanged[DomDevice]=='On') then
		print("Turning On with value : " .. tostring(uservariables['HoldDimmer1']))
		otherdevices_svalues[DomDevice] = tostring(uservariables['HoldDimmer1'])
		send("control?cmd=PWM," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables['HoldDimmer1']*32)))
else
	print("Value sent from domoticz is : " .. otherdevices_svalues[DomDevice])
	uservariables['HoldDimmer1'] = otherdevices_svalues[DomDevice]
	send("control?cmd=PWM," .. tostring(GPIO) .. "," .. tostring(tostring(uservariables['HoldDimmer1']*32)))
	commandArray['Variable:HoldDimmer1'] = uservariables['HoldDimmer1']
	end
end

return commandArray
Other than that, I have not amended the script - it should be working and giving the correct results with Easy ESP.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

Quindor
New user
Posts: 4
Joined: 22 Jan 2016, 16:54

Re: QuinLED via ESP Easy?

#9 Post by Quindor » 26 Jan 2016, 01:02

Hi, Quindor himself here!

It would be awesome if ESP Easy could incorporate PWM dimming with smooth fading in combination with Domoticz! That would make my, ahum, very amateuristic code obsolete! It's my first time coding anything real, ever. :P

Anyway, I looked into before myself and from what I have been able to read is that Arduino for ESP8266 does not have access to the hardware timers (currently) and thus cannot do a reliable flicker-free PWM at 1000Hz on several GPIO's like NodeMCU can. After that I kind of game up on it because for any reliable PWM with WiFi on, a hardware timer is needed.

I've used ESP Easy myself for some sensors and other stuff though. Works great! :D

Quindor
New user
Posts: 4
Joined: 22 Jan 2016, 16:54

Re: QuinLED via ESP Easy?

#10 Post by Quindor » 26 Jan 2016, 01:13

Hi, Quindor himself here!

Awesome to see my dimmer boards being used. Soon I will be releasing board revision 2.5 which has some slight improvements!

I would love to see the same functionality as I built using NodeMCU in ESP Easy. This was my first attempt at coding anything really and well, I know it's quite amateuristic! :mrgreen:

Sadly, from what I have read is that ESP Easy uses Arduino for ESP8266. And that using that IDE you don't have access to the internal hardware timers of the ESP8266 itself, like NodeMCU has. There have been experiments but it's struggles to keep up with 200Hz SoftPWM let alone being able to handle multiple 1000Hz PWM outputs like the hardware timer can. Compounded on that fact is that if you wish to use the module for PWM and have a WiFi connection without a hardware timer, each time you use the WiFi or it receives packages it influences the software timer and produces flickering in the connected lights.

So SoftPWM is a no go, even for one output. Hopefully the Arduino IDE for ESP8266 will get access to the hardware timer and then it would be easy to port the functionality. It would benefit a lot of people looking for a cheap and easy LED dimmer with settable smooth fading between values! My code works flawlessly, but it can certainly be done better. ;)

I've used ESP Easy for other sensors and stuff myself and it's made me abandon the programming effort I was putting into that completely, so keep up the great work! :D

mkotek
Normal user
Posts: 116
Joined: 15 Dec 2015, 10:58
Location: Lomianki, Poland
Contact:

Re: QuinLED via ESP Easy?

#11 Post by mkotek » 26 Jan 2016, 07:25

Welcome Quindor.
As you know, I simply love your dimmer and the lua code. Being able to easily replace ESP inside, however, beat any specialized coding, that is why I have been looking for solution using Easy ESP. Hearing the bad part about refresh makes me sad, but maybe the community can come up with the soluton, the way Martinus came up with OTA that was seemingly unavailable for core 2.0.0.

Let's not abandon hope then :) In the meantime, I am happily using your modules combined with Domoticz and my alarm system's PIRs to light them up on the stairs for example and it is absolutely reliable in such scenario, so not such a big deal. It is all about easy replacement though and I have had some issues with quick programming of NodeMCU, contrary to my Easy ESP experience.
Michal 'Kotek', greetings from Poland. Zapraszam na mój blog o automatyce domowej po polsku: http://www.ukotka.com.

cherowley
Normal user
Posts: 125
Joined: 14 Jan 2016, 09:39

Re: QuinLED via ESP Easy?

#12 Post by cherowley » 26 Jan 2016, 16:52

Hi mkotek,

Ah ha! Synology does in fact have curl! This may be very useful and allow sending 0's and 255's from the command line! (Synology doesn't have netcat)

Cheers!

Quindor
New user
Posts: 4
Joined: 22 Jan 2016, 16:54

Re: QuinLED via ESP Easy?

#13 Post by Quindor » 26 Jan 2016, 21:11

Ah, yes, I agree the current situation could be much improved if it could be integrated into ESP Easy. What I built works and it's reliable, but efficient in setting up and a nice web interface such as ESP Easy, not really. ;)

Hopefully they can get the hardware timers working in Arduino for ESP. It's easy after that. :)

cherowley
Normal user
Posts: 125
Joined: 14 Jan 2016, 09:39

Re: QuinLED via ESP Easy?

#14 Post by cherowley » 28 Jan 2016, 11:58

Not sure about hardware pwm but I'm experimenting with adding a PWMFADE command. Simply PWMFADE,GPIO,TARGETLEVEL

This is for R048

Quindor
New user
Posts: 4
Joined: 22 Jan 2016, 16:54

Re: QuinLED via ESP Easy?

#15 Post by Quindor » 28 Jan 2016, 12:58

cherowley wrote:Not sure about hardware pwm but I'm experimenting with adding a PWMFADE command. Simply PWMFADE,GPIO,TARGETLEVEL

This is for R048
Sounds good! Although I'm wondering how useful it's going to be (at least for LED lighting) without a 100% stable PWM signal at a very high frequency (Like 1000Hz). Testing is always good though!

Aside from giving the command, which GPIO pin to this new level. Will you also be able to give a value how long the fade should take and have it auto-calculate how many steps it needs to take and how fast? That's one of the things I did with my code so some lamps would fade up in 1 second but others take 9 seconds for a new slow effect. :)

When it's integrated I'll be sure to test it!

cherowley
Normal user
Posts: 125
Joined: 14 Jan 2016, 09:39

Re: QuinLED via ESP Easy?

#16 Post by cherowley » 02 Feb 2016, 10:51

I've modded some of the source code and have fading working, after a fashion.

It's not that smooth due to having a linear fade and also just being in the main loop.
No error checking either as not bothered going beyond rough alpha coding due to poor performance.

I have edited _p001_Switch.ino, WebServer.ino and ESPeasy.ino in R048.

Added:

PWMFADE, pin, target, time in seconds

RGB, redpin, redlevel, bluepin, bluelevel, greenpin, greenlevel (this is fixed time of 1 second but can take longer due to just being in main loop again)

Ah well, was worth a try - I'm sure a proper coder could make this work lol.

Was thinking it would be worth adding code to write the gpio levels to flash and retrieving them on boot too?

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests