tag:blogger.com,1999:blog-21101880198878060572024-03-07T23:49:28.783-08:00A More Common HadesAndroid and LinuxJMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comBlogger80125tag:blogger.com,1999:blog-2110188019887806057.post-25165686479083130422012-05-28T06:37:00.007-07:002012-05-28T22:07:13.205-07:00The granddaddy of weather geek tasksI had mentioned earlier that I was working on a large Tasker project, and here it is. This is a mobile version of the Storm Prediction Center's <a href="http://www.spc.noaa.gov/exper/mesoanalysis/new/mobile.php">Mesoanalysis</a> site. It consists of 110 different weather maps and models, all of which are available for 10 different regions of the United States.<br /><br /><span style="font-style:italic;">Again, I must warn you, the intented audience for this is... me! <span style="font-weight:bold;">This was created for my Galaxy Nexus with a 4.65 inch 1280×720 resolution screen size.</span> It will certainly look terrible on a smaller phone. The Tasker scenes will be too large for the screen and the weather maps will probably be too small to be useful. On something larger such as a tablet, it will be too small but resizing the one scene named "Meso" should make it work great.</span><br /><br />The way it works is pretty simple. The main interface is a scene named <span style="font-style:italic;">MesoMenu1</span>. I've included a task named <span style="font-style:italic;">MesoStart</span> which will display the menu, or you can make one on your own. The task can be called from a shortcut/widget on your home screen or from any other method you might call a Tasker task.<br /><br />This is the main interface, <span style="font-style:italic;">MesoMenu1</span>. From here you will want to first set your region so the weather maps are centered on your area. There is one blank area where you may want to add another bit of text to launch something else, like the <a href="http://a-more-common-hades.blogspot.com/2012/04/convective-outlook-tasker-projects-for.html">Convective Outlook</a> project, for example.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/-GKSf5Mou0rY/T8N_lz5vCII/AAAAAAAAAXo/xJGP-5Ads5s/s1600/Screenshot_2012-05-28-09-34-37.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://4.bp.blogspot.com/-GKSf5Mou0rY/T8N_lz5vCII/AAAAAAAAAXo/xJGP-5Ads5s/s400/Screenshot_2012-05-28-09-34-37.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5747577837019138178" /></a><br /><br />This is the region select screen. The region is stored in a global variable %SECTOR so it should never need to be changed, but can be changed from this menu at any time. Once you select a region, a map will pop up showing you the area you chose.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-AS7VDrAqXwk/T8N_uW7vDnI/AAAAAAAAAX0/dUY6iy-aAMo/s1600/Screenshot_2012-05-28-09-34-56.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://2.bp.blogspot.com/-AS7VDrAqXwk/T8N_uW7vDnI/AAAAAAAAAX0/dUY6iy-aAMo/s400/Screenshot_2012-05-28-09-34-56.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5747577983861722738" /></a><br /><br />This is an example of selecting <span style="font-style:italic;">Wind Shear</span> from the main menu. You are presented with all the same choices that you'd see on the SPC's website. Some menus have a lot of maps and some only have a few. This one happens to have a lot.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-hpArS0IVw9U/T8N_0baKDoI/AAAAAAAAAYA/vJsCGd6fc9M/s1600/Screenshot_2012-05-28-09-35-12.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://1.bp.blogspot.com/-hpArS0IVw9U/T8N_0baKDoI/AAAAAAAAAYA/vJsCGd6fc9M/s400/Screenshot_2012-05-28-09-35-12.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5747578088142278274" /></a><br /><br />Once you select one, 850 & 500 mb Winds in this case, a map will be displayed. Closing it will take you back to the last menu.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-NbuHzTZoRls/T8N_5speNAI/AAAAAAAAAYM/sF61jYnI8Rg/s1600/Screenshot_2012-05-28-09-35-38.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://2.bp.blogspot.com/-NbuHzTZoRls/T8N_5speNAI/AAAAAAAAAYM/sF61jYnI8Rg/s400/Screenshot_2012-05-28-09-35-38.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5747578178669261826" /></a><br /><br />Here is the <a href="http://www.mediafire.com/file/uu9abvac3wu5qkg/Meso.prj.xml">download link</a>. Download to your sdcard then import into Tasker. Enjoy.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-8015554932643408002012-05-20T19:56:00.002-07:002012-05-20T19:59:03.553-07:00Oops, Convective Outlook bug fixedOops, the Tasker project in my <a href="http://a-more-common-hades.blogspot.com/2012/04/convective-outlook-tasker-projects-for.html">last post</a> had a bug with the images. I had selected the wrong image to display somewhere along the line. It's fixed now and I went ahead and added the day 4-8 outlook as well.<br /><br /><a href="http://www.mediafire.com/file/568kdr81pgal52e/Outlook.prj.xml">here</a>JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-89460445460666421652012-04-29T12:56:00.011-07:002012-05-20T20:00:46.269-07:00Convective Outlook Tasker projects for weather geeks<span style="font-style:italic;">(this had a bug which I fixed, the download link is updated with the fixed version. I also added day 4-8 to the project.)</span><br /><br />I've been playing with Tasker scenes and made a couple useful weather related scenes for the weather geeks, but unfortunately one of them isn't ready yet. It works great, but I decided to add a legend to help define some of the options and it's turning into a pain. I would skip the legend now but I already have it halfway done and it would take more work to take it out than to finish it.<br /><br />I also have another one that is turning into a larger project than I wanted. It's not overly complicated, but it's going to require over 100 selectable menu items and that is a lot of boring grunt work, but it will be great for weather geeks when I'm done.<br /><br />So, here is a simple one, a mobile version of the Storm Prediction Center's <a href="http://www.spc.noaa.gov/products/outlook/">Convective Outlook</a> for days 1, 2 and 3. 4-8 would be easy to add, but I don't really use it so I left it out. <br /><br />The whole thing is pretty simple, the menu allows you to choose the outlook for Day 1, 2 or 3. <br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-L4cWreuBofg/T7RyMrmwVOI/AAAAAAAAAXM/XONSg3TkNhI/s1600/Screenshot_2012-05-16-23-33-40.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://1.bp.blogspot.com/-L4cWreuBofg/T7RyMrmwVOI/AAAAAAAAAXM/XONSg3TkNhI/s400/Screenshot_2012-05-16-23-33-40.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5743340986993497314" /></a><br /><br />Once you choose, it downloads the image and text for that day and displays it. The text is scrollable and contains all the text from the related SPC outlook page.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-Qohon5NVDms/T7RyUHDu2MI/AAAAAAAAAXY/Yn0o6X9wXSs/s1600/Screenshot_2012-05-16-23-34-31.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://1.bp.blogspot.com/-Qohon5NVDms/T7RyUHDu2MI/AAAAAAAAAXY/Yn0o6X9wXSs/s400/Screenshot_2012-05-16-23-34-31.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5743341114621876418" /></a><br /><br />Tapping on the text or the image will take you back to the previous menu where you can select another day if you want.<br /><br />It consist of two scenes and two tasks. The task named "Start Outlook" is an optional way to start the scene. It simply displays Outlook1 (the menu from the first image above). You can skip that task and display Outlook1 with another method if you prefer.<br /><br /><span style="font-style:italic;">This project was created on my phone, a Galaxy Nexus, with a 4.65", 1280×720 resolution screen. It might not be useable on a smaller phone, and will probably require resizing for any phone with a different screen size.<span style="font-weight:bold;"></span></span><br /><br />I've put this up for download <a href="http://www.mediafire.com/file/568kdr81pgal52e/Outlook.prj.xml">here</a>. If that site displays the text from the xml, you can click download to save it to your computer or phone. Once downloaded, simply import into Tasker and enjoy.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-86316939703345918952012-02-01T19:35:00.001-08:002012-02-01T20:18:20.606-08:00Tasker scenesIf you haven't been playing with Tasker's new Scene feature, you really need to. I had read about them in the Tasker changelog but didn't have time to test them out and didn't really know what they were until I sat down a couple of days ago and made one. I guess a good way to explain them is that they are like a cross between popup dialogues and Zoom widgets. They are, of course, completely customizable. <br /><br />Here is my first one. It may not be pretty but it's useful:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-1vBnVlLJfiA/TyoFNnecmwI/AAAAAAAAAWY/4EB3aR3IVb0/s1600/02.01.2012-22%253A37.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 225px; height: 400px;" src="http://3.bp.blogspot.com/-1vBnVlLJfiA/TyoFNnecmwI/AAAAAAAAAWY/4EB3aR3IVb0/s400/02.01.2012-22%253A37.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5704377609511279362" /></a><br /><br />They can be triggered through a Tasker widget or shortcut or with a Zoom widget. My entire screen is actually an invisible 4x5 Zoom widget. The top row is blank at the moment except for the asterisk, which actually toggles wifi on and off and changes the color of the asterisk from orange to a nearly invisible gray to indicate it's on/off state. The next two rows, when tapped, execute a Tasker task which displays the scene.<br /><br />The scene has several short text blocks that trigger various Tasker tasks, some text, a play/pause button that controls playback of the podcast app BeyondPod and a close button to make the scene go away. I'm sure I'll do a lot of reconfiguring, but it puts a lot of my often used controls in a pop-up.<br /><br />Scenes can be changed with Tasker much like Zoom widgets. For example, the green arrow controls audio play/pause for the podcast app BeyondPod and changes icons depending on it's state, the blocks of text on the right and left are updated by a certain task that runs every 30 minutes, and tapping some of the short texts trigger tasks which begin with a color change to green and return to gray at the end of the task to give visual feedback that they are running. Some of the tasks which I don't need visual feedback for just close the scene. And when I'm not using it, I can look at a nice clean wallpaper.<br /><br />In case you're curious, the bottom two rows of my home screen, when tapped, lock the screen and can also display images or text. For example, I have a task to grab a weather image, display it for 10 seconds on the bottom part of the Zoom widget, then go back to showing nothing.<br /><br />All in all, scenes are a powerful new feature. They may be confusing at first, but if you've used Zoom you will find them very familiar and easy to learn.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-35366812377085366592012-01-22T11:07:00.000-08:002012-01-22T11:28:44.635-08:00ssh problem with Locale Execute PluginI recently found ssh commands to be flaky when running them with the Locale Execute Plugin for Tasker. A check of the log showed a couple interesting lines:<br /><br />D/LocaleExecute( 7130): stderr: ssh: Warning: Reading the random source seems to have blocked.<br />D/LocaleExecute( 7130): stderr: If you experience problems, you probably need to find a better entropy source.<br /><br />/dev/random is a random number generator that keeps a pool of random bits for use in cryptography, but it uses computer activity to generate them and if the computer isn't active enough, it will block the sending of random bits until it gets some more.<br /><br />/dev/urandom is more foolproof in operation because, when it runs out of random bits from computer activity, it generates some more on it's own, but if an attacker knew the algorithms used by urandom, they could in theory use that to hack anything replying on urandom as an entropy source. But as the man pages say "<span style="font-style:italic;">Knowledge of how to do this is not available in the current unclassified literature, but it is theoretically possible that such an attack may exist. If this is a concern in your application, use /dev/random instead.</span>"<br /><br />Unless you think the NSA is trying to crask the ssh link between your phone and computer, it should be safe to link /dev/random to /dev/urandom.<br /><br /><span style="font-style:italic;">cd /dev<br />mv random random.bak<br />ln -s urandom random</span><br /><br />I don't know why this problem only manifested itself when ssh was ran with the Locale Execute Plugin. I assume when ran from a terminal, the terminal app was creating enough noise for the kernel to keep the entropy pool filled or something.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-34074194854343334672012-01-19T20:45:00.000-08:002012-01-20T16:10:02.309-08:00Pulling Sender and Subject from Gmail part 2I'm not a database guy. I've used sqlite3 several times on Android to pull information out of db files, but I usually just dump everything and filter it with tools I'm familiar with and never sat down and tried to learn much about it until tonight. What I learned was just enough basics to make a database admin say "Aww, that's cute... he's twying to wearn something" but it's already useful.<br /><br />My problem was that I had never actually viewed a db file before. I had dumped them and looked at the output and wondered why there was no way to identify and extract a certain column. It wasn't until I actually tapped on a file and opened it to see that the columns were indeed named and sought out a way to utilize that.<br /><br />It's actually so simple I could kick myself for not looking sooner. I was toying with pulling data from the gmail file again and found that you can pull data from other columns and limit the output to only show one record (like head -1), but that gives you the oldest record at the top of the file. Turns out, the first column in the gmail file it named _id and it's just line numbers, and you can sort the output by the _id column in reverse order and grab that top line to get the newest. It's as simple as "ORDER BY _id DESC LIMIT 1"<br /><br />Anyway, I came up with a cleaner way to grab the sender, sender's email address and the subject from the most recent email, or all three together like I had previously posted. This script will do all four.<br /><br />Here is what it looks like. I just signed up for an account at RootzWiki, so that's my most recent email.<pre># mailsender email<br />staff@rootzwiki.com<br /># mailsender name<br />RootzWiki<br /># mailsender subject<br />New Registration at RootzWiki<br /># mailsender<br />"RootzWiki" <staff@rootzwiki.com> New Registration at RootzWiki<br />#</pre>Using this, it's easy to trigger a Tasker action based on any of those criteria.<br /><br />First you set up an event profile based on a ui notification owned by gmail, and use it to trigger a task like this:<br /><br />1- using the Locale Execute Plugin, execute one of the commands and redirect it to a file<br />2- wait 1 second (usually a good idea with commands like this)<br />3- read line 1 from the output file to %var<br />4- Do something if %var matches whatever<br /><br />The email address is probably the best thing to match, but you could also use it to for a name or a certain subject, just adjust the command accordingly.<br /><br />All you need to do is replace YOURNAME with your google login name on the second like because the database file is named after your gmail name.<pre>#! /system/bin/sh<br /><br />yourmail="YOURNAME@gmail.com"<br /><br />dir="/data/data/com.google.android.gm/databases/"<br />case "$1" in<br /><br />name)<br />sqlite3 ${dir}mailstore.${yourmail}.db "select fromAddress from messages ORDER BY _id DESC LIMIT 1" | grep -o '"[^"]*"' | tr -d \";;<br /><br />email)<br />sqlite3 ${dir}mailstore.${yourmail}.db "select fromAddress from messages ORDER BY _id DESC LIMIT 1" | grep -o \<.*\> | tr -d '<>';;<br /><br />subject)<br />sqlite3 ${dir}mailstore.${yourmail}.db "select subject from messages ORDER BY _id DESC LIMIT 1";;<br /><br />*)<br />sqlite3 ${dir}mailstore.${yourmail}.db "select * from messages ORDER BY _id DESC LIMIT 1" | awk '/@/{FS="|";print $4,$11}';;<br /><br />esac<br /></pre>If you want to play around, you can also extract a preview to the email, or even the entire body with these sqlite3 commands:<br /><br />"select snippet from messages"<br />"select body from messages"<br /><br />I think I'm done playing with it, but your gmail messages are completely accessible from the command line on Android. Might be useful for something.<br /><br /><span style="font-style:italic;">Edit: Jan 20. Here's a QR code to copy the script to your phone's clipboard.</span><br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/-dDapCXlHqWU/Txn-yrtZvKI/AAAAAAAAAWM/-Ix8NHNmaMA/s1600/mailsender.png"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 291px; height: 291px;" src="http://3.bp.blogspot.com/-dDapCXlHqWU/Txn-yrtZvKI/AAAAAAAAAWM/-Ix8NHNmaMA/s400/mailsender.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5699866950094142626" /></a>JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-2183977179750968602012-01-18T19:56:00.000-08:002012-01-18T20:25:43.218-08:00Screenshot commandThis command will take a screenshot on Android ICS: <br /><br /><span style="font-style:italic;">/system/bin/screencap -p /sdcard/FILENAME.png</span><br /><br />You might want to make the filename be the date and time:<br /><br /><span style="font-style:italic;">/sdcard/$(date +%m.%d.%Y-%H:%M).png</span><br /><br />I found that in /system/bin/bugmailer.sh, a script to send bug reports. The p option and calling it a png file both seem to have the same result, but if you leave both off, it ends up as a data file that nothing will open. It seems redundant but for safety's sake, I'll follow their example of both using -p and naming it a png. Unfortunately, there are no other options.<br /><br />It's a neat trick. With Tasker, I can trigger a screenshot and <a href="http://a-more-common-hades.blogspot.com/2010/07/various-linuxphone-ssh-transfer.html">scp</a> that sucker right to my computer automatically.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-21668917276484406712012-01-17T19:39:00.000-08:002012-01-17T20:14:52.496-08:00Pulling sender and subject from GmailThis came up on the Tasker group today. Someone wanted a way to get the sender and/or subject from Gmail to have Tasker keep beeping until they read an email from an important person. Or something like that.<br /><br />The Android Gmail client doesn't have an API to allow you to get any information about a new email. But we're root and we don't care about that API business.<br /><br />In the directory <span style="font-style:italic;">/data/data/com.google.android.gm/databases</span> is a file named <span style="font-style:italic;">mailstore.YOURNAME@gmail.com.db</span>. Breaking out the trusty sqlite3, we find that the sender and subject is contained in the 4th and 11th fields of the <span style="font-style:italic;">messages</span> table and we can extract that by dumping the table...<br /><pre>sqlite3 mailstore.YOURNAME@gmail.com.db "select * from messages"</pre>...and filtering it with awk.<br /><pre>awk '/@/{FS="|";print $4,$11}' | tail -n1</pre>The last line seems to be the most recent email. For some reason I can't get awk to grab the last line on my phone, so I had to use tail.<br /><br />That is what I posted on the Tasker group but that was a test and it needs tweaked. It is essentially grepping all the lines containing "@" then printing the 4th and 11th fields. I tried that first because you can get some gibberish in those messages, and I wanted to grab the lines with email addresses and that was a quick way, but the receiver's (your) email address is on the same line as the information we want so it would be a lot safer to grab lines containing your email address instead of the general "@" symbol.<br /><pre>awk '/YOURNAME@gmail.com/{FS="|";print $4,$11}' | tail -n1</pre>The end result is something like <span style="font-style:italic;">"John" <john_doe@isp.net> Re: blah blah</span><br /><br />Instead of posting a huge long line that makes my blog look funny, I'll put it all together like this:<br /><pre>#! /system/bin/sh<br />email=YOURNAME@gmail.com<br />file=/data/data/com.google.android.gm/databases/mailstore.${email}.db <br />sqlite3 ${file} "select * from messages" | awk '/@/{FS="|";print $4,$11}' | tail -n1</pre>I didn't actually test it, but Tasker can listen for notifications which belong to any apps including Gmail. You can have a profile that watches for Gmail notifications, then executes that script and sends the output to a file, then reads the line from the file into a variable, and acts on it accordingly. You could have it read the sender's name to you, remind you to read the email if it's someone important, or whatever.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-71268502188728927602012-01-07T07:46:00.000-08:002012-01-07T08:16:39.063-08:00ssh on ICSSince getting the Galaxy Nexus, I've been unable to use ssh until now. The problem was something with the router. Everything was set up properly, all my other computers can ssh to each other, and I could ssh from outside my network, but once connected to wifi, I couldn't ssh from the computer to the phone or from the phone to the computer. I finally solved it by buying a new router.<br /><br />There is still one oddity though. When connected to wifi, the phone will not ssh to the external IP address of anything on the network. What I mean is that if my computer's assigned IP address is 192.168.1.5 and ssh is running on port 1234 and the external IP address is 123.45.54.321, I should be able to connect to 123.45.54.321 port 1234. I always use that since it's the same address I would use if I were trying to connect remotely. But for some reason it won't work.<br /><br />Luckily Tasker provides an easy fix. I set up a profile to write "connected" to /sdcard/Tasker/wifi when connected to my wifi and write "disco" when disconnected. Since I already had to write a <a href="http://a-more-common-hades.blogspot.com/2011/10/remote-ssh-to-multiple-hosts-on-same.html">script</a> to connect to multiple ssh servers, I can read that file and see if I'm on wifi and use the proper IP.<br /><br /><pre>#! /system/bin/sh<br /><br />if grep -q connected /sdcard/Tasker/wifi<br />then<br />comp1ip=192.168.1.9<br />comp2ip=192.168.1.5<br />else<br />comp1ip=$(hip)<br />comp2ip=$(hip)<br />fi<br /><br />case "$1" in<br /><br />comp1)<br />echo "$comp1ip ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts<br /><br />ssh USER@$comp1ip -i PATH/TO/KEYFILE -p PORT;;<br /><br />comp2)<br />echo "$comp2ip ssh-rsa BBB==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts<br /><br />ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;<br /><br />esac</pre><br /><br />There's also another improvement that can be made to that script by changing the section for each computer.<br /><br /><pre>comp1)<br />echo "$comp1ip ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts<br /><br />if [ -z "$2" ]<br />then<br />ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT<br />else<br />shift; ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT "$*"<br />fi<br />;;</pre><br /><br />What this does is check for arguments to the script. If there are none, it will connect normally. If there are arguments, it will run them as commands on the remote computer.<br /><br />So, the command <span style="font-weight:bold;">s comp1</span> would login to computer 1, but s comp1 <span style="font-weight:bold;">cd ~foo && touch bar</span> will run the command on computer 1 to cd to the foo directory and create the file bar.<br /><br />That makes it a lot simpler to bounce commands off the remote computer.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-35463008457670209842011-12-21T19:38:00.000-08:002011-12-21T20:12:21.980-08:00Woe is me...Since getting the Galaxy Nexus, I've had a little trouble and have been flashing ROMs like crazy and spending enough time in recovery that I could have put Betty Ford's kids through college. Wait... I'm not sure that made sense.<br /><br />Anyway, I assumed the problems were from hacks being rushed to the public with little testing, but I think I actually got a lemon and am going to swap it for a new one.<br /><br />To begin with, I kept losing root after an hour or two for some unknown reason. I noticed that the file manager I was using was registering battery usage almost as high as the display after one such unrooting, so I stopped using it. That helped me get through a day or two with root intact, but I'm not entirely sure that was the problem because I was working in the terminal last night and lost root again.<br /><br />I've also had random shutdowns and really bad slowdowns, and I've spend a couple of days trying, and failing, to get ssh to work. Oddly, I can ssh from the phone to my computer from anywhere on the cell network, but it simply will not work when connected to my router.<br /><br />On the router, I had assigned the phone a certain IP address but it seemed to connect at a different one for the past few days. I kept setting it, thinking maybe I had kept forgetting to hit "apply" or something, until I finally realized tonight that I had set it yesterday for a different MAC address.<br /><br />A little investigation revealed that my phone's MAC address changes on every boot. Oops, MAC addresses aren't supposed to do that! It's a pretty neat trick but not only troublesome for IP reservation, but could be causing a lot of other problems as well. <br /><br />I found someone else on XDA who had the same problem and Samsung said it was a hardware problem and swapped it for him. Verizon's phone number is right there on the charger and I didn't know Samsung's so I called the big V and they were a little puzzled. They called Samsung and they were puzzled too, but the Verizon guy told me to swap it.<br /><br />I'm going to swap it at the store tomorrow so I don't have to wait for one to be shipped.<br /><br />It nearly brought a tear to my eye, but I just typed "fastboot oem lock" in a terminal and brought my phone back to stock. But hopefully I'll be ready to start playing with the GNex for real after tomorrow.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-74723188510138175202011-12-18T08:47:00.000-08:002011-12-18T09:41:07.670-08:00Galaxy NexusI finally got a Galaxy Nexus. I went Thursday at 11:15, walked in and told them I wanted a Galaxy Nexus and they said "We don't have them yet. They're coming in via UPS today. We're getting 8 of them and can save one for you if you want."<br /><br />Yes, I live in a small town.<br /><br />I didn't get around to buying one until yesterday afternoon. Since I enjoy voiding warranties within an hour of purchase, I promptly rooted it but didn't have time to do much else. Last night, I was a little upset because I kept losing root. I still don't know what the problem was, I'd flash the recovery and su binary and I would be doing something as root in a terminal when suddenly it would tell me "only root can do that" and I could no longer su. The root checker app said I had root, and the superuser app showed that certain apps were allowed and logged them as allowed when I opened them, but they still reported that they couldn't gain root. <br /><br />It kept losing root after numerous flashes and rootings until I flashed <a href="http://forum.xda-developers.com/showthread.php?t=1394639">this ROM</a> this morning, and that seems to have cleared it up.<br /><br />Anyway, my impressions on the Galaxy Nexus...<br /><br />This puppy is huge! I'm charging the battery on my digital camera to try to get some comparisons of the Nexus One and Galaxy Nexus, but if you want a good idea of the size, it's almost the exact same size as a dollar bill, except a little shorter. <br /><br />You ever go to a cell phone store and look at the flip phones and think "awww, such cute little screens, but I don't know how you could get anything done on that tiny little window." I felt that way when picking up the N1 after 20 minutes with the GNex.<br /><br />The N1 had a habit of turning in my pocket, the GNex stands tall and it's thinner, so although it's much larger, it rides in my pocket better than the N1. <br /><br />There are some things I don't really like. <br /><br />The phone has very few features and it's easy to pull it out of your pocket and try to use it upside down. The earplug is on the bottom, which may or may not be a good thing, I'm not really sure yet.<br /><br />The battery cover is a cheap piece of plastic that snaps in place instead of sliding. It's not what I would have designed, but it does raise the possibility of easy replacement, so there may be some cool looking battery covers showing up soon.<br /><br />There are no hardware buttons for "back" "menu" "home" and "search", instead there are software buttons for "back" "home" and "recent apps". Three small dots are used for settings, and they may be at the top or the bottom of an app. I miss being able to always find them in one place.<br /><br />And no trackball. Oh, how I miss that, but no other phones have them either. I've really been dreading the loss of the trackball, but I'll have to adapt.<br /><br />With the launcher, you can't add widgets by long pressing the home screen, you have to do it from the app drawer. The app drawer has tabs for apps and widgets, and everything side scrolls now, which takes some getting used to. <br /><br />LauncherPro still works, so that gives you the old school feel with long press widget adds etc, but it hasn't had an update in forever so it will surely stop working one of these days and old fogies like me will be dragged kicking and screaming into the future.<br /><br />I really do love the phone. My gosh, when I pull that thing out it feels like I'm using a tablet. I have a lot of setup to do to get things working the way I want, so that means a lot of playing with this cool phone!JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-82333070790699921102011-12-12T19:06:00.000-08:002011-12-12T19:24:22.647-08:00Android blues... and cheers.<span style="font-weight:bold;">The bad.</span><br /><br />My Nexus One is dying. About a month ago, I was having problems like my favorite keyboard kept being reset to the Android default and my email sync kept turning off for no reason. So I upgraded to the newest Cyanogen and had even more problems. First it took several attempts to install, then a couple more wipes and attempts and some tweaking, hacking and tricking to get the Market to work, and I've been having random reboots and lock-ups since. <br /><br />When you have a broken power button, a random lock up means you have to plug it into a charger then pull and insert the battery a couple of times to trick the sucker into booting.<br /><br />I'm pretty sure there is something wrong with the phone's hardware somewhere. The upside is that it gives me an excuse to get the new Galaxy Nexus. The downside is that Verizon is dragging their feet about putting the darn thing on sale, so I'm stuck with a dying N1 for the time being. <br /><br />There's nothing cooler than having to leave a party to go outside and plug my phone into the car charger to tease it into a hard reboot when it suddenly locks up in the middle of a conversation.<br /><br /><span style="font-weight:bold;">The Good.</span><br /><br />If you haven't been to the web version of the <a href="https://market.android.com/">Android Market</a> lately, they've added some handy filters to search results, and they're also having <a href="https://market.android.com/details?id=apps_timed_promotion&feature=banner">10 cent app sales</a> to celebrate their 10 billionth download. The downloads have been changing daily and there are quite a few worth picking up. I've grabbed a bunch because, although I don't really want them now, I may have a use for them in the future.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-65066820399896806112011-10-30T20:44:00.000-07:002011-10-30T21:18:13.602-07:00Run Tasker task from command lineI have been looking for an alternative to Notify My Android in order to send myself notifications to my phone when I'm at home. NMA notifications work fine, but you have to open the app to clear them and I just wanted a vibration or sound that didn't leave anything else on the phone for when a job finished at the computer or something.<br /><br />I first looked at playing a media file with the following command:<br /><br /><span style="font-style:italic;">am start -n com.android.music/com.android.music.MediaPlaybackActivity -d /sdcard/foo.mp3</span><br /><br />That sorta works. It opens the media app and plays the file then immediately goes to the next song. Adding <span style="font-style:italic;">&& sleep 1 && pkill com.android.music</span> makes it work more like I wanted, but that's too ugly.<br /><br />I ran across <a href="http://groups.google.com/group/tasker/browse_thread/thread/6f3057616898efe5">this</a> post in the Tasker forum about invoking a task from the command line, but the consensus was that it wouldn't work unless the command line app has the right permissions.<br /><br />But then I discovered that this works:<br /><br /><span style="font-style:italic;">am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name YOUR_TASK_NAME</span><br /><br />The only difference being the "-e" option instead of "-es."<br /><br />So I made a simple script called "task" for the phone.<pre>#! /system/bin/sh<br />am broadcast -a net.dinglisch.android.tasker.ACTION_TASK -e task_name "$*"</pre>Now I can bounce the command off the phone via ssh and run any Tasker task I want.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-51276876774359761002011-10-19T20:20:00.000-07:002011-10-24T20:58:40.655-07:00The Pogoplug is taking over my lifeThe $50 Pogoplug that I bought to goof around with is now my main server.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/-bMmlRi0UHio/TqYrXIkRCmI/AAAAAAAAAVI/unei2sndQe4/s1600/snap2.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 351px; height: 400px;" src="http://2.bp.blogspot.com/-bMmlRi0UHio/TqYrXIkRCmI/AAAAAAAAAVI/unei2sndQe4/s400/snap2.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5667264857528928866" /></a><br /><br />The Pogoplug is about the size of a small, thick book. To the right is an Edge DiskGo network attached storage drive. That's where I keep all my media to be played on the TV via the Roku and the MyMedia Server Roku app. The Pogoplug is running a small python server that acts as the companion to the Mymedia app and I simply mounted the drive over the network because I didn't have any USB cables to plug it in directly, so it acts as if it is serving the files from it's own drive.<br /><br />Debian is installed on the USB stick in the front of it. The white cable in the back is the power cord, and there's a cat5 plugged into the back which you can't see, and the two black cords are USB cords running to my CM11A and W800RF32A, which are an X10 controller and wireless receiver respectively.<br /><br />It's not only serving media and running the automation, but other scripts to check weather, watch my IP address, back up files from my phone when I connect to my home wifi, etc. Everything installed and runs just as easily as it would on any desktop Linux. The only hard part was getting accustomed to Debian, but it's not so different from Slackware and at least it's not Ubuntu.<br /><br />That's the beauty of Linux, very small programs requiring very little resources can do as much, if not more, than some $100 program you'd have to buy for a Windows computer, and they can do it in the background without you having to be there to point and click, and they can do it on very minimal hardware.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-41237340588176435342011-10-13T21:38:00.001-07:002011-10-14T19:05:43.029-07:00remote ssh to multiple hosts on same network in AndroidI have four devices running ssh at home. Since they're all attached to my router, they all have the same IP address to the outside world, but ssh runs on different ports on each device. In theory, you can ssh into each one by specifying the correct port. In practice, however, it's not always that simple, especially with Android. <br /><br />In order to prevent a man-in-the-middle attack, when ssh makes a connection, it saves the computer's IP and host key in the ~/.ssh/known_hosts file and the next time you try to connect, it checks the IP in that file to make sure the host key is the same.<br /><br />Let me illustrate. Let's say my home IP address is 123.45.54.321. I have 2 devices, comp1 and comp2 running ssh on port 111 and 222, respectively. And let's just say their host keys are AAA and BBB (the keys are actually much, much longer). If I ssh into 123.45.54.321 port 111, then this gets entered into the known_hosts file: <span style="font-style:italic;">123.45.54.321 AAA</span>.<br /><br />Now, if I try to ssh into comp2 at 123.45.54.321 port 222, it gets the host key BBB from the computer and looks in the known_hosts file and says, "whoa, I expected AAA from the computer at 123.45.54.321, something is wrong" then the connection fails.<br /><br />There are normally a couple of solutions for this. First, you can sometimes connect to comp1, copy the key from known_hosts then remove it from the file and connect to comp2. Now put the comp1 key back in known hosts. I've never done this and heard that it doesn't always work, but sometimes ssh will keep trying entries in known_hosts until it gets one right.<br /><br />The better solution is to set up ssh config file like so:<br /><br /><span style="font-style:italic;">Host comp1<br />Hostname comp1.somedomain.com<br />Port 111<br />HostKeyAlias = comp1<br />CheckHostIP = no<br /><br />Host comp2<br />Hostname comp2.somedomain.com<br />Port 222<br />HostKeyAlias = comp2<br />CheckHostIP = no</span><br /><br />Then you can connect with the command <span style="font-style:italic;">ssh comp1</span> or <span style="font-style:italic;">ssh comp2</span>.<br /><br />Unfortunately, that doesn't work with Android because it doesn't have an ssh config file. I'm not entirely sure you can do anything about it with the normal Android ssh program. I deleted it long ago and use the ssh binary from Better Terminal Emulator Pro <a href="http://a-more-common-hades.blogspot.com/2010/11/ssh-error-and-fix.html">(see this post)</a> and there is a workaround with it.<br /><br />The first trick doesn't work with the BTEP ssh binary, and neither does the second trick because it doesn't seem to use a config file. As often is the case with Android, the ugliest solution is the only solution.<br /><br />BTEP looks for the known_hosts file in /data/data/com.magicandroidapps.bettertermpro/home/.ssh (sorry, I originally posted the wrong directory. Fixed now!). You can use the first trick to get a copy of the host keys, then write a script to overwrite known_hosts depending on which computer you want to connect to.<pre>#! /system/bin/sh<br /><br />case "$1" in<br /><br />comp1)<br />echo "$(hip) ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts<br />ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;<br /><br />comp2)<br />echo "$(hip) ssh-rsa BBB==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts<br />ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;<br /><br />esac</pre>You would fill in your user, path to the ssh key and port number. You can also fill in the IP address, but that's what the <span style="font-style:italic;">$(hip)</span> part does. hip is a script that tells me my home computer's IP address which I've blogged about <a href="http://a-more-common-hades.blogspot.com/2010/07/various-linuxphone-ssh-transfer.html">here</a> and <a href="http://a-more-common-hades.blogspot.com/2010/08/tasker.html">here</a>. Essentially, I keep my home IP address in a file and the hip command just displays that file. That way, I don't need to hard code my IP in any scripts. If my IP changes, I can just update it in that file and not worry about changing the scripts.<br /><br />I named the script above simply "s". So, if I run <span style="font-weight:bold;">s comp2</span>, it will write <span style="font-style:italic;">123.45.54.321 ssh-rsa BBB==</span> to known_hosts then connect to comp2.<br /><br />Incidentally, this also takes care of another problem- IP changes. The first time you connect to a host, ssh asks if you really want to connect and you have to type yes or no.<br /><br />If you normally have <span style="font-style:italic;">123.45.54.321 ssh-rsa BBB==</span> in your known_hosts file and your home IP changes for some reason, the new IP won't be in the file and your scripts will break until you manually log in and tell ssh yes or no. But now that no longer matters because we are controlling known_hosts and filling it with the correct up-to-date IP and associated key.<br /><br />The other solutions are better for computers that are running the real OpenSSH, but this is the only solution I could figure out for Android and it's funky programs.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-25026220116866953402011-10-11T19:54:00.000-07:002011-10-11T20:40:11.121-07:00PogoplugI was in Best Buy today and noticed that they sell Pogoplugs for $50 so I picked one up. I believe it is the first generation without wifi, but I don't care about that, I prefer using network cable when available over wifi anyway. The downside to Pogoplugs is that they have very little space available on them, but you can install Linux on an external hard drive plugged into them via USB. I didn't have an external drive, per se. I have a NAS network drive, and that may work, but I didn't have a USB cord to attach it, so I installed Linux on a USB stick for the time being.<br /><br />Using <a href="http://mehl.co/articles/installing_debian_on_the_pogoplug/index.html">this</a> guide, it only took a few minutes to have a very minimalistic version of Debian running on it, and after installing the gcc compiler and other tools, I was able to install <a href="http://www.heyu.org/">Heyu</a>. Then I plugged my CM11A X10 controller into the Pogoplug and was a little surprised that the darn thing actually worked. Awesome!<br /><br />The NAS drive is what I use to store videos for streaming to the Roku. I tried to install the server program on the Pogoplug using the USB stick just to see if it would work, but python threw socket errors for some reason. I'm going to investigate whether I can use the NAS with the Pogoplug. If not, I'll probably get an external drive and use it to serve videos, control the home automation, and various other things I have a computer doing now. I'm not entirely certain I want to turn over everything to a little box like this, but I want to do it to see for myself that it can be done, then change back to the computer if I prefer it.<br /><br />I think it's pretty amazing that, for $50, you can get a computer the size of a book that can do all this. Then again, the <a href="http://www.raspberrypi.org/">Raspberry Pi.org/</a> is only going to be $25, so maybe I got ripped off!JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-14293126692376003782011-10-07T20:55:00.000-07:002011-10-10T19:58:47.975-07:00Yay, new computer.I bought a new computer and, boy, why didn't someone tell me computers had gotten so darn good these days? My main desktop was a 2.2 GHz box with 2 gigs of ram. That's pretty outdated but was enough for everything I needed, but I wanted to turn it into a server and get a new one for general use. Now I have an i7 quad core with eight 3.3Ghz processors. What a difference!<br /><br />Since I got the Roku, I found myself wanting to encode videos to play on it. With the old computer, encoding a 175mb 30 minute TV show took about 45-50 minutes and the fans on the computer sounded like a jet trying to take off. And movies? They weren't worth spending hours to encode.<br /><br />The new computer? It can encode a TV show in 1-2 minutes and a 3 Gig HD movie in 15-30 minutes and it doesn't make a sound the entire time.<br /><br />I've had it for a couple weeks, but soon after getting it, half of my home automation stopped working. I finally figured out that the computer was to blame. The instant the power cord is plugged into the computer, it causes interference that drowns out the X10 signals. I ordered a noise filter that finally arrived so now I can leave it plugged in as long as I want and still have my automation working.<br /><br />Anyway, I've been slowly setting up the old computer to act as a server. It isn't a lot of work, it was really a desktop/server before, but I need to get everything set up so I can stick it in a closet somewhere and forget about, administering it from the new computer when needed.<br /><br />I should have a lot to post about soon. I have a transceiver for my home automation on the way in order to pick up RF signals. With it, I will be able to set up motion detectors and things that can send a signal to the computer instead of only the other direction. Automation is only half useful without that.<br /><br />I'm also planning to start toying around with plug computing. A plug computer is a full fledged linux computer that fits in a box the size of an electric plug. With the right setup, I could do away with my computer that acts as a server and use a plug computer to run the automation, and mount a cheap hackable display like the Chumby in the house to control it all graphically, and of course Android to control it all remotely.<br /><br />Anyway, sorry for not having much to post about but hopefully that will change soon.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-22034894356028288432011-09-19T17:07:00.000-07:002011-09-19T18:56:51.929-07:00Camera weather displayI'm sorry I haven't posted much in a while. To tell the truth, I haven't done much worth sharing. My daughter started kindergarten and I think her school is harder for the parents than the kids, and being a single dad makes it all the more tough. The only time I have for myself is a couple hours after she goes to bed and the housework ain't doin' itself during that time.<br /><br />Oh well, I did come up with something pretty cool that will probably be of no use to anyone unless they have the same gadgets as me. It may inspire someone to do something similar with other gadgets though.<br /><br />Taking my <a href="http://a-more-common-hades.blogspot.com/2011/02/foscam-control-script-etc.html">Foscam</a> and <a href="http://a-more-common-hades.blogspot.com/2011/07/final-roku-bash-shell-script.html">Roku</a> scripts and a Roku app, I made a little automated camera/weather display for my TV.<br /><br />The Roku app is <a href="http://forums.roku.com/viewtopic.php?f=28&t=25955&start=0">MyMedia</a> which allows you to play files from your computer on your TV. It's two parts, a simple server for your computer and an app on the Roku. The server shares Music, Photo and Video folders to your local network where the MyMedia app on the Roku can pick them up. There are other Roku apps which do the same thing, but this one fit my needs.<br /><br />Once that is set up, the ID for that channel is 2542, so using my Roku script, you can use the command <span style="font-style:italic;">roku go 2542</span> to load that channel. Once it loads, you can use the script again to navigate to different folders using <span style="font-style:italic;">left/right</span> and <span style="font-style:italic;">select</span> commands. You can, of course, do this with the Roku remote control, but it's a lot cooler to automate it.<br /><br />Let me back up and first post the script then walk through everything that is happening in 4 steps.<pre>#! /bin/sh<br /><br />cam snap<br /><br />WX=$(links -dump &#39;URL&#39; | grep -A 6 'Weather:' | sed -e 's/^[ \t]*//')<br /><br />convert /sdcard/cam.jpg -fill white -gravity South -pointsize 25 -stroke '#000C' -strokewidth 2 -annotate 0 "$WX" -stroke none -fill white -annotate 0 "$WX" /sdcard/cam.jpg<br /><br />roku right<br />roku go 2542; sleep 7<br />roku str right right select; sleep 1<br />roku select</pre><br /><br /><span style="font-weight:bold;">Step 1: cam snap</span><br />Using the Foscam script, just run <span style="font-style:italic;">cam snap</span> and a jpg will be saved wherever you have the script set up to save it. On my computer, I actually made a /sdcard directory so I could more easily write scripts that would work on both the computer and Android phone, so /sdcard/cam.jpg in this post is on the computer, not the phone.<br /><br /><span style="font-weight:bold;">Step 2: WX=$(links -dump...</span><br />Links is a command line Linux browser which can dump the text of a webpage. Lynx is another which is often interchangeable with Links, and both have the same -dump option so either could be used here. This sets the WX variable to the output of the links command. I used the weather conditions from the <a href="http://mobile.weather.gov/">weather.gov mobile site</a>. Click that, put in your zip code, click go, then click current conditions. Copy the URL of the current conditions page and use it to replace URL in this command in order to grab everything from Weather to Visibility then align the text properly. This is just an example, you could get the weather from anywhere.<br /><br /><span style="font-weight:bold;">Step 3: convert...</span><br />"convert" is part of Imagemagick, a powerful command line image manipulation program which is installed on most Linux distributions. In this case, I'm using it to write the weather from the WX variable on the image.<br /><br /><span style="font-weight:bold;">Step 4: roku...</span><br />All the Roku commands use my Roku script to navigate to the MyMedia channel and select the image. The first command is used to wake the Roku up in case the screen saver is on, the second selects the channel and waits for it to load, which usually only takes 3-4 seconds, and the rest navigate and select the image. I don't have any other images to display so when I navigate to the Photos folder and click "select", it automatically opens the image I want since it's the only one. If you have other photos, you may want to use a subdirectory and a couple extra commands to navigate to it.<br /><br />Here is the end result:<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/-NKxpRx3dvB8/Tnft3YKejPI/AAAAAAAAAVA/z8xVgF4Rd8M/s1600/cam.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 400px; height: 300px;" src="http://1.bp.blogspot.com/-NKxpRx3dvB8/Tnft3YKejPI/AAAAAAAAAVA/z8xVgF4Rd8M/s400/cam.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5654249392821931250" /></a><br /><br />I pointed the camera at a wall because the normal view would show part of my neighbor's house, and I would feel awkward about that. It's also dark, it looks much better pointed over my yard with the daytime sky in view. The image itself is mediocre on a computer, but looks great stretched out on a wide screen TV.<br /><br />So, what use was all this? Well, I have a cron job scheduled to run at the same time my alarm goes off in the morning. It turns on a couple lights that are controlled with X10 automation, sends the weather forecast to my phone, and a couple other odd jobs. I added this to the schedule, so I can roll over, look at the TV and see what it looks like outside as well as the current weather conditions.<br /><br />I also set up a Tasker task to ssh in to my home computer and run the first three steps, copy the resulting file to my phone, then display it, in case I'm interested in seeing this image and info while I'm away.<br /><br />While this trick is pretty specific to my setup, maybe it will inspire someone with other gadgets to do something cool with whatever they have.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-4573316381204743232011-08-28T06:43:00.000-07:002011-08-28T08:52:43.027-07:00Part 2: Finding the current song playing in Android, still sorta.I made a post about getting the filename from the mediaserver at the <a href="http://groups.google.com/group/tasker/browse_thread/thread/022b69791ce009be">Tasker discussion group</a> and others found that the lsof utility only comes on Cyanogen so many people don't have it. I found an alternative in "<span style="font-style:italic;">ls -l /proc/$(pidof mediaserver)/fd</span>" and I'll show some ways to use it below.
<br />
<br />Another poster, Matthieu, also figured out a way to get the mp3 tags from the files. The ID3v1 tags are pretty simple, but ID3v2 is a pain. Here is a post I made to that thread incorporating the lsof alternative, Matthieu's method of extracting ID3v1 from that thread, and the start of an ugly method to get ID3v2 tags. More on that in a moment.
<br />
<br />Here's an lsof alternative. I think it could do without the grep command but it's safer with it in:
<br /><pre>ls -l /proc/$(pidof mediaserver)/fd | sort -g -k 9 | grep mp3 | tail -n1</pre>This will give you the long filename like /sdcard/foo.mp3:
<br /><pre>ls -l /proc/$(pidof mediaserver)/fd | sort -g -k 9 | grep mp3 | tail -n1 | awk '{print substr($0, index($0,$11))}'</pre>This gives the short filename like foo.mp3:
<br /><pre>basename "$(ls -l /proc/$(pidof mediaserver)/fd | sort -g -k 9 | grep mp3 | tail -n1 | awk '{print substr($0, index($0,$11))}')" .mp3</pre>This gives the id3v1 tag:
<br /><pre>tail -c 125 $(ls -l /proc/$(pidof mediaserver)/fd | sort -g -k 9 | grep mp3 | tail -n1 | awk '{print substr($0, index($0,$11))}') | head - c30</pre>This gives the id3v2 tag but needs tweaking:
<br /><pre>grep -A 20 TIT2 "$(ls -l /proc/$(pidof mediaserver)/fd | sort -g -k 9 | grep mp3 | tail -n1 | awk '{print substr($0, index($0,$11))}')" | grep -m 1 [a-z]</pre>That last one is ugly and unfinished. ID3v2 tags are variable length and the length of the tag is supposed to be encoded in the file itself but, for the life of me, I can't find a file on my system that follows that guideline. I'm obviously missing something because they display correctly when played, but most of them also have ID3v1 tags on the end as well, so maybe that's why they display properly.
<br />
<br />I would spend time trying to find a better solution but Pent said he is going to add mp3 tag support to Tasker soon and that should work better than anything I could come up with. Plus, I'm really not interested in the tags. When something interests me, I usually get about an hour late at night to work on it, and I only want the file name.
<br />
<br />As ugly as it is, the last one still kinda works. All the tags on my system start with TIT2, but are followed by a lot of hex gibberish before the plain text tag begins. This greps TIT2 then greps the first line below it that contains a lower case letter. On my files, it has a high success rate. One big problem it has is that the tag is often followed by another field such as TALB, so the output can be "<span style="font-style:italic;">Song TitleTALB</span>." Someone could figure out all the possible fields in an ID3v2 tag then just use sed to chomp them off. Or someone cou otu a more reliable method, or we can just wait for Tasker to do it for us.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-38205738600569100962011-08-20T23:05:00.000-07:002011-08-22T21:52:15.194-07:00Finding the current song playing in Android, sorta.I've seen people wanting to use Tasker to get the title of the currently playing song before, but it's not really possible because Android doesn't have an API for it. There is a semi-workable solution using the Locale Execute Plugin. We can find which files the media server has open with the lsof command. Assuming the only files you're interested in are mp3s, we can just grep the mp3s from the list and print the filename:<pre>lsof -p $(pidof mediaserver) | grep -m 1 mp3 | awk '{print substr($0, index($0,$9))}'</pre>As luck would have it, the current song seems to always be at the top of the list, so using <span style="font-style:italic;">grep -m 1</span> we can just get the first line of output.
<br />
<br />Output: <span style="font-style:italic;">/mnt/sdcard/download/AloeBlacc-YouMakeMeSmile.mp3</span>
<br />
<br />It can be cleaned up a little with the basename command:<pre>basename "$(lsof -p $(pidof mediaserver) | grep -m 1 mp3 | awk '{print substr($0, index($0,$9))}')" .mp3</pre>Output: <span style="font-style:italic;">AloeBlacc-YouMakeMeSmile</span>
<br />
<br />If you're interested in files other than mp3, you can add them to the grep command:<pre>grep -E -m 1 'mp3|wav|other1|other2'</pre>The downside is that this just gets the file name and doesn't display any metadata or anything like that. If your file is Track10.mp3, it may show information about the artist and song in the media player, but with this trick it will only show Track10.
<br />
<br />This trick also works to display the file being played in BeyondPod, the podcatcher app, but podcasts often don't follow naming schemes meant for humans so the output for the Jordan Jesse Go! podcast ends up being <span style="font-style:italic;">jjgo110814_ep187</span>. If your goal was to display the file in Tasker or Zoom, you could set up replacement titles for your podcasts, like if the title matches jjgo*, display "Jordan Jesse Go!"
<br />
<br /><span style="font-style:italic;">Aug 23</span>: I edited the awk command to handle filenames with spaces, then I realized the awk command isn't needed. There's no need to pick out the field with the filename with awk. You can use the entire line, the basename command will only output whatever is to the right of the last "/" anyway. I'll leave the original up since it's been there for a couple of days and people have already seen it, but this simpler command would be better to use:<pre><span style="font-weight:bold;">basename "$(lsof -p $(pidof mediaserver) | grep -m 1 mp3)" .mp3</span></pre>Use that one instead, and I'll try to notice the obvious sooner next time.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-16409448187679274462011-08-03T17:22:00.000-07:002011-08-03T17:26:31.328-07:00Free Nexus SIf you go to google.com, there is a line of text that reads "Nexus S, a pure Google experience. Get it FREE today only"<br /><br />It requires a 2 year contract or an extension of your existing contract. I wasn't impressed with the Nexus S when it came out but my Nexus One is seriously aging and I'm contemplating getting a Nexus S. I can't make up my mind because I want to wait for something better too. Oh well, in case you missed it, go to google.com and click the link.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-47843959784404768292011-07-20T16:18:00.000-07:002011-07-20T16:38:11.489-07:00New Tasker pluginIf you read this blog, you're probably interested in the new <a href="http://groups.google.com/group/tasker/browse_thread/thread/ee097f28aa6b8cab">Secure Settings</a> Tasker plugin. It has a lot of features which seem good. Unfortunately, I don't have a use for any of them except the shell command runner and I'm happy enough with my own methods that I probably won't change. But the plugin does allow you to store stdout and stderr in a Tasker variable and I'm sure will be a hit.<br /><br />The downside is that you have to set up a "variable changed" profile to get the output (see the second post in that thread and the later reply). It's more or less the same as my <a href="http://a-more-common-hades.blogspot.com/2011/01/tasker-command-runner.html">command runner</a> profile except it can display multiple lines of output and my profile can't because Tasker still can't read entire files. (I got it on the todo list, but it's been sitting there for nearly a year).<br /><br />Plus, it has other features. If you're interested in those, it's probably a win-win.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-15938915961383276472011-07-14T22:13:00.000-07:002011-07-14T22:15:53.274-07:00Notify My Android downWouldn't you know it, as soon as I start using and posting about Notify My Android, it stops working. According to an NMA <a href="http://twitter.com/#!/NotifyMyAndroid">Twitter post:</a><blockquote>Google C2DM SSL Server certificate expired and they didn't update. It should be normalized later this morning. Sorry for that.</blockquote>That was 16 hours ago. Hopefully they get it running soon.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-60713270476582358912011-07-11T17:19:00.000-07:002011-07-11T18:06:16.960-07:00Pulling data from Notify My Android notificationsNotify My Android (NMA) doesn't have Tasker integration, but we can bridge the gap... sorta.<br /><br />Data for the app is stored in a database so we can pull out the ever handy sqlite3 and grab it.<br /><br />sqlite3 /data/data/com.usk.app.notifymyandroid/databases/nma "SELECT * from notifications;"<br /><br />The data is stored in pipe delimited fields with the newest record on top. Here is what it looks like when I send the output of the date command as both the event and description field.<br /><br /><span style="font-weight:bold;">44|141395|Home|Mon Jul 11 20:18:43 EDT 2011|Mon Jul 11 20:18:43 EDT 2011|1310430099|0|1</span><br /><br />Assuming we want the 5th field, just tell Tasker to read the line, split the variable then flash %VAR5.<br /><br />But here's the catch, Tasker can perform an action when the notification comes in but the data doesn't go into the file until a few seconds after the app is opened, after it syncs with it's home server.<br /><br />The most elegant solution doesn't work. That would be a Tasker context watching for the file to be modified, then running the command to get the new notification. Unfortunately, watching for file modification doesn't seem to work in /data/data.<br /><br />You could write a script to watch the file for new contents then put something in a file on the sdcard that Tasker could see, but it would be necessary to keep the script looping and if you lost the network connection or something, it could loop indefinitely. You could kill it once the app exits, but this is getting too complicated.<br /><br />The easy answer is to just add a wait. You'll need a profile watching for the app to open, but disable that profile. Then have a profile watching for the notification. Once the notification comes in, have it enable the "App Open" profile. The App Open profile can carry out a task to<br /><br />1 wait 5 seconds (adjust if your network connection takes longer) <br />2 execute: @! sqlite3 /data/data/com.usk.app.notifymyandroid/databases/nma "SELECT * from notifications;" > /mnt/sdcard/Tasker/notified<br />3 read line 1 of Tasker/notified to var %NOTIFIED<br />4 Variable Split %NOTIFIED splitter: |<br />5 flash %NOTIFIED5<br />6 Profile Status set Notified off<br /><br />Remember, the NMA app must be opened for Tasker to grab the notification data, but with these profiles, when there isn't a notification, it can be opened without triggering the task.<br /><br />%NOTIFIED5 will contain the main body of the notification. You can select from 3, 4 or 5. They are the application, event and description. All three are necessary to send a notification through NMA and can contain 256, 1000 and 10000 characters respectively. Only the application and as much of the event as possible show in the Android Notification area. The entire event and the description are shown in the app.<br /><br />Pent has put the ability to read any file system-wide on Tasker's todo list. Until then, I hope someone gets some use out of this.JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.comtag:blogger.com,1999:blog-2110188019887806057.post-50691505217989045232011-07-10T08:11:00.001-07:002011-07-10T08:56:41.310-07:00Prowl-like custom Android push notificationsOh boy, I've been wanting this forever. When I used the iphone a year and a half ago, there was an app called Prowl which allowed you to send any push notification to your phone. You could, for example, have your computer send a notification when it booted and the notifications could say anything up to a 1024 character limit.<br /><br />I've really wanted that for Android and hoped to see it when Google came out with the Cloud to Device Messaging service but I didn't find it until now.<br /><br /><a href="http://nma.usk.bz/">Notify My Android</a> will allow you to send custom push notifications to your phone and here's how to use it from the Linux command line.<br /><br />You first get the app from the Market then create an account on their website. Once you log in to the website, go to "my account" and generate an API key. Now it's as simple as crafting a cURL or wget command to post the data.<br /><br /><span style="font-style:italic;">curl -k https://nma.usk.bz/publicapi/notify -F apikey="YOURKEY" -F application="Testing" -F event="test event" -F description="hello world"</span><br /><br /><span style="font-style:italic;">wget -q -O - --post-data "apikey=YOURKEY&application=APPNAME&event=EVENT&description=this is the description area where the actual notification text is supposed to go" https://nma.usk.bz/publicapi/notify </span><br /><br />The fields can be found on the website on the API page. cURL is easier to understand here because you just put a -F then the name of the field to post to and the text to post. <span style="font-style:italic;">-F apikey="YOURKEY"</span> is pretty easy to decipher, but wget is actually doing the same thing, just differently.<br /><br />One trick I always thought was useful was to set it up so you can pipe output to the phone. You can pipe output to this short script and it will show up on your phone. I include both wget and cURL. cURL is simpler to use on a computer but wget can be used on your phone, however, I've found that wgen on the phone doesn't allow secute https. You can still use regular unsecure http if you think the threat is low enough.<br /><br /><pre>#! /bin/sh<br />out=$(< /dev/stdin)<br />wget -q -O - --post-data "apikey=YOURKEY&application=APPNAME&event=EVENT&description=${out}" https://nma.usk.bz/publicapi/notify<br /><br />#! /bin/sh<br />out=$(< /dev/stdin)<br />curl -k https://nma.usk.bz/publicapi/notify -F apikey="YOURKEY" -F application="Testing" -F event="test event" -F description="${out}"</pre>JMhttp://www.blogger.com/profile/02471284686600275424noreply@blogger.com