Rusty's Blog

Thoughts and musings of someone who's not sure what 'normal' is…

Tuesday, October 13, 2009

Proprietary vs. Free.

First let’s get something straight. Free does not mean free as in free beer. If the developer wishes to make it free as in beer, they can, but that doesn’t mean it has to be inexpensive. Free also does not mean ‘Open’ in the sense that we will let you see the code, but that’s it. Free means that You can look at the code. You can modify the code. You can have someone else modify the code. You can feed those modifications back to the people you got the code from, or distribute the modified code yourself.

That said, free does not mean that you then can restrict the code to the product you release.

Perhaps an example would be handy. Personally I type faster than I can write with paper and pencil. That’s hardly unusual, but it does impact how I work compared to some other people. There are also requirements on what I am allowed to take from work. With good reason. In any case let’s take this situation and realize that there are going to be times when I want to note something, and have it available, but which I don’t really need to save for tomorrow. Basicly I just need a scratch pad. It might be nice if I could copy portions into the copy/paste buffer, but let’s presume that’s provided at an operating system level, or even by the tools provided by the libraries I’m using.

Ok, yes I could use just about any editor, and at the end of the day tell it not to seve the content, but I really don’t even want to be bothered with the prompt. Often I’m in a hurry to get going some place else, and the prompt doesn’t always pop up immediately. More of a problem though is that the vast majority of editors have a lot of extra features buit in that forces the application to take a significant amount of time to start. I just want a scratch pad that’s almost immediately available. So:

#!/usr/bin/python                  # You may need to change for your distribution
'''
   Scratchpad: A quick and dirty example of using a text area
   from gtk as a scratch pad. No major bells and whistles.
'''

import Tkinter                     # library of functions we'll need

scratchpad = Tkinter.Tk()          # scratchpad is a variable identifying an instance of TK
scratchpad.title("My Scratch Pad") # Nice to have a friendly window title
content = Tkinter.Text()           # add an area to put text into
content.pack()                     # Put it all together

scratchpad.mainloop()              # make it usable to the user.

Not a lot there eh? Well, for me that’s the entire point. But I can see where someone else might just want to be able to convert this into an editor. Tkinter has menu functions built in, and you could easily add a check on load to see if a file was given on the command line, add menu items to be able to load or save files, create new files, add tabs, etc. Probably the first thing to add would be a help option where if a user pressed ‘F1′ it would pop up a box telling the user what the intent of the program is, and how to use it. I’m hoping it’s reasonably self explanatory though, so for the moment I won’t be adding anything. Others can though.

You might be wondering if you can use this scratchpad. Sure. You will need to have Python installed on your computer. It’s installed by default on most Linux computers, you can download an installer from python.org for your computer if you are running Windows or a current Mac OS. (I Know it is available for Mac OS X, I don’t know about 9.x)

Once you have Python installed, you will need a text editor, the included IDLE will work, but under Windows Notepad will function just fine. I don’t run Mac OS systems these days so finding an appropriate editor is up to you, however vi should be available from withn the command prompt, EMACS, or the included IDLE editor for python should all work as well.

Open your editor, copy that code snipet from above, paste it into your editor, tell the editor to save the file with a usable filename, something like scratchpad.py, and close your editor. Under linux you will need to make the file executable using a command like “chmod +x scratchpad.py” in the appropriate directory. And from now on you can run the application simply by double clicking on the file. If you want you can create a link or alias to it from your favorite application launcher. How you do that is beyond the scope of this blog entry.

This will not work on the Android phone at the moment. The ASE release of Python does not currently support Tkinter. In time who knows.

Now as to a licence. I would honestly be surprised if anyone considered this worthy of a proprietary licence. I’ve done nothing within the application that is all that spectacular, and when it gets down to it, nothing within the tool is ‘creative’ it is essentially a simple instance of using included tools.

It also has flaws that I’m not concerned about fixing at this time. There is no scroll bar showing that there is text above or below the window view provided, and the text area does not resize if you resize the window. I can live with those flaws, but you might not like it enough that you want to fix those bugs. Or perhaps you want to extend the tool to give you statistical information about the contents of the scratch pad. You have to write a thousand word paper, well you could add a label at the end and refresh the content every second or two with the result of something like ‘i = content.text.split() ; statistics.label(“%i words” % length(i))’ And if you are using it that way, you might want to add those menus to save what you are editing. Go for it.

Now of course someone will be of the opinion that something like this is a great app, and they could market it. Well, great do so. You’ll note that you are free to do so. I would ask as part of the precept of free that if you are selling the product that you will be the point of contact for support for the app. I certainly am not going to be earning anything for my time providing support at this time, as the description above pretty much describes all of the support I can provide.

This really defines the real distinction between proprietary and free. To be proprietary at this point I would, and actually could, take the code listed above, use something like py2exe and create an executable, and possibly an installer for the program. However once I’ve done that, the resulting executable will only run under Windows. Mac users, you would be out of luck. For that matter, so would Linux users. I would have created a program that anyone running Windows could use. And while some would argue that that’s a tremendous market. Imagine that even 1% of 1% of the people running Windows paying $1 for a copy. I might even be able to retire. Well, yeah. I might even be able to hire someone to support the program. Who knows. The problem is that I personally am not interested in dealing with the support headaches.

The scratchpad shown above is scratching an itch. I needed a way to capture information temporarily. I’m not writing a journal or log of events that I will need to come back to at some point. I just decided to scratch an itch. That itch could be scratched using ‘notepad’ under windows, or for that matter any of hundreds of different editors. I just ended up still having an itch that needed to be scratched. So I scratched it. You are welcome to use the result, or not.

The proprietary solution would end up working more along the lines of ‘what is the need?’ ‘can we provide something to solve that need?’ ‘What is the potential for earning off of this?’ ‘How can we get our customers to pay for the program?’ ‘Is there likely to be a positive return on the work done?’ and so on. The biggest component however is the ‘How do we set things up so that ‘we’ get the money for this?’ question. To do that one has to make the product proprietary. Here is the end result of all of my work. Pay me, or you don’t get to make use of it. It may not do what you are looking for, but if you don’t pay me, you don’t get to decide that. And if it doesn’t do what you are looking for, that’s OK, I didn’t guarantee that it would.

Ok. enough of that. If you find the above information useful, you are welcome to decide if it is of value to you. I don’t think that the amount of work I’ve put into the program is worth money. But that doesn’t mean that you don’t. If you think it is worth sending me $1, I have to say I don’t know how you would do so. It’s a transaction level below what is sensible to send checks or money orders, and high enough to be a problem for PayPal to handle as personal transactions over time. Of course that’s a separate issue that I won’t get into at this time.

My issues with ‘proprietary’ over ‘free’ software are not the fees or commercial nature. My issues have to do with cutting out a significant percentage of potential users, and treating users as idiots. As noted above if I develop a proprietary product, It is very likely that I will have to limit myself to a single variety of potential users. You like Windows and I write for MacOS? Ok, you go buy a Mac. Doesn’t work well does it? If I write for Windows, and you run a Mac, things are a little better in that most macs have the ability to run Windows either embeded within mac, within a virtual computer, or in paralel with the Mac.  However the latter two require buying a windows licence, which I suspect many Mac users are loath to do. And no I’m not going to tell you of the problems of running windows programs under Linux. Some will use dual boot, or virtual terminals, etc.

In short, by developing for a specific target platform you are locking yourself into only having those people who are interested in running that platform as your customers. After all, if you wanted to write for multiple platforms, you would need each of those platforms to develop under. (at some level.)

Treating your customer as an idiot is related to the fact that you are actively preventing the user from extending or improving your product to better suit their own needs. If you are Steve Jobs, or Bill Gates, and when you walk into a room you are the smartest person in the room, you might be justified in deciding that all your customers and competitors are idiots. Me? I’m not so sure, and I certainly don’t want to treat friends and other potential users that way.

So for me, I’ll stick with free solutions You don’t have to, but you probably will find it workable as well.

posted by Rusty at 12:51 pm  

Sunday, September 13, 2009

Gleaning your IP address.

So you’re out and about. Having fun with your G1 (or other android phone) you’ve taken some pictures and you decide that right now you want to take one of thoe pictures and use it as the wallpaper on your laptop.

Well, you can e-mail it to yourself. Or you could post it on your picasaweb account, or well “neither of those really interest me.” you say? Well, if you had been thinking this morning when you left the house you probably would have packed along a usb cable to like up your computer to your phone, but if you are like most other people, you’ve decided that that really isn’t something you want to carry today, and you can always take care of that tonight. Or perhaps you have one of those micro sd-card to usb adapters on your keychain? No. Bummer.

Wouldn’t it be great if you could just fire up a small web server that points at your photo album? Point your web browser on your laptop at it and download the picture you want?

Actually if you have installed the Android Scripting Engine (ASE) you can.

ASE includes interpreters for Bean Shell, (a Java based shell scripting language) Lau, (found in some Linux distributions) Python, (pretty much everywhere these days) bash, (also pretty common) and more to come. Now I’ll be one of the first to admit that all of these are probably anything but feature complete. If you are thinking ‘Hey I’m going to write a push button app with custom lables using tk!’ sorry, tk is not included. However if you are interested in talking to the network, get information from features of the phone such as the location via gps, or the orientation of the phone (face up/down, on the side, etc) you can do some pretty interesting things. In time the screen may be dot addressable, and you may be able to do gui stuff, but it’s not currently being planned.

I’ve not done anything with Bean Shell, and not all that much with Lau. Both have fans and from what I have seen are likely to be used fairly heavily. However I do like to dabble with Python, so you’ll find most of my blog postings here relating to ASE are going to focus on Python.

But we’ve got that photo to get to the laptop. Right? Lets work on that.

Perhaps you haven’t installed ASE but that might work for you? Poing your browser at http://code.google.com/p/android-scripting/ and you should see a QRcode bar code on the page. If you have the BarcodeScanner application istalled fire it up on your phone, point the camera at the bar code on the screen, and you’ll end up in the application installer looking at the install helper for ASE.There are additional instructions that you will want to follow to add in the actual python interpreter as well as some sample scripts.

Now since the 0.10 alpha release of ASE, not only can you download the application itself via qrcodes, but you can enter small scripts that way as well. Launch ASE, hit ‘Menu’, pick ‘Add Script’ and select ‘Scan Barcode.’ The barcode reader will come up again, point it at the following qrcode based on the script posted by Mrflakey to the ASE-Scripting mail list:

httpd.py

httpd.py

You’ll actually be able to run it immediately, however it’s always a good idea to take a look at the code. It should look something like this:

httpd.py
import SimpleHTTPServer
from os import chdir
chdir('/sdcard/')
SimpleHTTPServer.test()

If all you wan to do is browse your pictures, then you will probably want to change the chdir line to read something a bit more like “chdir(‘/sdcard/dcim/Camera’)”

Now there is only one ‘issue’ left. “How do I get to the server?” Well, to tell the truth, that has been the real reason for this posting.

<hr>

The first time I used the script and downloaded content from my phone, the way I found the IP address for my phone was to open a terminal session on my dhcp server and looked for the message indicating that my phone had just been assigned an address via dhcp. That’s all well and good for when I am at home, but if you are out on the road, you probably don’t have that ‘advantage.’ Last I checked T-Mobile wasn’t exactly giving me access to their system at a level where I could get the IP address that my phone was using from their servers. Not really expecting that any time soon either.

If you dig around, you can find the ip address, but wouldn’t it be nice if you could present it as part of that httpd.py script? Actually, you can. But it’s a bit more work.

<hr>

The Android platform allows you to see the current IP addresses on your phone by using the command netcfg at the command prompt. You already know about 127.0.0.1. If you don’t a brief note, don’t bother to try to download anything from your phone by pointing your web browser on your laptop at 127.0.0.1:8000, it won’t work.

There are 6 different ‘interfaces’ that may have an IP address on your phone.:

$ $netcfg
lo      UP      127.0.0.1       255.0.0.0       0x00000049
dummy0  DOWN    0.0.0.0         0.0.0.0         0x00000082
rmnet0  DOWN    25.96.178.24    255.255.255.252 0x00001002
rmnet1  DOWN    0.0.0.0         0.0.0.0         0x00001002
rmnet2  DOWN    0.0.0.0         0.0.0.0         0x00001002
tiwlan0 UP      192.168.0.2     255.255.255.0   0x00001043

The above is something ‘like’ what is deisplayed on my phone. Presumption being that I’m at an internet cafe with wifi access and I’ve gotten both the cell phone and my laptop on the wifi, I would simply point my web browser at http://192.169.0.2:8000/ after launching httpd.py on my phone and I would be up and running. (caveat the internet cafe or wifi provider has to have enabled the ability of wirelessly connected customers to communicate directly with each other.)

If rmnet0 was UP rather than DOWN, and unless you have a rooted phone or a more recent phone than the G1 you will find tiwlan0 will thus be DOWN, and the internet cafe allows internet browsing, I could point my browser at http://25.96.178.24:8000/ and I would be able to browse the content as well.

On the other hand that’s a couple of extra steps. First you get the IP address of your phone, then you launch the server, then you hope you remember what the IP address was so you can point your laptop at the address. Annoying right?

Well we’re going to add two bits of content to the httpd.py script in a bit, one imports the library we are going to write, the other displays what our IP address is. But in order todo that we need to add a script to the phone. Let’s call the script ‘netip.py’.It’s going to have to do a few things.

  • Get the list of ip addresses and interfaces from the phone. We’ll call the program netcfg to get that.
  • ignore the ‘lo’ interface.
  • return the interface and ip address of the UP interface(s) or
  • return the ip address of the UP interface(s)
  • be able to show that the library functions.

There are some contitions that over the long term you will want to address as well, but I’m not going to for this script. What do you do when you are in a place without cell service or wifi? Currently the script does not address that.

Ok, we are going to import the following libraries.

import os, sys, android, string, time

os and sys allow us to talk to the operating system, android because the script will want to be able to show us things like what IP address we got using the makeToast() android call. The time librarry we are using to allow us to display two or more results with a delay between them. We are going to be using the string library to manipulate the output of the system call to netcfg. but we better get that first:

def colint():
    status = []
    a = os.popen('netcfg','r')
    while 1:
      line = a.readlines()
      if line:
        status.append(line)
      else:
        return status
        break
    return status

Ok, status is set to an empty list. the os.popen() call tells the phone to run the netcfg program and we are going to ‘read’ the results from the system call. Start a while loop. ‘1′ is always ‘true’ so we’ll use that for the test. In the loop we assign ‘line’ to the result of doing a readline on a. Now if the result of that is true, i.e. we got something other then an end of file mark we append the content of line as a new list entry to status. if we don’t get anything from the readline we return the status and break out of the while loop. The final ‘return status’ is not necessarily required, but I would rather have the function return a blank status if the while fails for some reason. Up to you.

Of cours we’re really only interesetd in entries that have a status fo UP right? so let’s get rid of the rest.

def upips(work):
    status = []
    a = 0
    while a < len(work[0]):
      if "UP" in work[0][a]:
        status.append(work[0][a])
      a += 1
    return status

This time we call the function with a list and presumably in that list there are some entries that have the string ‘UP’ in them.

And of course we are not interested in the ‘lo’ interface so we’ll clean that out:

def nolo(work):
# given a list of strings (with embeded '\n') break as needed, return
# list of strings w/o 'lo' in them)
  status = []
  a = 0
  while a < len(work):
    if "lo" in work[a]:
      a += 1
    else:
      status.append(work[a])
      a += 1
  if len(status) == 1:
    rets = status[0]
    statusl = rets.split()
    status = statusl[2]
  return status

If there is only one interface with an up status (other than lo) we also break up the string and only return the IP address. That’s done by calling the ’split’ string function and assigning the resulting list to ’status1′ then status will get the third entry (first is at 0 and is the interface name, ‘lo’, ‘tiwlan0′, etc. the second at 1 will be the up/down state.) Otherwise if it looks like there are multiple interfaces up besides the lo interface we will return a list of the entire strings.

The rest of this can either be considered ‘test’ code, or you can call the next to functions directly. The labels are a bit misleading. At an early stage in development these functions actually displayed the IP addresses. I decided later on that I really just wanted them to return them to the calling function. At some point you may be interested in binding to the up interface. The two functions are displayUp() and displayNoLo() which returns all up interfaces, or all but the lo interface. You will probably be most interested in the displayNoLo() function, but who knows.

def displayUp():
  nets = colint()
  nets = upips(nets)
  return nets
def displayNoLo():
  nets = colint()
  nets = upips(nets)
  nets = nolo(nets)
  return nets

Now then it’s always a good idea to include in a script some code to run to make sure that it all works. Since each of the two functions above will call the earlier functions we really only need to call those two functions. However we are going to make use of the makeToast() android call so we need ot initialize android. Also makeToast() displays a popup for about 2 seconds so let’s give it a chance to complete between calls to it, and exiting the program.

if __name__ == '__main__':
  droid = android.Android()
  droid.makeToast(displayUp())
  time.sleep(5)
  droid.makeToast(displayNoLo())
  time.sleep(5)
  droid.exit()

The ‘if’ conditional at the top is the first line that will be run if you execute the program directly. I personally recommend including all of this. At the very least you will be able to look at how various functions can be called later on.

Ok, if you have a clean camera lens, you may be able to load the entire program via qrcode. Again launch ASE, ‘Add Script’ from the Menu button, and ‘From Barcode’ Once that is up, point the camer at the screen and see if it will read the following bar code:

netip.py

netip.py

And a modified httpd that uses the code is at:

httpd2.py

httpd2.py

If you would rather, the full text of the scripts are at http://www.beresourceful.net/~rusty/android/netip.py and http://www.beresourceful.net/~rusty/android/httpd2.py

Now if you have an available network connection and access to the internet, you should never be unable to get documents off your sdcard for your Android based cell phone.

Once you run a program that imports a python library you will end up with both a .py and a .pyc of that file in your list of scripts. The .pyc edition can be run the same as the .py, but is a ‘compiled’ version of the program that speeds up execution of library system calls in the future.

You may wish to create a ’shared’ folder on your sdcard that you point httpd2.py at instead of pointing at the entire card. Or as noted earlier just point at your /sdcard/dcim/Camera/ folder for images only. The reason for that is that there are no restrictions on who can download content from your phone while httpd2.py is running, except for the limitation that it is in a subdirectory of the current directory. You may also want to change the print out to read more like ‘print “connect to http://”, netip.displayNoLo(), “:8000/”‘ to give you a reminder that it is on port 8000 and that you use a web browser.  If 8000 is entirely too likely for someone to connect to, you can point SimpleHTTPServer.test() at a different port. I’ll leave learning how to do that to you. If you don’t have a rooted phone, you can’t point at anything below 1023, but you could point it at 58080 if that works better for your mental image.

Enjoy, and play around.

posted by Rusty at 3:30 am  

Monday, July 20, 2009

90% done…

…90% to go.

I posted a half humorous note on my facebook page Friday (or was it Saturday morning?) that had a list of tasks I wanted to do this weekend. Asside from a bit of formatting, I’ve gotten what I think should be the most important part of the list done.

One of the problems I have at work is that I can’t exactly launch any IM client and start chatting with people. I have a few philisophical problems with the Microsoft Communicator client at work. But am happy to use it for the most part. The biggest issue I have is that you can’t update contact information to display a custom identifier for someone. If it isn’t published in the domain the way you want it to appear, too bad so sad. Oh, I understand some of the reasoning behind that. No labeling your boss the ‘idiot in charge’ and stuff like that. But if there are two John Smith’s in your business, it can take significant additional knowledge to confirm that you have selected the right John Smith to send a message to. If you know that one of them preferrs to be called Jonathan, it makes sense to be able to put that in an alias for the user in the IM client. But that’s locked out at the moment. I’m not holding out a lot of hope that it will change either.

However that’s still not the significant issue for me. The real issue is that I can’t connect to the resources I would like to. Particularily my own jabber server.

So I have had to come up with a kludge. And the first half works for now.

The kludge is that I have put together a monitoring client for my jabber server that attaches as one of my resources, and simply collects each IM that I receive, and tosses it into a tab separated values file. (I’ve had issues with comma separated values in the tool that I use to read the messages, so rather than fight with them, I’ve set up the tool to work with me.

The other issue I’ve had over the years or so has been that I’m never really sure what happens to an IM sent to me while I am away, or if I get something and the client dumps for some reason. This way I should get a reasonably comprehensive copy of my IMs while I am otherwise occupied. In theory I could set up the client so that at any time I could pull up a list of messages on another session, sort of using it as a secretary within jabber. Who knows, I may just do that at some point. Not tody though.

On top of that I needed a way of displaying those messages. I have that now too. I was able to use some of the code I wrote a while back. Ok, I basically grabbed something out of a php tutorial at some point, and I’ve been re-arranging things ever since. In any case I revised the code again, and now I can view the contents of the capture file. Basicly the tool I’m using displays the contents of the formatted text file in a table.

Things ain’t quite perfect yet. The script crashes out on unicode character issues, which I’m not sure I have a good way to get arround, but until it dies, I can at least see most of the messages I get.

The second half of that list should be easier. Well, the actual sending of messages will be. However I am not building the sender code without adding some security wrapper to the system. That URL will need authentication before it should accept a message to send. The reality is that I need to build the authorization and authentication system in such a way that it can not easily be spoofed. One of the problems with the easiest sollution I can come up with is that I don’t know if there is a way to maintain authentication without adding some sort of SSL or https sollution to the mix.

This is a ’solved problem’ you may be saying. Use https or ssl. Not so fast. First of all I need to build the platform so that I can get such a solution through the firewall at work. Not necesarily trivial, however that on it’s own is not a serious problem. The greater problem is that to use the appropriate ports on my server, I need ot abandon features that I very much do not want to abandon. so not so easy.

The next obvious sollution is to use gpg to encrtype the user credentials and then base 64 encode the encrypted credentials and send that off as a cookie that can be asked for at any time. The problem here is that with the exception of a user on a public internet server, the encrypted credentials could be used by anyone on a nat traversing link. Capture the cookie with airsnort or the like, and you suddenly have everything you need to look like me to my server. So that’s not a solution I’m happy with.

I suppose I could implement a variation of a kerberose solution. Point the user at a third party location for logging in using a ssl or https session there, then that system provides a token back to the local web server that is provided to the user’s workstation in a cookie that is only good for a few minutes, and the user needs to re-authenticate again if they exceed that time. A varriation would be to only allow the user to post if a persistent authenticated secure session exists with the third party server. (separate tab or window that could be minimized) One possible variation would be to build in open-id/open-auth. I’m already using that at one level for this blog, however I’m not sure that either have a system that works well with passing arround jabber credentials securely.

I don’t think I’m going to get that part of the solution implemented this weekend.

Oh well.

posted by Rusty at 12:58 pm  

Tuesday, June 30, 2009

My first Android App/script…

Minor setup stuff. I use a G1 phone from T-Mobile and have very much enjoyed the experience. One of the things that I’ve been looing for since I started using it has been a way to post microblogs to http://identi.ca. There are a couple of apps out there for twitter users, and while I do use twitter, it’s had a few problems that make it unsutible in my view for ongoing use.

There really are several different ways of getting content out of identi.ca onto my phone. sms messages, e-mail, web browser, gtalk/xmpp, etc. However I really didn’t want to be reading messages from identi.ca, I’m a bit more interested in sending messages to there.

For me a critical point is that I have a jabber/xmpp server running on one of my own servers. As a matter of fact I had already linked my jabber account there. If you have a gmail account, you might prefer to use that. However a pointer there is that any time you receive an IM at your gmail gtalk account, it very well may be using an sms message to talk to your phone. That can get expensive. I recommend using a server of your own, or getting an account on jabber.org or a public server and use that resource for sending and receiving jabber to identi.ca messages.

Now getting a jabber message from a phone to a jabber server is not really difficult. I suspect that I could install a development package on my desktop, write a bit of code for the android environment, compile a package, put it on a server I have access to, install the package to my phone, test, and repeat the steps from write a bit of code on, until testing gives me the results I expect.

An alternative that has just recently shown up is the Android Scripting Environment. http://code.google.com/p/android-scripting/

With the Android Scripting Environment (ASE) you can write scripts in Bean Shell, Lua, or Python. By default Bean Shell is installed, but you will need to install the interpreters for Lua and Python. The Environment is a .8 code base, which means it is very functional, but may not be complete from the perspective of a general user.

I’ve personally never done well in Java, and Bean Shell really is a scripting environment for Java. If you happen to like Java, it may be all you need. I’ve also never worked with Lua, but from what I see in the collection of scripts that are available as examples, it appears to be a reasonable language as well. I have played around a bit with Python, and while the environment is hardly complete, it seems to be sufficient for what I need. For android, it does include xmpp support, as well as support for pulling down URLs, interpreting html, and a few other elements as well. All I needed this time was the Android support and the xmpp support.

I’ve liberally copied code from a couple of different resources. For an example of how to send a message to a jabber server, (which was not written for the android platform, but it’s python and all the referenced libraries are included in ASE) I used the tutorial at http://snippets.dzone.com/posts/show/618

Here’s the sample:

import android
import xmpp

droid = android.Android()

# User interaction stuff
message = droid.getInput('identi.ca update', "What's Up?")['result']
tag = droid.getInput('tags?',"What tags? (Prepend w/#)")['result']

# Varios Variables we will use
_SERER = 'jabber.server.you.use', 5223   # put in your own jabber server name and appropriate port
username = 'your.user.name'              # give it the user name you want to use
password = 'your.password'               # until I figure out how to store these credentials securely
fullmessage = tag + message              # build the message we're going to send. (could use improvement)
destid = 'somename@jabber.server'        # for identi.ca use 'update@identi.ca'

# send the message
cnx = xmpp.Client('jabber.server.you.use') # don't need the port so don't use when creating a connection instance to use
cnx.connect( server=(_SERVER) )          # establish a connection
cnx.auth(username,password, 'G1')        # authenticate yourself, and give a 'presence' (G1 in this case)
cnx.send( xmpp.Message( destid, fullmessage ) ) # Send the message

# exit 'cleanly'
quit = droid.exit()                      # we're done, time to go

And that pretty much summs it up. There are a few things I will be investigating over time. I suspect that using a dictionary, I can create a set of ‘tags’ that I want to use regularly (#cvg2009, #c25k, etc.) then feed that to some sort of a pick list, and hopefully I could enter the update and select the appropriate tag all in one dialog. Worst case, 2 dialogs sort of like what I’m doing now. This currently has a bit more flexibility, but in the end I would also like to be able to identify if this is to be a message to update, or to some other specific user.

What am I doing with this? Well, as a department co-head for the 2009 CONvergence convention, I wanted a way to update my facebook, twitter, identi.ca and planet pages with what I’m doing, and what’s happening now. I’m pretty sure that I can update twitter directly, and possibly through that facebook, and it looks like I could import from there to identi.ca, which also would propogate to my world page, but after seeing the problems that twitter has been going through with it’s growing pains, I didn’t think that was the best route. If it works for you, ok. The facebook app for Android has been having problems since facebook changed something recently, so that was out. And it’s been a while since I wrote anything I considered interesting like this, so here it is.

How things work from here. My jabber server accepts a connection and forwards the message to update@identi.ca, which then places the update in my stream. Through the facebook interface it posts an update to facebook. I also have my account configured so that all events are posted to twitter as well. My planet page pulls any updates I’ve made in the past couple of hourse every 2 hours from twitter and identi.ca. Hey it pulls an update that I’ve posted a blog as well. Handy little page at times.

I always seem to discover ‘issues’ that need to be corrected that have almost nothing to do with the specific project at hand, except that they got in the way. Today I discovered I had not punched a hole for tcp through my firewall for jabber clients. I had punched one for UDP, but since nothing is listening for that…

Have fun. If you find the app useful, and want to let me know about updates, I would appreciate hearing about them.

posted by Rusty at 12:15 am  

Powered by WordPress