import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Element;
import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
Serial myPort;
String waarde = "0";
int number = int(trim(waarde));
// this is the webpage containing the relevant data
String url = "http://iphone.bjair.info/m/beijing/mobile";
// this is the path in the resulting expression that leads to the data of interest
String path = "#number h1";
int refresh = 20; // sec
int walkingTime = 6; // min
void setup() {
size(200, 200);
background(0);
println(Serial.list());
myPort = new Serial(this, Serial.list()[0], 9600);
noStroke();
smooth();
frameRate(1/(float)refresh);
draw();
}
void draw() {
// the data extraction is done in the function getTimeUntilNextBus()
Integer timeUntilBus = getTimeUntilNextBus();
// the rest here is only to calculate the leaving time that is needed to
// catch the bus
if(timeUntilBus != null) {
//int diff = timeUntilBus - walkingTime;
println("Time until leave: "+timeUntilBus);
}
/*
}
Integer getTimeUntilNextBus() {
// doc contains the result from the website request
Document doc;
// this is the actual request, including error handling, simply copy this
try {
doc = Jsoup.connect(url).get();
} catch(IOException e) { // Connection error
e.printStackTrace();
doc = null;
} catch(IllegalArgumentException e) {
println("Bad URL!");
doc = null;
}
if(doc != null) {
// this is the command that selects the data from the result expression
Element data = doc.select(path).first();
waarde = data.text();
println(waarde); //here it gives the number in the string which is around 200.
println(number); //here it should give the same number as an integer.
while(number > 100){
myPort.write(1);
}
return 4;
}