I have Tasker on an android phone. I want Vera to be able to send something to the android phone to have it execute a task. Tasker cannot listen on a socket. But, it can monitor for file changes and then execute a task when the file is changed. I can install an FTP server on the phone. What I want to do is create a virtual switch called “Police Scanner”, a scene for when it turns on, and then when the LUUP code for it uploads a file called ScannerOn.tmp, Tasker will see the changed modification date and execute a task that starts Scanner Radio playing my local police scanner stream. And I’ll have another one for shutting it off.
If I do something like “put /dev/null /sdcard/TaskerFiles/ScannerOn.tmp”, it will create (or modify) a 0 byte file called ScannerOn.tmp.
Unless someone can think of another way to have Vera send data over the network to the android phone that I can use to execute tasks. I want to do this on the local network, I do not want to rely on an internet connection for this to work like some of the Android “notify” programs require.
What does the “f, e” do? I grabbed this code from a LUA forum.
I ran this through the test LUA code thing, and it said “command failed”. But, it created the file on the android phone and put that text in it. So it works.
The only problem is, the “File Modified” event on Tasker is not triggering for me at all. I’ve added different text thinking that maybe it was actually looking at content instead of timestamp, and it still doesn’t work. I’ve also tried the “File Opened” event and that doesn’t trigger either. Very strange. I also tried putting in the full path to the file using /mnt/sdcard/vera/ScannerOn.tmp, and that didn’t help either.
Ah ha! Uploading a new file every time didn’t fire the Tasker event because it was deleting the old file first. I used the FTP append command and added to an existing file, and that works:
[code]local ftp = require(“socket.ftp”)
local ltn12 = require(“ltn12”)
f, e = ftp.put{
host = “10.32.32.50”,
port = “2121”,
user = “vera”,
password = “password”,
command = “appe”,
argument = “ScannerOn.tmp”,
source = ltn12.source.string(“z”)
}
return f
[/code]
Interesting stuff, following on the FTP theme and the code you have written, do you know what the code would be to take either a file or multiple files or a folder) from Vera and put it on a CIFS share on a NAS?
Unless im mistaken, this has potential to be used as a scheduled back up Scene?
CIFS is complicated. A lot more than FTP. If you are looking for a scheduled backup of Vera to a NAS, you could do what I do and use rsync. Installing rsync on Vera is just a matter of installing the package (opkg install rsync). Installing rsync on the NAS is probably easy (Synology has a homebrew package). Then use cron to schedule it.
Does your NAS have ssh and rsync on it? I would not code this with LUUP. I would just write a cronjob and have the underlying OS on Vera do it that way. If you do it with LUUP, you have to write something that will recursively go through all of your directories and upload each file.
Vera has a built in backup function also, and it should be doing autobackups daily to cp.mios.com right now. You can also pull down an already packaged backup from the Setup->Backup page.
Creating your own backup mechanism is likely going to present problems when restoring. Why not just use the packaged stuff?
Thanks again, I wanted to avoid using SSH or doing anything which involved me playing around on the ‘inside’ of Vera, so I was hoping there was a straight forward bit of code that would allow me to back something up via a LUA in a scene. But It sounds like it’s not as straight forward as it seemed from your piece of code up above…