EnvironmentXML is no longer maintained.
It has been deprecated in favour of EEML (Extended Environments Markup Language).
A new Processing library is available for EEML
and existing EnvironmentXML feeds can be translated into EEML by subsituting '/xml/' with '/eeml/' in feed URLs
(e.g. 'http://haque.co.uk/environmentxml/live/eeml/79.xml').

EnvironmentXML library for Processing



Click here to download the latest environmentXML library for Processing.
This archive contains the library, documentation and a a fully commented example Processing template.
Unzip and place the whole folder into your Processing/Libraries folder.

Description:

EnvironmentXML is a library for Processing that enables simple access to and from the EnvironmentXML website http://www.haque.co.uk/environmentxml/ which hosts a repository of data feeds from environments, devices and objects from around the planet (well... eventually!); it also enables people to add, tag and share their own data feeds (i.e. any Processing integer or float) for others to connect to remotely.

This library makes use of the Processing's net library. XML parsing is based on proXML by Christian Riekoff.

EnvironmentXML should be placed in your Processing libraries folder. (i.e. unzip the link above, and place the entire extracted folder into the /Processing/Libraries).

Documentation below is out of date: the Environment XML library is now fully asynchronous and so there are only two classes available: DataIn and DataOut (which subsume all the methods that DataInAsynch and DataOutAsynch used to use; and which now require onRequestEnvironmentXML() and onReturnEnvironmentXML() as explained below). The example at the bottom contains all up-to-date code and the documentation remains for reference purposes regarding methods and implementation.



There are four classes available, and both operate asynchronously (i.e. the library operates in its own thread so that you can continue your programme in the foreground and only get notified when it is accessed or when new data is available):




Reference:



DataIn(remoteURL) class

This object holds data that you receive as input from a remote URL. To create it, pass a string containing the URL you would like to connect to (refer to the EnvironmentXML website to choose one).

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/79.xml"); }

Returns: none
Usage: application




Methods:

update()

This method updates your input object, in preparation for extracting the variables and tags. This should be called before each time you attempt to getTagValue() or getIdValue().

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/79.xml"); } void draw(){ dataIn.update(); }

Returns: none
Usage: application


getTagValue(String tag)

This method returns the value of the remote datastream that corresponds to a particular tag. (If the datastream contains non-unique tags, i.e. more than one stream with the same tag, use getIdValue() instead).

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/79.xml"); } void draw(){ dataIn.update(); println("value: " + dataIn.getTagValue("temperature")); }

Returns: float
Usage: application


getIdValue(int datastreamId)

This method returns the value of the remote datastream that corresponds to a particular datastream ID number.

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/79.xml"); } void draw(){ dataIn.update(); println("value: " + dataIn.getIdValue(0)); }

Returns: float
Usage: application


getAge()

This method returns the number of seconds since the XML was last seen live by the server. Default is 999999999 (i.e. very old). Useful for determining how fresh the data is.

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/83.xml"); } void draw(){ dataIn.update(); println(dataIn.getAge()); }

Returns: integer
Usage: application


printXML()

This method prints the remote environmentXML to your console; useful for debugging.

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataIn dataIn; void setup(){ dataIn = new DataIn("http://www.haque.co.uk/environmentxml/live/xml/79.xml"); } void draw(){ dataIn.update(); dataIn.printXML(); }

Returns: none
Usage: application


DataOut(parent, int port) class

This object holds data that you will serve as XML from your applet. To create it, pass parent this and port number (e.g. 5299). Remember that you may need to configure your router to allow external access to this port. You will also need to find out what your IP address is for adding it to the repository at the EnvironmentXML website; it should look something like this: "http://12.34.56.78:5299/". You can check your IP address at WhatIsMyIp.com. (Contact me for further details on how to add yourself -- it's very easy, but just not public yet).

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataOut dataOut; void setup(){ dataOut = new DataOut(this, 5299); }

Returns: none
Usage: application


Methods:

setTag(int id, String tags)

This method sets up individual datastreams and assigns tags to each particular datastream. These tags need not be unique but must be single-word (no spaces), separated by a comma, i.e. ",". You may have as many as you want (both streams and tags).

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataOut dataOut; void setup(){ dataOut = new DataOut(this, 5299); dataOut.setTag(0,"firsttag,secondtag,thirdtag"); dataOut.setTag(1,"fourthtag,fifthtag,sixthtag"); dataOut.setTag(2,"seventhtag,eighthtag,ninthtag"); }

Returns: none
Usage: application


update(int id, int value)

This method updates a particular datastream with a particular value.

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataOut dataOut; void setup(){ dataOut = new DataOut(this, 5299); dataOut.setTag(0,"firsttag,secondtag,thirdtag"); dataOut.setTag(1,"fourthtag,fifthtag,sixthtag"); dataOut.setTag(2,"seventhtag,eighthtag,ninthtag"); } void draw(){ dataOut.update(0,int(random(1000))); dataOut.update(1,int(random(1000))); dataOut.update(2,int(random(1000))); }

Returns: none
Usage: application


serve()

This method should be called quite frequently to check whether any client is trying to access your streams and to serve out current XML formatted datastreams if so. It returns a String message from the client that accessed; this message will contain the IP address of the client (and other info).

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataOut dataOut; void setup(){ dataOut = new DataOut(this, 5299); dataOut.setTag(0,"firsttag,secondtag,thirdtag"); dataOut.setTag(1,"fourthtag,fifthtag,sixthtag"); dataOut.setTag(2,"seventhtag,eighthtag,ninthtag"); } void draw(){ dataOut.update(0,int(random(1000))); dataOut.update(1,int(random(1000))); dataOut.update(2,int(random(1000))); dataOut.serve(); // or to see the message returned: // println( dataOut.serve() ); }

Returns: String
Usage: application


printXML()

This method prints the local environmentXML to your console; useful for debugging.

Example

import proxml.*; import processing.net.*; import environmentxml.*; DataOut dataOut; void setup(){ dataOut = new DataOut(this, 5299); dataOut.setTag(0,"firsttag,secondtag,thirdtag"); dataOut.setTag(1,"fourthtag,fifthtag,sixthtag"); dataOut.setTag(2,"seventhtag,eighthtag,ninthtag"); } void draw(){ dataOut.update(0,int(random(1000))); dataOut.update(1,int(random(1000))); dataOut.update(2,int(random(1000))); dataOut.printXML(); }

Returns: none
Usage: application


DataInAsynch(this, String remoteURL, int period) class

This is just like DataIn (see above) only it acts asynchronously. In other words when you start a new DataInAsynch, you provide a period (in milliseconds) for it to check for new data and update; when it receives data it calls onReturnEnvironmentXML() (required in your applet code otherwise it will fail with errors), whereupon you can use the methods below to extract values, age, etc. of the stream.

Example

import processing.net.*; import environmentxml.*; import proxml.*; DataInAsynch dataIn; int i; void setup(){ // dataIn will check for new data from this feed every 5 seconds dataIn = new DataInAsynch(this, "http://www.haque.co.uk/environmentxml/live/xml/79.xml", 5000); int i = 0; } void draw(){ // we are doing something in the foreground that needs full attention... println(i++); } void onReturnEnvironmentXML(DataInAsynch d){ // this method is called whenever updated environmentXML is available println("found: " + d.getTagValue("temperature")); println("found: " + d.getIdValue(3)); println("found: " + d.getAge()); }

Returns: none
Usage: application


Methods:

getTagValue(String tag)

Just like getTagValue() above.

Example

see above

Returns: float
Usage: application


getIdValue(int datastreamId)

Just like getIdValue above.

Example

see above

Returns: float
Usage: application


getAge()

Just like getAge() above.

Example

see above

Returns: integer
Usage: application


onReturnEnvironmentXML(DataInAsynch d)

This method must appear in your main applet code; it will be called whenever a DataInAsynch object has freshly updated XML.

Example

see above

Returns: none
Usage: application


DataOutAsynch(this, int port) class

This is just like DataOut (see above) only it acts asynchronously. In other words after you start a new DataOutAsynch, any time it receives a request from a remote client to provide remote environmentXML it will call onRequestEnvironmentXML() (which must be in your applet code otherwise it will fail with errors). It is a good idea at this point also to update your datastreams with update(). Data is then served automatically in the background.

Example

import processing.net.*; import environmentxml.*; import proxml.*; float x; float y; float z; DataOutAsynch dataOut; void setup(){ dataOut = new DataOutAsynch(this, 5213); dataOut.setTag(0,"tagone,tagtwo,tagthree"); dataOut.setTag(1,"tagfour,tagfive,tagsix"); dataOut.setTag(2,"tagseven,tageight,tagnine"); } void draw() { // main loop where are variables are getting set, reset and reset again // for all sorts of reasons x = random(1000); y = random(1000); z = random(1000); } void onRequestEnvironmentXML(DataOutAsynch d){ // this function *must* be included when using DataOutAsynch; it will // be called whenever a client requests environmentXML // It might be a good idea at this point to update your datastreams d.update(0,x); d.update(1,y); d.update(2,z); println("Client request received; we will provide: " + x + "--" + y + "--" + z); }

Returns: none
Usage: application


Methods:

setTag(int id, String tags)

Just like setTag() above.

Example

see above

Returns: float
Usage: application


update(int id, float value)

Just like update() above.

Example

see above

Returns: float
Usage: application


onRequestEnvironmentXML(DataOutAsynch d)

This method must appear in your main applet code; it will be called whenever a remote client requests envioronmentXML (which is served automatically in the background).

Example

see above

Returns: none
Usage: application



Example of a complete Processing applet with both inputs and outputs working asynchronously.

import environmentxml.*; DataIn dataIn; DataOut dataOut; float x; float y; float z; void setup(){ // dataIn will check for new data from this feed after 5 seconds dataIn = new DataIn(this, "http://www.haque.co.uk/environmentxml/live/xml/79.xml", 5000); // dataOut will serve the following feeds when accessed dataOut = new DataOut(this, 5213); dataOut.setTag(0,"tagone,tagtwo,tagthree"); dataOut.setTag(1,"tagfour,tagfive,tagsix"); dataOut.setTag(2,"tagseven,tageight,tagnine"); } void draw(){ // we are doing something in the foreground that needs full attention... x = random(1000); y = random(1000); z = random(1000); } void onReturnEnvironmentXML(DataIn d){ // this method is called whenever updated remote environmentXML is available from your dataIn remote URL println("found: " + d.getTagValue("temperature")); println("found: " + d.getIdValue(1)); println("found: " + d.getAge()); } void onRequestEnvironmentXML(DataOut d){ // this function will be called whenever a client requests your local environmentXML // i.e. your dataOut streams // It might be a good idea at this point to update your datastreams because straight // after exiting this function the dataOut object will automatically serve your datastreams d.update(0,x); d.update(1,y); d.update(2,z); println("Client request received; we will provide: " + x + "--" + y + "--" + z); // depending on where you are accessing from, you may be able to extract information // including IP address // of the remote client with the following: println(d.serverMessage()); }