Android and Linux

Monday, May 28, 2012

The granddaddy of weather geek tasks

I 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 Mesoanalysis site. It consists of 110 different weather maps and models, all of which are available for 10 different regions of the United States.

Again, I must warn you, the intented audience for this is... me! This was created for my Galaxy Nexus with a 4.65 inch 1280×720 resolution screen size. 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.

The way it works is pretty simple. The main interface is a scene named MesoMenu1. I've included a task named MesoStart 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.

This is the main interface, MesoMenu1. 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 Convective Outlook project, for example.

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.

This is an example of selecting Wind Shear 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.

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.

Here is the download link. Download to your sdcard then import into Tasker. Enjoy.

Sunday, May 20, 2012

Oops, Convective Outlook bug fixed

Oops, the Tasker project in my last post 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.


Sunday, April 29, 2012

Convective Outlook Tasker projects for weather geeks

(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.)

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.

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.

So, here is a simple one, a mobile version of the Storm Prediction Center's Convective Outlook 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.

The whole thing is pretty simple, the menu allows you to choose the outlook for Day 1, 2 or 3.

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.

Tapping on the text or the image will take you back to the previous menu where you can select another day if you want.

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.

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.

I've put this up for download here. 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.

Wednesday, February 1, 2012

Tasker scenes

If 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.

Here is my first one. It may not be pretty but it's useful:

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.

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.

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.

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.

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.

Sunday, January 22, 2012

ssh problem with Locale Execute Plugin

I 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:

D/LocaleExecute( 7130): stderr: ssh: Warning: Reading the random source seems to have blocked.
D/LocaleExecute( 7130): stderr: If you experience problems, you probably need to find a better entropy source.

/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.

/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 "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."

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.

cd /dev
mv random random.bak
ln -s urandom random

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.

Thursday, January 19, 2012

Pulling Sender and Subject from Gmail part 2

I'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.

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.

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"

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.

Here is what it looks like. I just signed up for an account at RootzWiki, so that's my most recent email.
# mailsender email
# mailsender name
# mailsender subject
New Registration at RootzWiki
# mailsender
"RootzWiki" <> New Registration at RootzWiki
Using this, it's easy to trigger a Tasker action based on any of those criteria.

First you set up an event profile based on a ui notification owned by gmail, and use it to trigger a task like this:

1- using the Locale Execute Plugin, execute one of the commands and redirect it to a file
2- wait 1 second (usually a good idea with commands like this)
3- read line 1 from the output file to %var
4- Do something if %var matches whatever

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.

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.
#! /system/bin/sh


case "$1" in

sqlite3 ${dir}mailstore.${yourmail}.db "select fromAddress from messages ORDER BY _id DESC LIMIT 1" | grep -o '"[^"]*"' | tr -d \";;

sqlite3 ${dir}mailstore.${yourmail}.db "select fromAddress from messages ORDER BY _id DESC LIMIT 1" | grep -o \<.*\> | tr -d '<>';;

sqlite3 ${dir}mailstore.${yourmail}.db "select subject from messages ORDER BY _id DESC LIMIT 1";;

sqlite3 ${dir}mailstore.${yourmail}.db "select * from messages ORDER BY _id DESC LIMIT 1" | awk '/@/{FS="|";print $4,$11}';;

If you want to play around, you can also extract a preview to the email, or even the entire body with these sqlite3 commands:

"select snippet from messages"
"select body from messages"

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.

Edit: Jan 20. Here's a QR code to copy the script to your phone's clipboard.

Wednesday, January 18, 2012

Screenshot command

This command will take a screenshot on Android ICS:

/system/bin/screencap -p /sdcard/FILENAME.png

You might want to make the filename be the date and time:

/sdcard/$(date +%m.%d.%Y-%H:%M).png

I found that in /system/bin/, 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.

It's a neat trick. With Tasker, I can trigger a screenshot and scp that sucker right to my computer automatically.

Tuesday, January 17, 2012

Pulling sender and subject from Gmail

This 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.

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.

In the directory /data/data/ is a file named Breaking out the trusty sqlite3, we find that the sender and subject is contained in the 4th and 11th fields of the messages table and we can extract that by dumping the table...
sqlite3 "select * from messages"
...and filtering it with awk.
awk '/@/{FS="|";print $4,$11}' | tail -n1
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.

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.
awk '/{FS="|";print $4,$11}' | tail -n1
The end result is something like "John" <> Re: blah blah

Instead of posting a huge long line that makes my blog look funny, I'll put it all together like this:
#! /system/bin/sh
sqlite3 ${file} "select * from messages" | awk '/@/{FS="|";print $4,$11}' | tail -n1
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.

Saturday, January 7, 2012

ssh on ICS

Since 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.

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 and ssh is running on port 1234 and the external IP address is, I should be able to connect to 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.

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 script to connect to multiple ssh servers, I can read that file and see if I'm on wifi and use the proper IP.

#! /system/bin/sh

if grep -q connected /sdcard/Tasker/wifi

case "$1" in

echo "$comp1ip ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts

ssh USER@$comp1ip -i PATH/TO/KEYFILE -p PORT;;

echo "$comp2ip ssh-rsa BBB==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts

ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT;;


There's also another improvement that can be made to that script by changing the section for each computer.

echo "$comp1ip ssh-rsa AAA==" > /data/data/com.magicandroidapps.bettertermpro/home/.ssh/known_hosts

if [ -z "$2" ]
ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT
shift; ssh USER@$(hip) -i PATH/TO/KEYFILE -p PORT "$*"

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.

So, the command s comp1 would login to computer 1, but s comp1 cd ~foo && touch bar will run the command on computer 1 to cd to the foo directory and create the file bar.

That makes it a lot simpler to bounce commands off the remote computer.