need a loop for reading messages for logging  [Solved]

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: need a loop for reading messages for logging  [Solved]

Post by waaren »

pvklink wrote: Sunday 07 July 2019 10:34 i understand the problem with value 1 and 2 now...when only write to domoticz and not to global i dont get something back...
so my local logging function has to split domoticz and global logging in two executing parts...?
Best to change line 56-59 in global_data.lua from

Code: Select all

            for i, record in ipairs(messages) do
                 dz.log(record.log, dz.LOG_INFO)
                 newText = record.text .. lf .. newText
            end
to

Code: Select all

            for i, record in ipairs(messages) do
                if record.log then dz.log(record.log, dz.LOG_INFO) end 
                if record.text then newText = record.text .. lf .. newText end
            end
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: need a loop for reading messages for logging

Post by pvklink »

Yesss, thank you waaren , it works !! finally!

i struggled with:
- if logcode = 1 or logcode = 3 then
- if logcode <> 2 they did not work...

if logcode ~= 2 then WORKED! i thought that ~ can only be used with strings not numeric

Code: Select all

   addMessage = 
        function(dz, item, info, message, messages,logcode)
	        	local trigger  
		if item.isDevice then
				trigger = ", Device: " .. item.name
	        	elseif item.isTimer then
				trigger = ", Timer: " .. item.trigger
		elseif item.isVariable then
				trigger = ", Variable: " .. item.name
	        	else
				trigger = ", Unknown trigger"
		end
		messages[#messages + 1] = {}
		if logcode ~= 2 then
		            messages[#messages].log  = 'scriptname: ' .. info.scriptName .. trigger .. ' ' .. message
		end
		if logcode ~= 1 then
			messages[#messages].text = dz.time.rawDate .. '  ' .. dz.time.rawTime .. ' : ' .. message
			--messages[#messages].text = dz.time.rawDate .. '  ' .. dz.time.rawTime .. ' : ' .. message .. '<br>'
		end
           	return messages
	end,

    dumpMessages = 
        function(dz, messages)
            local textDevice = dz.devices('timerlog')
	    local currentText = dz.globalData.mylogging
            local newText = currentText
	    local lf = '<br>'					--local lf = "\n" 	--local lf = "\r\n"	--PVK \n of \r\n UITGEZET ANDERS werkt dashticz niet
            local maxLines = 8
            
            for i, record in ipairs(messages) do
                if record.log then dz.log(record.log, dz.LOG_INFO) end 
                if record.text then newText = record.text .. lf .. newText end
            end
            
            dz.log(newText, dz.LOG_INFO)
            
            if newText ~= currentText then
                --lines = dz.utils.stringSplit(newText, lf)  -- create lines table from newText string						--PVK UITGEZET ANDERS werkt dashticz niet
                --newText = table.concat(lines, lf, 1, (math.min(maxLines,#lines))) -- recreate newText string from first maxLines 		--PVK UITGEZET ANDERS werkt dashticz niet
                textDevice.updateText(newText) 
		dz.globalData.mylogging = newText  -- ADDED

            end    
        end,    
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest