2011.05.18

HTTP Request

I’ve been falling behind on Processing Month, but it’s not because I haven’t been hacking away, it’s because I’ve been hitting a lot of walls, not having things work out the way I want them to. I’m trying to not just take other people’s code and go from there, but trying my best to dig through the Processing documentation and reference and figure things out. Sometimes it works… Sometimes it doesn’t.

So that “138″ you see above is not very exciting at all. I started working with pulling data from the web into Processing, with the thought that I’ll have a web application output data, that Processing pulls in, and then talks to an Arduino to do… something.

So right now there is a bit of PHP that looks like the following:

<?php echo "138" ?>

And in Processing when I call the println command it outputs this:

HTTP Request

And in draw() after we call the println command, we also call the text command which puts the “138″ on the canvas.

I know… it’s fairly unexciting, but it’s a small step. Very small. I have a long way to go to get it working more reliably. Right now, we are reversing the output from the request, and grabbing the first line (index array zero) which should be the last line if we didn’t reverse it. I’m not too clear on array operations yet. (I come from the text processing world of Perl, so there’s a little culture shock in Processing.) Also, if the code outputs anything after the value, it doesn’t work. (I found this out when editing the file in nano, which seems to add an extra line at the end. Urgh)

/*
 * 20110518.pde
 */

import processing.net.*;

Client c;
String data;

void setup() {
  size(800, 600);
  background(0);
  stroke(255);
  c = new Client(this, "rasterweb.net", 80);
  c.write("GET /raster/processing/20110518.php HTTP/1.1\n");
  c.write("Host: rasterweb.net\n\n");
}

void draw() {
  
  if (c.available() > 0) {
    
    data = c.readString();
        
    println(data);
    
    String lines[] = reverse(split(data, "\n"));
    
    textAlign(CENTER);
    textSize(100);
    text(lines[0], width/2, height/2);
        
  }
}

The good news is, since I have been busy with Processing (and if all goes well) I’ll have a new interactive art piece to display at the Milwaukee Makerspace for Bay View Gallery Night.

Comments are closed.

« | »

buy the button:

Buy The Button

recently at:


top recent artists: