LED Dimmer using curl cmd in LUA script - problem with os.execute?

Moderators: grovkillen, Stuntteam, TD-er

Message
Author
robatbentley
Normal user
Posts: 69
Joined: 18 Mar 2017, 22:13
Location: Newcastle/UK

LED Dimmer using curl cmd in LUA script - problem with os.execute?

#1 Post by robatbentley » 29 Mar 2018, 15:23

I've been trying to implement an LED dimmer (based on post https://www.domoticz.com/forum/viewtopi ... 90#p176190) using a Domoticz switch, ESPEasy (12E) and a LUA script. The problem is that the LUA script builds a command but doesn't seem to be executing it successfully. i.e. My scope, attached to pin GPI04 doesn't "see" any change in the PWM. However, when using a command window with "curl http://192.168.1.154/control?cmd=PWM,4,300" the PWM changes according to the request.

I thing my Domoticz and ESPEasy are working okay but the execution part (i.e. the os.execute?) the LUA script isn't working. i.e. Just can't get the curl command to execute.
I'm no coder and not really sure how else to debug this, but the curl command (with parameters) looks okay. i.e. curl 'http://192.168.1.154/control?cmd=PWM,4,30'. I'm just not sure where single or double quote are required in the curl command when dumped into os.execute.

I've also tried placing the raw curl command into the os.execute but still didn't change the PWM settings on my scope.
...and Wireshark shows messages when using Windwos cmd window (see attached wireshark capture) but shows nothing when using the Domotics LUA script.
I've spent a couple of days on this now and just run out of ideas as to how to fix it. Any help appreciated.
Thanks

My setup is...

* Windows 10 (64 bit)
* The LUA script is in file called script_device_PWM_LED_switch.lua
* Domoticz installed a service, and restarted it a number of times
* The Domoticz switch name is called PWM_LED_switch
* Using GPI04 (D2) for PWM
* curl installed in system path
* ...and set system and user path variables to point to c:\curl\bin\

Using following LUA code...

Code: Select all

-- LED dimmer script script using ESPEasy
commandArray = {}
DomDevice = 'PWM_LED_switch';
IP = '192.168.1.154';
PIN = "4";
if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then
		print ("OFF dim = "..uservariables['dimmer']);
		CalcValue = 0;
   	else if(devicechanged[DomDevice]=='On') then
   		DomValue = uservariables['dimmer'];
        print ("ON dim = "..uservariables['dimmer']);
        CalcValue = DomValue;
    else
    	print("Other");
        DomValue = otherdevices_svalues[DomDevice];
        CalcValue = math.floor(DomValue / 100 * 1023);
        commandArray['Variable:dimmer'] = tostring(CalcValue);
        print ("dim Level = "..uservariables['dimmer']);
   	end
   	end
   	runcommand = "curl 'http://" .. IP .. "/control?cmd=PWM,"  ..PIN.. "," .. CalcValue .. "'";
   	os.execute(runcommand);
	print("PWM value= "..CalcValue);
	print("runcommand value= "..runcommand);
end
return commandArray
Domoticz log, just after changing the domoticz dimmer switch settings, looks like...

Code: Select all

2018-03-29 14:13:20.088 MQTT: Topic: domoticz/in, Message: {"idx":4,"nvalue":0,"svalue":"18.8;41.2;1;995.5;5"} 
2018-03-29 14:13:24.209 User: Admin initiated a switch command (7/PWM_LED_switch/Set Level) 
2018-03-29 14:13:24.433 (Dummy) Lighting 5 (PWM_LED_switch) 
2018-03-29 14:13:24.436 LUA: Other 
2018-03-29 14:13:24.436 LUA: dim Level = 317 
2018-03-29 14:13:24.445 LUA: PWM value= 30 
2018-03-29 14:13:24.445 LUA: runcommand value= curl 'http://192.168.1.154/control?cmd=PWM,4,30' 
2018-03-29 14:13:24.506 EventSystem: Script event triggered: C:\Program Files (x86)\Domoticz\scripts\lua\script_device_PWM_LED_switch.lua 
2018-03-29 14:13:26.887 EventSystem: Event triggered: SetDayTypeWeekDay_1 
2018-03-29 14:13:26.887 Started DayType check 
2018-03-29 14:13:26.974 DayType set to 5 (Weekday) 
2018-03-29 14:13:29.125 Set UserVariable GotDayType = 0 
You do not have the required permissions to view the files attached to this post.
RobUpNorth

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], opensiteexplorer.org/dotbot [bot] and 20 guests