We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › unstable installation: html to arduino
Page Index Toggle Pages: 1
unstable installation: html to arduino (Read 839 times)
unstable installation: html to arduino
Feb 26th, 2008, 12:13am
 
hi all,

im running a processing sketch reading a simple .html document from a webpage, playing audio with ESS and controlling an arduino board with simple message system

it works great, but when running for a longer time i get this error msg:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
java.lang.NullPointerException
at Temporary_5174_7427.draw(Temporary_5174_7427.java:53)
at processing.core.PApplet.handleDisplay(PApplet.java:1465)
at processing.core.PGraphics.requestDisplay(PGraphics.java:690)
at processing.core.PApplet.run(PApplet.java:1562)
at java.lang.Thread.run(Unknown Source)

it looks like network problems - - is there a way to suppress these so the program wont go to a halt??
can anyone help please??

best,
jacob

the following is the processing code

import processing.serial.*; //serial communication
import krister.Ess.*; //ESS sound package
AudioChannel[] mySound = new AudioChannel[1]; // One channel of audio playback

Serial port; // The serial port
PFont font; // Text display variables
String serialString = ""; // Serial variables
boolean output13 = false; //Output PIN variables
boolean change = false; //bool to check for change
String URL = "http://sl.accidentdesigns.com/taggingart/memslot/switch.html"; // URL to read from
String[] data; //to store data from URL

void setup() {
// GRAPHICS SETUP
size(300, 200);
font = loadFont("Ziggurat-HTF-Black-32.vlw");
textFont(font);
background(51);
text("status:"+output13, 15, 30);

// SERIAL / ARDUINO SETUP
// Print a list of the serial ports, for debugging purposes:
println("Serial ports");
println(Serial.list());

// the arduino is normally the second port
print("Selected port: ");
println(Serial.list()[2]);
port = new Serial(this, Serial.list()[2], 9600);

Ess.start(this); // Start Ess
// Load sounds and set initial panning
// Sounds must be located in the sketch's "data" folder
mySound[0] = new AudioChannel("Netfilm.mp3");

}

void draw() {
// GET SERIAL DATA
while (port.available() > 0) {
  serialInput();
}
data = loadStrings(URL);  //read data from URL
//println(data[0]);
print(data[0].charAt(31)+" "); // character at line 0, position 31 in string is status (0/1)
char dummychar = data[0].charAt(31);
if (dummychar == '1'){
  output13 = true;
  if (mySound[0].state == Ess.STOPPED) {
    mySound[0].play();
  }
} else {
  output13 = false;
  mySound[0].stop();
}

if (change != output13) {
  background(51); // clear screen w/ dark grey
  text("status:"+output13, 15, 30);
  change = output13;
}

setOutput13();
delay(500); //wait 0.5 sec

}

void getAnalogs() {

port.write("r a");
port.write(13);

}

void getDigitals() {

port.write("r d");
port.write(13);

}

void setOutput13() {

port.write("w d 13 "); // NOTE THE SPACE TRAILING THE 13

if(output13==true) {
  port.write('1');  //NOTE THAT WE ARE SENDING A STRING AND NOT AN INTEGER

} else {

  port.write('0');  //NOTE THAT WE ARE SENDING A STRING AND NOT AN INTEGER

}

port.write(13);

}

void serialInput() {
serialString = port.readStringUntil(13);
if (serialString != null) {
    //println(serialString);
    //textDisplayed = serialString.substring(0,serialString.length());
  }
//processByte((char)port.read());
}

Re: unstable installation: html to arduino
Reply #1 - Feb 26th, 2008, 10:32am
 
ha!
i think i nailed it :)
by bringing in a simple null check, like this

if (loadStrings(URL) != null){
  data = loadStrings(URL);  //read data from URL
  dummychar = data[0].charAt(31);
}

but now i get a different error every 30 minutes or so (i think when my internet connection is too slow / unstable)

java.net.ConnectException: Connection timed out: connect
     at java.net.PlainSocketImpl.socketConnect(Native Method)
     at java.net.PlainSocketImpl.doConnect(Unknown Source)
     at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
     at java.net.PlainSocketImpl.connect(Unknown Source)
     at java.net.Socket.connect(Unknown Source)
     at java.net.Socket.connect(Unknown Source)
     at sun.net.NetworkClient.doConnect(Unknown Source)

since this installation is going to run for 2 weeks, i would still love to implement some kind of bug catch for this - - is this possible with making a catch routine?? maybe something like the following (taken from http://processing.org/learning/libraries/yahoosearch.html )

// Error handling below, see the documentation of the Yahoo! API for details

catch (IOException e) {
 println("Error calling Yahoo! Search Service: " + e.toString());
 e.printStackTrace();
}

but catching EVERY possible error??
Re: unstable installation: html to arduino
Reply #2 - Feb 26th, 2008, 10:59am
 
all exceptions extend the Exception class, so this would catch everything :

Code:
try {
// your code
} catch(Exception e) {
// handle any exception which would be thrown above
}
Re: unstable installation: html to arduino
Reply #3 - Feb 26th, 2008, 11:43am
 
thank you antiplastik
i did a little clean up in the code and tried to implement your tip in the following - - try {} catch {} is in void getstate()

Code:
import processing.serial.*; //serial communication
import krister.Ess.*; //ESS sound package
AudioChannel[] mySound = new AudioChannel[1]; // One channel of audio playback

Serial port; // The serial port
PFont font; // Text display variables
String serialString = ""; // Serial variables
boolean output13 = false; //Output PIN variables
boolean change = false; //bool to check for change
String URL = "http://sl.accidentdesigns.com/taggingart/memslot/switch.html"; // URL to read from
String[] data; //to store data from URL
char dummychar = '0';
boolean flipflop = false;

void setup() {
// GRAPHICS SETUP
size(300, 200);
font = loadFont("Ziggurat-HTF-Black-32.vlw");
textFont(font);
background(51);
text("status:"+output13, 15, 30);

// SERIAL / ARDUINO SETUP
// Print a list of the serial ports, for debugging purposes:
println("Serial ports");
println(Serial.list());

// the arduino is normally the third ([2]) port
print("Selected port: ");
println(Serial.list()[2]);
port = new Serial(this, Serial.list()[2], 9600);

Ess.start(this); // Start Ess
// Sounds must be located in the sketch's "data" folder
mySound[0] = new AudioChannel("Netfilm.mp3");

}

void draw() {

getstate(); // read from URL
setOutput13(); // set pin according to URL state
flipit(); // update progress cursor

delay(500); //wait 0.5 sec
}

void getstate() {
try {
if (loadStrings(URL) != null){
data = loadStrings(URL); //read data from URL
dummychar = data[0].charAt(31);
}
if (dummychar == '1'){
output13 = true;
playsound ();
} else {
output13 = false;
mySound[0].stop();
}

if (change != output13) {
background(51); // clear screen w/ dark grey
stroke(255);
fill(255);
text("status:"+output13, 15, 30);
change = output13;
}

} catch(Exception e) {
print("caught one exception: "+hour()+":"+minute()+":"+second()+" ");
delay(1000); // if error wait 1sec and try again
return;
}
}

void playsound () {
if (mySound[0].state == Ess.STOPPED) {
mySound[0].play();
}
}

void flipit () {
if (flipflop == true){
stroke(255);
fill(255);
rect(15,35,20,20);
} else {
stroke(51);
fill(51);
rect(15,35,20,20);
}
flipflop = !flipflop;
}

void setOutput13() {
port.write("w d 13 "); // NOTE THE SPACE TRAILING THE 13
if(output13==true) {
port.write('1'); //NOTE THAT WE ARE SENDING A STRING AND NOT AN INTEGER
} else {
port.write('0'); //NOTE THAT WE ARE SENDING A STRING AND NOT AN INTEGER
}
port.write(13);
}

some exceptions i catch but i still get some network errors:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)

-- shouldn't this be caught? and once caught shouldn't the program just wait 1sec and then try again?
Re: unstable installation: html to arduino
Reply #4 - Feb 26th, 2008, 2:10pm
 
I'm not an expert in exceptions, but I think what you get is a stack trace, which means the ConnectException has already been caught (by the socketConnect() method I guess).

You should be able to catch it again if the method which caught it (socketConnect()) finally throws it later. But maybe it is not the case. Maybe it just catches the exception and stop?

Does your sketch stop after the error message? Or is it still running?
Re: unstable installation: html to arduino
Reply #5 - Feb 26th, 2008, 3:15pm
 
it stops Sad
if it just continued running i wouldnt mind a few error msgs
Re: unstable installation: html to arduino
Reply #6 - Feb 26th, 2008, 11:53pm
 
i get some funky java error msgs
it seems like some low level communication errors --- can anyone help me decode them?

here´s another one:

java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at sun.net.www.http.HttpClient.parseHTTPHeader(Unknown Source)
Re: unstable installation: html to arduino
Reply #7 - Jun 26th, 2008, 7:58pm
 
Did you ever find a solution to your problem? I'm running into the same thing.
Re: unstable installation: html to arduino
Reply #8 - Jun 30th, 2008, 1:19pm
 
yes, i switched the location of my php script to a faster webserver. this solved it. so i think that the error was low-level java problems in relation to slow server responses, but i never got a fulfilling explanation to the problem. on 2 out 3 webservers it still caused problems....
you can see the final processing code on this wiki:
http://wiki.accidentdesigns.com/index.php/Memory_Slot
Page Index Toggle Pages: 1