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?