Discover IR codes for lost remote
-
Thanks, I’ve made a few adjustments based on feedback, and using just one .csv file for now, which it seems to find ok, based on the print output, but it unfortunately doesn’t extract the POWER information?
LuaTest 1.7 Lua file: /etc/cmh-ludl/luatest.lua Results No errors Runtime: 9.9 ms Code returned: nil Print output 7,7.csv Code 1 2 local lfs = require "lfs" 3 local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files 4 local split = "[^,]+,[^,]+,[^,]+,[^,]+,[^,]+" -- (func_name,protocol,D,S,F) 5 6 local prontoCode = '' 7 8 for filename in lfs.dir(dir) do 9 if filename: match "%.csv$" then 10 print(filename) 11 for line in io.lines(dir .. filename) do 12 local func_name,protocol,D,S,F = line: match (split) 13 -- print(line) 14 -- print (line: match (split)) 15 if 'POWER' == func_name:upper() then 16 print ("$protocol $D $S $F", protocol,D,S,F) 17 print (func_name) 18 end 19 end 20 end 21 end
-
My fault. A rookie error in the code (which, obviously, I hadn't tested.)
For your purposes, it's probably good enough to use the search string:
local split = "([^,]+),(%.*)" -- (func_name,protocol,D,S,F)
So this I have tested, and it works.
local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) local prontoCode = '' for filename in lfs.dir(dir) do if filename: match "%.csv$" then print(filename) for line in io.lines(dir .. filename) do local func_name,etc = line: match (split) if 'POWER' == func_name:upper() then print ("$protocol $D $S $F", etc) end end end end
giving this output, for example:
7,7.csv $protocol $D $S $F NECx2,7,7,2
-
Thanks @akbooer
If I’m to use the irptransmogrifier command line interface, I’m going to need to get the format into something like this.
irptransmogrifier render -p -n D=7,S=7,F=2 NECx2
Here is the latest code,
local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) local prontoCode = '' for filename in lfs.dir(dir) do if filename: match "%.csv$" then print(filename) for line in io.lines(dir .. filename) do local func_name,etc = line: match (split) if 'POWER' == func_name:upper() then print ("$protocol $D $S $F", etc) for word in string.gmatch(etc, '([^,]+)') do print(word) end end end end end
Which I’ve tried to update so that the returned values can be seen individually
Print output
7,7.csv
$protocol $D $S $F NECx2,7,7,2
NECx2
7
7
2However I theoretically need them created into individual variables, however I’m not able to get name them ?
This was my attempt, which didn’t work..
local protocol, device, subdevice, function2 = string.match(etc, '(%a+) (%d+) (%d+) (%d+)') print('Protocol = ' .. protocol) print('Device = ' .. device) print('SubDevice = ' .. subdevice) print('Function = ' .. function2)
-
Once you get the variables you need, use this line instead of the above - I left out the "-p"
local command = string.format("%sirptransmogrifier render -p -n D=%s,S=%s,F=%s protocol",irptransmogrifierPath,D,S,F,protocol)
-
Thanks, but that’s ultimate where I’m struggling.
I can’t work out how to take those 4 comma separated values, and make each one identifiable as a separate variable - D,S,F, protocol
This line returns what I need,
print ("$protocol $D $S $F", etc) ,
which tells me the values i need are in etc so any idea why this didn’t work ?
local protocol, D, S, F = string.match(etc, '(%a+) (%d+) (%d+) (%d+)') print('Protocol = ' .. protocol) print('D = ' .. D) print('S = ' .. S) print('F = ' .. F)
-
@parkerc said in Discover IR codes for lost remote:
any idea why this didn’t work ?
...because the syntax is wrong.
I've lost count of the number of times that I may have suggested to you that it might just be worthwhile to learn a little bit more about Lua. The effort that you are putting into this shows that a bit of learning will be a very good investment.
This will split the parameters:
local params = "([^,]+),([^,]+),([^,]+),([^,]+)" local protocol, D,S,F = etc: match(params)
-
parkercreplied to akbooer on Oct 2, 2020, 9:41 PM last edited by parkerc Oct 2, 2020, 5:41 PM
@akbooer said in Discover IR codes for lost remote:
I've lost count of the number of times that I may have suggested to you that it might just be worthwhile to learn a little bit more about Lua.
I know, and believe me when I say. I honestly try to lean aspects of Lua when I can. but - I don’t know if you recall my responses in the past - my job and other commitments leave me so little time to learn anything for any length of time. And when I do find a pocket of time to play, I’m eager to create something new and interesting , and obviously use that as time to learn in the process.
To make it worse, not being a programmer, and not being able to work with LUA on a daily basis, so much of what I learn is sadly lost - through lack of use..
Not meant to be a sob story, just something I have to work with - hence I’m always so grateful for your help and the help of others..
-
parkercreplied to parkerc on Oct 2, 2020, 9:45 PM last edited by parkerc Oct 2, 2020, 5:46 PM
It looks like I finally have the main function in good shape Next on the list is to understand how the IrpTransmogrifier element fits in.
FYI - I’ve added a logging facility to the code, so that I can keep track of the .csv files accessed and the codes sent.
function scanIndexFiles () local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) local prontoCode = '' for filename in lfs.dir(dir) do if filename: match "%.csv$" then print('Filename =' ..filename) for line in io.lines(dir .. filename) do local func_name,etc = line: match (split) local params = "([^,]+),([^,]+),([^,]+),([^,]+)" local protocol, D,S,F = etc: match(params) if 'POWER' == func_name:upper() then -- print ("$protocol $D $S $F", etc) print('Protocol = ' .. protocol) print('D = ' .. D) print('S = ' .. S) print('F = ' .. F) local irptransmogrifierPath = "insert path here" -- this may all need work depending on whatever "irptransmogrifier" does local command = string.format("%sirptransmogrifier render -n D=%s,S=%s,F=%s protocol",irptransmogrifierPath,D,S,F,protocol) print(command) local handle = assert(io.popen(command)) local prontoCode = handle:read("*a") handle:close() print(prontoCode) local time = os.date("%Y-%m-%d %H:%M:%S") local file = io.open("/www/test_write.txt", 'a') file:write(time .. "; " .. filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") file:close() local INTERVAL_SECS = 2 --luup.call_delay('sendProntoCodeToBroadLinkDevice', INTERVAL_SECS, prontoCode) end end end end end
-
Current sticking point is - what do I do about the ‘Java’ requirement for getting IrpTransmogrifier to run on Vera.. Any recommendations?
To help narrow down my options; I’ve also posted this question on the Vera forum to see if anyone installed/used it.. -
Hoping this is the final piece to the puzzle and then we’re hopefully good to go....
JamVM seems the most likely...
-
I’d be really surprised if that fitted. What type of Vera is it?
-
VeraPlus.
The MIPS processor seems to be supported..
-
akbooerreplied to parkerc on Oct 4, 2020, 6:33 PM last edited by akbooer Oct 4, 2020, 2:34 PM
-
parkercreplied to akbooer on Oct 4, 2020, 9:30 PM last edited by parkerc Oct 4, 2020, 5:39 PM
@akbooer said in Discover IR codes for lost remote:
"...a Java VM is out of the question"
Interesting, as when I had read that part, I assumed he was just referring to your normal/standard approach to installing a Java VM on anything, as later in his point (3) he goes on to say ....
- Finding a lightweight Java VM that runs on MIPS. If you Google for "java openwrt" there are a lot of forum postings lamenting the lack of a working JVM for OpenWRT. However, jamvm (an actively maintained lightweight JVM) has had an OpenWRT ipkg right there in the OpenWRT opkg repository for a couple of years.
Goes on in (4) to propose..
opkg install jamvm
Which, considering how Vera is set up, that’s not a package you can install via that route..
root@MiOS_5247999:/tmp/verair# opkg install jamvm Unknown package 'jamvm'. Collected errors: * opkg_install_cmd: Cannot install package jamvm. root@MiOS_ 5247999:/tmp/verair#
It would be good to have everything I need for this all on the same machine; looking at the specification of a VeraPlus, does anyone think it has the resources ?
Spec / Vera Plus
CPU = 880MHz MIPS SoC
Flash Memory = NAND 128MB
Memory = DDR3 256MB -
a-lurkerreplied to parkerc on Oct 5, 2020, 12:12 AM last edited by a-lurker Oct 4, 2020, 8:22 PM
@parkerc said in Discover IR codes for lost remote:
does anyone think it has the resources ?
No.
Forget doing this on a Vera. It would be easier to use, say Windows. Any recent Win machine probably already has the JRE already installed. Just install Lua on the Win machine (refer Google), get the code working (can still use Vera to test the majority of the code) and the call the IR transmitter on Vera with a URL, just like any other function (refer MiOS wiki) can be executed.
The install info for IrpTransmogrifier already has a batch file available ready to run it (refer to IrpTransmogrifier GitHub release and documentation pages). Basically IrpTransmogrifier is a Java program and needs to be executed by something that knows how to do it eg JVE. Just like windows knows how to execute Windows executables.
What does IrpTransmogrifier do? Lots of stuff but in your case it can generate (or as they prefer "render") actual codes, when feed a little bit of information. ie the parameters that define a code in a concise manner - that is: protocol,D,S,F
-
Thanks
Agreed, it doesn't really matter where the ‘processing’ is done, (doing it all on Vera just seemed the easiest) - but I ultimately just need to have a facility where I can search, find and the raise a request (all of which is so far unproven/tested) for the ‘POWER’ IR commands via ...
irptransmogrifier render -p -n D=7,S=7,F=2 NECx2
... and then have it (hopefully) return the command in the pronto code/format I want ....
0000 006C 0000 0022 00AD 00AD 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0041 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 06FB
.. and then once I have it, I just need to get that returned ‘code’ into your Broadlink request..
function sendProntoCodeToBroadLinkDevice(prontoCode) local BROADLINK_DEVICE_ID = 49 luup.call_action('urn:a-lurker-com:serviceId:IrTransmitter1', 'SendProntoCode', {ProntoCode = prontoCode}, BROADLINK_DEVICE_ID) end sendProntoCodeToBroadLinkDevice(prontoCode)
It all seem so do-able when I started.
-
Hi all
The plan on this now is to generates a CSV file, one line per signal, containing the filename, the ‘POWER’ command was found in, its protocol, and the D, S, and F parameters, that I can then import into IrScrutinizer (which is basically IrpTransmogrifier with a GUI), and then export that in the Pronto format .
Currently the following code to create the .csv is not going recursively through all the folders, any advice ?
function scanIndexFiles () local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) local time = os.date("%Y-%m-%d %H:%M:%S") local prontoCode = '' for filename in lfs.dir(dir) do if filename: match "%.csv$" then for line in io.lines(dir .. filename) do local func_name,etc = line: match (split) local params = "([^,]+),([^,]+),([^,]+),([^,]+)" local protocol, D,S,F = etc: match(params) if 'POWER' == func_name:upper() then local file = io.open("/www/powerircodes.txt", 'a') print(filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") file:write(filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") file:close() end end end end end scanIndexFiles()
-
If it’s not easy/desirable to work through the folders using code, I can alway go down through the entire sub- folder hierarchy and bring all the individual .csv files into one single directory.
Update:
Some really good progress has been made using the IrScrutinizer app on a windows PC, as that allows me to do a batch conversion of the raw format i gather , into the desired Pronto code format.
Next challenge:
What is the best export format from IrScrutinizer to use with Lua ? Txt, html, xml,
See all the expert options here.. - http://www.harctoolbox.org/IrScrutinizer.html#The+Export+pane
Once that’s’ s done, the final piece of this grand plan i guess, is to have Vera work through that entire exported list, in order - sending each command, wait for a response, and if nothing is seen after x seconds, move onto the next one..
-
Hi,
If there is anyone still following this -
I’ve got all the .csv files into a single directory now, and everything is pretty much coming together - it’s just that my current issue seems to be with the code that’s extracting the ‘POWER’ line item information.
Based on the following LuaTest output, if I’m interpreting it correctly it needs something to handle any errors found when working through each .csv file. I’ve tired to add an ‘elseif’ but it either just breaks it/or stops.
Please could someone advise how do to get it ignore a file where it has a problem and move on seamlessly to the next one ?
LuaTest 1.7 Lua file: /etc/cmh-ludl/luatest.lua Results Runtime error: Line 14: attempt to index local 'etc' (a nil value) Locals [scanIndexFiles] lfs={ _VERSION="LuaFileSystem 1.6.2", symlinkattributes=function, lock_dir=function, dir=function, _DESCRIPTION="LuaFileSystem is a Lua library developed to complement the set of functions related to file systems offered by the standard Lua distribution", setmode=function, unlock=function, _COPYRIGHT="Copyright (C) 2003-2012 Kepler Project", currentdir=function, touch=function, mkdir=function, lock=function, link=function, attributes=function, chdir=function, rmdir=function } dir="mnt/nas/vera/ircodes/" split="^([^,]+),(.*)" prontoCode="" [main] Print output Filename =26,-1.csv Filename =232,26.csv Filename =88,23.csv Filename =3,1.csv Filename =64,-1.csv Filename =1,222.csv Filename =25,-1.csv Filename =20,-1.csv Filename =64,159.csv Filename =203,67.csv Filename =167,133.csv Filename =192,243.csv Code 1 function scanIndexFiles () 2 local lfs = require "lfs" 3 local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files 4 local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) 5 6 local prontoCode = '' 7 8 for filename in lfs.dir(dir) do 9 if filename: match "%.csv$" then 10 print('Filename =' ..filename) 11 for line in io.lines(dir .. filename) do 12 local func_name,etc = line: match (split) 13 local params = "([^,]+),([^,]+),([^,]+),([^,]+)" 14 local protocol, D,S,F = etc: match(params) 15 if 'POWER' == func_name:upper() then 16 -- print ("$protocol $D $S $F", etc) 17 -- print('Protocol = ' .. protocol) 18 -- print('D = ' .. D) 19 -- print('S = ' .. S) 20 -- print('F = ' .. F) 21 local time = os.date("%Y-%m-%d %H:%M:%S") 22 local file = io.open("/www/powerircodes.txt", 'a') 23 print(filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") 24 file:write(filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") 25 -- file:write(time .. "; " .. filename .. "; " .. protocol .. "; " .. D .. "; " .. S .. "; " .. F .. "\n") 26 file:close() 27 28 end 29 end 30 end 31 end 32 end 33 34 scanIndexFiles()
-
function scanIndexFiles () local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- make this your path to the files local split = "^([^,]+),(.*)" -- (func_name,protocol,D,S,F) local file = io.open "/www/powerircodes.txt" for filename in lfs.dir(dir) do if filename: match "%.csv$" then for line in io.lines(dir .. filename) do local func_name,etc = line: match (split) if etc then local params = "([^,]+),([^,]+),([^,]+),([^,]+)" local protocol, D,S,F = etc: match(params) if 'POWER' == func_name:upper() then local info = table.concat ({filename, protocol, D, S, F}, "; ") print(info) file:write(info .. "\n") end end end end end file:close() end
-
Thanks so much @akbooer
I’ve run it a couple of times now, but it doesn’t seem to write to the file? It prints to the screen ok, but not to the write?
To get around that I’ve just been coping and pasting the print output into a text fileI’m close to the final piece now, I’ve captured and converted all the ‘POWER’ codes listed across all of those .csv files and I’d like to convert them into a table, or .csv, with their associated command name as the variable name, so I can then call them.
Example content of text1.txt (created by IrScrutinizer).
Power 0000 0070 0000 0032 0080 0040 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0030 0010 0010 0010 0010 0010 0030 0010 0010 0010 0030 0010 0030 0010 0010 0010 0030 0010 0030 0010 0030 0010 0ACD Power$1 0000 006C 0022 0002 015B 00AD 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0016 0016 0016 0016 0041 0016 0016 0016 0016 0016 0016 0016 0041 0016 0016 0016 0041 0016 0041 0016 0016 0016 0041 0016 0041 0016 0041 0016 05F7 015B 0057 0016 0E6C Power$2 0000 0068 0000 0022 0169 00B4 0017 0044 0017 0044 0017 0017 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0044 0017 0017 0017 0044 0017 0017 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0017 0017 0044 0017 0044 0017 0017 0017 0017 0017 0044 0017 0044 0017 0017 0017 0636
And I’m now trying to get that above into a more usable format, such a Lua array/table or maybe another .csv. Below is th3 code I’ve been working on to do that, but i’m not having much success doing the conversion.
function convertCodestoarray (filename) local lfs = require "lfs" local dir = "mnt/nas/vera/ircodes/" -- the path to the files print(dir .. filename) for filename in lfs.dir(dir) do if filename: match "%.txt$" then for line in io.lines(dir .. filename) do local params = "([^,]+)/n([^,]+)" local codename, prontocode = params local params = table.concat ({codename, prontocode}, ", ") print(params) for filename in lfs.dir(dir) do local file = io.open("powerircodes.csv", 'a') filename:write(params .. "\n") end end filename:close() end end end convertCodestoarray("text1.txt")
30/49