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 & HelpIntegration › Which way is simplest
Page Index Toggle Pages: 1
Which way is simplest (Read 1179 times)
Which way is simplest
Oct 22nd, 2007, 4:51pm
 
Hello,

I'm scoping a project that could be achieved in a number of ways and I was hoping that I could get some suggestions from the list about the easiest/simplest way to achieve it.

In summary: I need 20 or so users to be able to set the brightness of 20 corresponding LEDs from the web.

They will use some sort of web interface to set individual variables (ie, user1 = 1, user2 = 14, etc). The vars will be updated as often as they wish, which could be as fast as a few times a second. These variables will be sent to some arduinos which control the brightness of 20 LEDs. I have one Mac G4 that will have a USB hub attached running the arduinos - that bit is not the topic of this post. My question is how to get the data from the users to the machine running the arduinos.

A few options I've already thought about:
* Processing applet running in a browser writes a text file containing the data to a webserver, arduino machine reads text file from server. Possible problems with speed of update, and multiple users simultaneously changing their data value.
* users post to some other web interface (blog or similar), which creates XML file/feed which is read by the arduino machine. Problems: how to create the XML file? How to read?
* processing net library client/server model (does this work if server is behind firewall, which might be the case?)
* post/get in HTTP page writes to mySQL database, read by arduino machine using the mySQL library. Problems: don't know where to start with mySQL!

As a comparative newbie, I'm going to have a steep learning curve whichever method I use, so I'm keen not to go down any dead ends at this early stage. I have the option of using Processing, Max/MSP or, if I really have to, Flash.

Any help gratefully received, as are pointers as to where to start.
With best wishes,
m


Re: Which way is simplest
Reply #1 - Oct 28th, 2007, 1:57am
 
I would take a look at OSC. Open Sound Control, which is used for a lot of such things and generally plays well with all software.

For Processing:
http://www.sojamo.de/iv/index.php?n=11

Max/Msp:
http://www.cnmat.berkeley.edu/OpenSoundControl/Max/

Also Jitter has it's own native matrix send/receieve, which might be overkill:
http://www.cycling74.com/documentation/jit.net.send
http://www.cycling74.com/documentation/jit.net.recv
Re: Which way is simplest
Reply #2 - Oct 28th, 2007, 9:16am
 
you might want to take a look at tom igoes new book Making Things Talk which has examples of communicating with web pages, and is full of processing and arduino examples.

HTH

Nick
Re: Which way is simplest
Reply #3 - Oct 29th, 2007, 5:58pm
 
Thanks fot the tips. I'll be getting that book for reference purposes I think.

I'll take a look at OSC and report back if it works. I'm a little nervous about using 'direct connection' methods to do the job (if that makes sense!), mainly because I don't yet know how far behind firewalls and routers the arduino computer will be. I've had trouble getting sysadmins to clear a route to a specific computer in the past.

That said, I'm probably going to hedge my bets and try and get a couple of methods up and running - one of them is bound to work.

Thanks again, and please keep advising!
m
Re: Which way is simplest
Reply #4 - Feb 4th, 2008, 11:49pm
 
Hello,

For your information, we realised the project by getting someone else to write some PHP that updated a mySQL database. It's not the ideal solution in many ways, but it does give us the option of recording every change that takes place, and to be able to map this in time after the event is potentially very useful.

There is a database output that is read by a Processing applet, which we initially used loadStrings() for. This was fine as long as the internet was fine, but as soon as the connection timed out or did something else unexpected, the applet crashed. We solved this by getting a try/catch script off someone else. This is perhaps the most annoying part of the project - having to rely on other people's more sophisticated code makes it really hard to troubleshoot.

In case it's useful to anyone else, I've quoted the try/catch section here.

Quote:


import java.net.*;//import the library you need
import java.io.*;void testURL(String myURL) {
 retVal="";

 //try and get the url - if you can't get the local one
 //stick it all into lines array
 if(check.checked != true) {
   try
   {
     println("getting page...");

     URLConnection urlConn =       new URL("http://www.yoururl.com/yourdata.php").openConnection();    //put your url here
     urlConn.setUseCaches(false);  

     InputStream in = urlConn.getInputStream();
     byte buf[] = new byte[4096];
     int nSize = in.read(buf);
     while(nSize>=0)
     {
       retVal=retVal+new String(buf,0,nSize);

       nSize = in.read(buf);
     }

     lines = splitTokens(retVal);        // this is splitting what we get into an array
     // this is debug
     // for(int lop=0;lop<lines.length;lop++){
     //   println(lop+": "+lines[lop]);
     // }
     indicator = color(100);            // screen to grey
     println("Success.");
   }
   catch(Exception e)
   {

     retVal="in exception";

     // print error message
     println("Exception: "+e.getMessage());
     println("NO INTERNET, using local file." + nf(h, 2) + ":" +nf(m, 2)+":"+ nf(s, 2) + ", " + d +"/"+mon+"/"+y);   // report to console
     myURL =  "/data/levels.txt";            // so USE LOCAL FILE
     lines = loadStrings(myURL);

     indicator = color(200,0,0);            // screen to red
   }
 }   else  {                                                    // if checkbox == true
      myURL =  "/data/levels.txt";            // so USE LOCAL FILE
   lines = loadStrings(myURL);
   println("NO INTERNET, Checkbox checked. " + nf(h, 2) + ":" +nf(m, 2)+":"+ nf(s, 2) + ", " + d +"/"+mon+"/"+y);      // report to console
   indicator = color(200,0,0);                              // screen to red
 }

}

Page Index Toggle Pages: 1