December 12, 2011

Above image is the result of the following code:

So it sort of runs, but displays this error in the console:

java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:613)
at processing.mode.java.runner.Runner.reportException(Runner.java:561)
at processing.mode.java.runner.Runner.exception(Runner.java:501)
at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
at processing.mode.java.runner.EventThread.run(EventThread.java:89)
Exception in thread “Animation Thread” java.lang.NullPointerException
at processing.core.PApplet.loadImage(Unknown Source)
at processing.core.PApplet.loadImage(Unknown Source)
at wunderground_twitter.responseReceived(wunderground_twitter.java:169)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.francisli.processing.http.HttpClient.pre(HttpClient.java:163)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:680)

Oddly enough, when I don’t have the color commented out in Glyph.pde, I get this:

Going to switch gears and work on the Arduino stuff. I did spend the morning looking at the Sparkfun 2x2 button pad, and I think I’m going to go with a rotary encoder for the following reasons:

  • I need diodes for it and didn’t realize this until today.
  • The tutorial I found is just for hooking up four RGB LEDs and getting them to flash. I only have two RGB LEDs and don’t think I have time to figure out how to get single-color LEDs to work with this thing, or even if it’s possible.
  • I am already losing my mind as it is.

Permalink: http://tmblr.co/ZtI-YwDB4Twc

December 12, 2011

All right. I’m part of the way there. I can get individual tweets to show up as dots, with happy tweets on the top row (query “weather :) geocode:37.781157,-122.398720,15mi”) and sad tweets on the bottom (query “weather :( geocode:37.781157,-122.398720,15mi”).

But what happens with the code above is that this comes up:

and then it’s quickly replaced by this:

The arrays are being filled with 200 items because that’s how I initialized them, then replaced with the 15 items returned by the Twitter search once that call is actually made. So I need to instantiate my arrays after the responseReceived method is invoked, but simply moving those lines of code into the responseReceived or draw methods isn’t working.

The other problem is that I’m only getting 15 results for each search, which is useless for showing me how many positive/negative tweets were made about the weather within a certain time period. Not that I’ve built that into the search yet.

Permalink: http://tmblr.co/ZtI-YwD8xuPq

your code not (completely) functional or elegant

December 11, 2011

Got it to display data from 4 cities. I’m sure there’s a less stupid/more elegant way to do this, but it works…sort of. I’ve run it 6 times and have gotten a NullPointerException twice, but maybe it’s because I’m making API calls too close together? (Yeah, I’m totally pulling that out my ass. I don’t actually know why it’s only working 2/3 of the time.)

Now it’s time to work on the Twitter stuff. It’s currently in a separate sketch. Once I get that working on its own (which shouldn’t be too difficult considering we’ve done really similar stuff in previous assignments) I’ll create a Tweet class in the wunderground sketch. I’m hoping to get all the visualizations worked out today so I can solder my button pad tomorrow and get that working over the next two days.

Permalink: http://tmblr.co/ZtI-YwD7R5H_

December 10, 2011

Some links I included in my project proposal, but haven’t yet posted here:

Twitter Search API - searching by time
http://stackoverflow.com/questions/6819211/twitter-search-api-searching-by-time

Getting Started with Processing and Data Visualization
http://blog.blprnt.com/blog/blprnt/your-random-numbers-getting-started-with-processing-and-data-visualization

Using Sparkfun’s 2x2 RGB LED Button Pad with an Arduino
http://www.aarongoselin.com/active-posts/28-using-sparkfuns-2x2-rgb-led-button-pad-with-an-arduino

Permalink: http://tmblr.co/ZtI-YwD4ZSRI

December 7, 2011

I didn’t need that word wrap function after all. I just needed to set the width and height of the text area: Processing reference for text()

Permalink: http://tmblr.co/ZtI-YwCyg5ip

December 7, 2011

I’m going to need this at some point: http://wiki.processing.org/w/Word_wrap_text

Permalink: http://tmblr.co/ZtI-YwCyWD0T

December 3, 2011

Oh. I wasn’t including the parent dictionaries. (Thanks, Nuri, your code helped me figure out my problem!)

Console output:

San Francisco, CA
Last Updated on December 3, 2:33 PM PST
Current conditions: Partly Cloudy
Temperature: 66.9° F / 19.4° C

Also, I was getting the error

ClassCastException: java.lang.Double cannot be cast to java.lang.Long

on the line

int tempF = results.get(“current_observation”).get(“temp_f”).intValue();

so I looked at the JSON data again and it turns out temperatures are expressed as decimals. When I looked at it a couple days ago, the temperature in Fahrenheit was coincidentally right at 63 degrees, but if I’d paid attention, temp_c was 17.2. (Right after I figured this out, I looked at Francis’s email about the HTTP library update and he mentioned it there too. Paying attention is important and will save you time.)

Note: tempF and tempC apparently can’t be doubles. The error I get here is

ClassCastException: java.lang.Double cannot be cast to java.math.BigDecimal

The Processing reference sheds some light on why this doesn’t work:

Processing functions don’t use this datatype, so while they work in the language, you’ll usually have to convert to a float using the (float) syntax before passing into a function.

Also…from reading one of Nuri’s posts, and thinking about the problem I had earlier with the way temperature values are expressed in the Weather Underground API, it looks like it might be necessary to convert to one data type or the other using int() or float().

Permalink: http://tmblr.co/ZtI-YwCmTU8E

Not working.

December 3, 2011

Code above returns a NullPointerException:

Exception in thread “Animation Thread” java.lang.NullPointerException
    at wunderground.responseReceived(wunderground.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.francisli.processing.http.HttpClient.pre(HttpClient.java:163)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
    at processing.core.PApplet$RegisteredMethods.handle(Unknown Source)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PApplet.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:680)

I’ll come back to this after lunch.

Permalink: http://tmblr.co/ZtI-YwCm2Vz5

information I need from wunderground

December 1, 2011

In order to display the data I need from Weather Underground, I’ll need to make requests for:

  • city & state: display_location, full (string)
  • date: current_observation, observation_time (string)
  • temperature: current_observation, either temperature_string (obviously a string) or temp_f and temp_c (both int)
  • conditions: current_observation, weather (string)

(Screenshots of JSON data are from the Weather Underground API console.)

Permalink: http://tmblr.co/ZtI-YwChxSyi

simple weather underground API request using http library for processing

November 30, 2011

This code:

import com.francisli.processing.http.*;

HttpClient client;

void setup() {
  client = new HttpClient(this, “api.wunderground.com”);
  client.GET(“/api/d6961237291397f0/conditions/q/CA/San_Francisco.json”);
}

void responseReceived(HttpRequest request, HttpResponse response) {
  println(response.getContentAsString());
}

void draw () {
}

Returns:

HttpClient: Connecting to api.wunderground.com on port 80
HttpClient: GET http://api.wunderground.com:80/api/d6961237291397f0/conditions/q/CA/San_Francisco.json HTTP/1.1

{
    “response”: {
        “version”: “0.1”
        ,”termsofService”: “http://www.wunderground.com/weather/api/d/terms.html”
        ,”features”: {
        “conditions”: 1
        }
    }
        ,    “current_observation”: {
        “image”: {
        “url”:”http://icons-ak.wxug.com/graphics/wu2/logo_130x80.png”,
        “title”:”Weather Underground”,
        “link”:”http://www.wunderground.com”
        },
        “display_location”: {
        “full”:”San Francisco, CA”,
        “city”:”San Francisco”,
        “state”:”CA”,
        “state_name”:”California”,
        “country”:”US”,
        “country_iso3166”:”US”,
        “zip”:”94101”,
        “latitude”:”37.77500916”,
        “longitude”:”-122.41825867”,
        “elevation”:”47.00000000”
        },
        “observation_location”: {
        “full”:”SOMA - Near Van Ness, San Francisco, California”,
        “city”:”SOMA - Near Van Ness, San Francisco”,
        “state”:”California”,
        “country”:”US”,
        “country_iso3166”:”US”,
        “latitude”:”37.773285”,
        “longitude”:”-122.417725”,
        “elevation”:”49 ft”
        },
        “estimated”: {
        },
        “station_id”:”KCASANFR58”,
        “observation_time”:”Last Updated on November 30, 4:57 PM PST”,
        “observation_time_rfc822”:”Wed, 30 Nov 2011 16:57:09 -0800”,
        “observation_epoch”:”1322701029”,
        “local_time_rfc822”:”Wed, 30 Nov 2011 16:57:17 -0800”,
        “local_epoch”:”1322701037”,
        “local_tz_short”:”PST”,
        “local_tz_long”:”America/Los_Angeles”,
        “weather”:”Clear”,
        “temperature_string”:”64.2 F (17.9 C)”,
        “temp_f”:64.2,
        “temp_c”:17.9,
        “relative_humidity”:”30%”,
        “wind_string”:”From the NNW at 11.0 MPH Gusting to 12.0 MPH”,
        “wind_dir”:”NNW”,
        “wind_degrees”:340,
        “wind_mph”:11.0,
        “wind_gust_mph”:”12.0”,
        “pressure_mb”:”1020.9”,
        “pressure_in”:”30.15”,
        “pressure_trend”:”-“,
        “dewpoint_string”:”32 F (0 C)”,
        “dewpoint_f”:32,
        “dewpoint_c”:0,
        “heat_index_string”:”NA”,
        “heat_index_f”:”NA”,
        “heat_index_c”:”NA”,
        “windchill_string”:”NA”,
        “windchill_f”:”NA”,
        “windchill_c”:”NA”,
        “visibility_mi”:”10.0”,
        “visibility_km”:”16.1”,
        “precip_1hr_string”:”0.00 in ( 0 mm)”,
        “precip_1hr_in”:”0.00”,
        “precip_1hr_metric”:” 0”,
        “precip_today_string”:”0.00 in (0 mm)”,
        “precip_today_in”:”0.00”,
        “precip_today_metric”:”0”,
        “icon”:”clear”,
        “icon_url”:”http://icons-ak.wxug.com/i/c/k/nt_clear.gif”,
        “forecast_url”:”http://www.wunderground.com/US/CA/San_Francisco.html”,
        “history_url”:”http://www.wunderground.com/history/airport/KCASANFR58/2011/11/30/DailyHistory.html”,
        “ob_url”:”http://www.wunderground.com/cgi-bin/findweather/getForecast?query=37.773285,-122.417725”
    }
}

(link to HTTP library for Processing)

Permalink: http://tmblr.co/ZtI-YwCei0Pw