Showing posts with label processing. Show all posts
Showing posts with label processing. Show all posts

Tuesday, September 17, 2013

Setting Processing's User-Agent for loadXML

In Processing, I'm fetching Yahoo's weather forecast for my location.  The loadXML() function is perfectly happy to take a URL, so I can just point it at my location's RSS feed.

In its default mode, this sends a user-agent string of "Java/1.6.0_51" which reflects my current Java version.  But I want to set my User-Agent, to something more descriptive.  If my project misbehaves, or an operator gets curious, it would be polite to have a more descriptive string with some contact info.

You can prepend a string to the user-agent by specifying it in your setup() function.

void setup () {
  System.setProperty("http.agent", "abstractForecast; https://github.com/fnaard/abstractForecast;");
}

Which results in the web server logging a user-agent of:

abstractForecast; https://github.com/fnaard/abstractForecast; Java/1.6.0_51

Oracle has some documentation on the network properties you can set.  There are more, notably: proxy settings, IPv4/v6 preference, and DNS caching behavior.

Thursday, March 22, 2012

Activating your MacOS Screensaver from the Command Line (and Processing!)

It's a matter of calling osascript with the -e flag, and giving it a statement to evaluate:

  osascript -e 'tell application id "com.apple.ScreenSaver.Engine" to launch'

It's useful at the moment because I'm messing around with a Touchatag RFID reader (drivers are here, btw), using these libraries for Processing.  What I wanna try out first is attaching an RFID tag to the bottom of my coffee mug.  When I leave my desk to get some more tea, I'll tap the mug on the reader and it'll activate my screensaver, which requires a password to unlock.

BTW, here are the two lines (mind the line-wrap, there) in Processing, to kick-off that applescript and activate the screensaver:

  String[] command = { "/usr/bin/osascript","-e","tell application id \"com.apple.ScreenSaver.Engine\" to launch"};
  exec(command);


Easy enough!  Next up, if I've tapped more than three pint glasses of beer, disable the Send button in my email client.

Sunday, September 18, 2011

New Toy

This little guy arrived the other day, just in time for a quick Arduino and Beer trip I'm taking up to the Bay Area.  It's a little thermal printer, similar to the ones in cash registers.  It's light, and it seems to only need one or two amps at five volts.  I have a battery pack that puts out two amps at that voltage.  My brother has some plans.

The manual is kinda fun .. it's chinese and bad english .. but the last page shows some extended characters, one of which is a solid black square, so I might be able to do QR codes on self-adhesive paper.  Extra checksums plz!

Some of the docs mention RS232, so I'm gonna pack a usb-to-db9 connector with me.  They also mention useful configuration bits for running on battery power, so we're in the right neighborhood for a battery-powered application.  Hey and the example code is for Processing!  Plus, there's a link to some good-looking Arduino hackery.  I think we'll hit the ground running!

Monday, October 25, 2010

Getting Started with Processing

I finally finished the Getting Started with Processing book. It's been the one I carry around for when I'm getting the oil changed, having lunch alone, or have a moment at the pub. Here's what my screen looked like after the penultimate chapter.