Real-time Weather with Flash and Java

January 22nd, 2010 by Rob
1-Wire Weather Station

1-Wire Weather Station

This is a real-time weather station I built using an AAG electronica instrument and an EEE 701 for the server.

I coded the server in Java using Apache’s Mina library for non-blocking sockets. The client is FLEX, and uses Socket (rather than HTTP). The webcam service consists essentially of a Java class that reads the video4linux data as raw RGB and saves it to a JPEG which is then streamed over the socket along with all the other data (I built the server to be pluggable, so each of these little add-ons is a plugin that shares the stream with the other plugins). The archival data lives in MySQL.

Read the rest of this entry »

Flex Earthquake Map

January 22nd, 2010 by Rob

Shows the world’s earthquakes during the last 24 hours. Blue markers are small magnitude quakes, red markers are large magnitude.

Data updates every 30 seconds and comes from here: http://earthquake.usgs.gov/earthquakes/catalogs/

AppendToGatewayUrl

June 22nd, 2009 by Rob

If you’re using BlazeDS and seeing an error involving a callback called “AppendToGatewayUrl” this might help.

AppendToGatewayUrl modifies the gateway of a NetConnection object with the session id (in this case “jsessionid”) of the current session. If you reconnect with this value appended to the gateway URL, your session can be identified, even on clients that do not use cookies.

There are two ways to handle this:

  • set NetConnection.client to an object that implements the AppendToGatewayUrl function, or;
  • subclass NetConnection to implement it (since NetConnection.client points to the NetConnection instance by default, you can not reassign the client field if you want this method to work).

There’s one caveat to both approaches, though. It has been my experience that if you call NetConnection.connect while you are receiving a response to bundled remote methods, the data may be lost or a “Client.Data.UnderFlow” error thrown. This occurs because AppendToGatewayUrl gets called after the first result, and the immediate call to NetConnection.connect aborts the rest of the transfer.

Here’s a sample implementation of option A:

public class Sample{

  private var conn : NetConnection;

  public function Sample(){
    conn = new NetConnection();
    conn .client = this;
    conn .connect(‘http://localhost/gateway’);
  }

  public function AppendToGatewayUrl(extra:String):void{
    conn .connect(conn.uri + extra);
  }

  public function load():void{
    conn .call(’service.load’,new Responder(loadResult,error));
  }

  private function loadResult(value:*):void{
    trace(‘value’,value);
  }

  private function error(err:*):void{
    trace(‘error’,err.message);
  }

}

To get around the problem with bundled calls, you could save the session id in a field and reconnect before the next call.

Update: Using PixelBender to Crunch Numbers

March 7th, 2009 by Rob

I didn’t realize it, but there’s a bug in PixelBender for Flash when using image4 input. In my case, I have x-y coordinates, and I was trying to operate on two at a time using image4. Can’t do it (yet). The kernel craps out after 60 elements.

Of course, you’re not allowed to output 2- or 1-element pixels, so you have to use image3 for input. What to do? It’s simple really: Say you have a Vector of numbers representing pairs (coordinates, in my case). The first pixel with contain x,y,x and the second y,x,y and so on. All you have to do is check the current pixel’s x-coordinate (assuming the height of your PixelBender input is set to 1) and do the calculations in one or the other order.

Note that in PixelBender, the x,y of the pixel (as reported by outCoord()) is the midpoint of the pixel, so x=0.5,1.5,2.5 and so on. To determine which order to take the calculations in, you just need to know whether x is even or odd.

Read the rest of this entry »

Using Pixel Bender for Math in Flash/FLEX

February 27th, 2009 by Rob

Pixel Bender has applications other than manipulating images in Flash/FLEX. While working on some map projection experiments, I decided to look for a way to offload some of the computations to avoid freezing up the display or simply taking too long. Turns out, Pixel Bender not only does math several times faster than Flash, it can also be run asynchronously!

Read the rest of this entry »

Dynamic Font Loading in Flash 9

June 18th, 2008 by Rob

One of the biggest headaches in localizing Flash sites is setting up to dynamically load and easily use embedded fonts. Recently, in order to build a site that will need localization for an as-yet-undecided number of countries, I finally decided to dive in and solve this problem once and for all.

Read the rest of this entry »