Web Visit Information into Max

    Sep 04 2011 | 1:25 am
    Hello Forum,
    I'm currently undertaking a project which uses QRcodes as the seeds for generative synthesis, the idea being that the code links to an audio visual piece generated from the very information that got you there.
    I am wondering if there is a way for Max to receive visit information from a website, a band is all i need for my purposes. I want to have a code displayed on screen (A), and next to it its generative output on screen (B), so when someone scans the code and is redirected to the corresponding site, the result will be played on screen (B) and a different code will display on screen (A)
    I'd love some help as the exhibition is opening in three weeks!
    Thanks a lot

    • Sep 04 2011 | 10:21 pm
      You can download files from online using [jit.uldl] so that might be worth a look to see if it will fit your needs. There's a great example in the [jit.str.regecp] helpfile called "parser/downloader".
    • Sep 05 2011 | 4:16 pm
      I tried adding jit.str.regecp to a patch and my max install says "no such object". Do I need to download and install this seperately perhaps? I'm using Max 5.1.8 on OSX Lion.
    • Sep 05 2011 | 9:43 pm
      Ah the problem is me being unable to type on my dying Macbook. Try [jit.str.regexp] and you might have more luck!
    • Sep 16 2011 | 1:23 am
      thanks for the advice, i've had a look at the jit.uldl and i don't think this will help because what i really need is a bang whenever the page is visited. Perhaps if there is a way for the page to generate a new image whenever it is hit which i can then get into max with the jit.uldl, that could be used, but i have no idea if this is possible.
      I've done some reading and it seems Java might be an option.
      Thanks again.
      ps. i thought i'd get an email notification when someone responded to my post, hence the delay in reply.
    • Sep 16 2011 | 3:38 am
      My preferred approach to this would be to use php or similar on the webserver. Whenever the page is hit, a small php script would send a udp packet to the (known?) ip address of the machine running max, picking that up in max with [udpreceive] and responding accordingly.
      If the receiving machine is behind a dsl/cable modem or some other router, you'd probably need to set the router to redirect the incoming udp port from the router's public ip to the max-machine's internal network ip.
      This would avoid repeatedly polling a remote server with jit.uldl. It would be simple to respond to on the Max end, you receive one udp packet per page hit, in near-realtime.
      If you have to poll the server, I think I'd have a php script on the public QR-code page that just writes the current timestamp to a logfile when the page is hit.
      Setup a second page with a php script which reads that logfile and prints the timestamps to the page, then empties the logfile. Have jit.uldl poll that page every couple of seconds, and compare the last timestamp you have stored in Max to each of the received timestamps. If any received timestamp is greater than the stored one, store the new one and do whatever you need to do. You could queue/delay your output accordingly if you get more than one timestamp per poll request.
    • Sep 18 2011 | 7:07 am
      Hey John,
      Thanks for such a comprehensive reply, The PHP approach seems to be exactly what i'm looking for, however i'm going to be running this off the gallery's wifi, and i'm not too keen to sort out all that routing, an then transfer systems, on the morning of the opening. So it seems polling the server might be a better option for me.
      I'm alright with HTML, but PHP is not something i have ventured into yet, do you know of any sites that may lead me int he right direction?
      Thanks again for your input, i'm now, finally, confident that i can pull this off.
    • Sep 18 2011 | 9:47 am
      is great for learning all things Web. They give a good start in any area, then you can go to more detailed resources if you need.
    • Sep 18 2011 | 9:38 pm
      Setting up and testing the routing on opening morning is definitely not advisable, you'd want to have that sorted well in advance and tested through a few days of shutdowns and power-outs.
      If you need help with the php, post here, it's what I do for a living and I can probably customize a couple of quick log write/read scripts that will do what you want.
      First make sure the webserver you'll be using lets you run php scripts.
      Second, the php script needs to be able to write to a file, so either the webserver needs to be running as the same user as your ftp account (common for shared hosting anyway), or the webserver needs write permission for a directory, preferably one outside the public web folder.
    • Sep 19 2011 | 12:31 pm
      Hey John,
      I really appreciate your offer to customise a couple of scripts! I'm fascinated with the possibilities of harvesting web information to drive patches, but with this deadline looming, and my very limited knowledge of networking, it looks like i may have to dive into that aspect in earnest at a later date... possibly while sitting the exhibition :)
      i've been plugging away with some basic PHP, and I got a page to display a timestamp to test the server was enabled, so tick there. I've also been trying to write a log file, but so far without any luck. i'm not sure exactly what you mean by "the webserver needs to be running as the same user as your ftp account", is this a preference i can set? I use cpanlel to upload to the server... i can use ftp but i don't have it setup yet. Is there a way to test this?
      Once again, thanks heaps.
    • Sep 19 2011 | 11:19 pm
      The webserver will either be running as your user (common in shared hosting), or it may be running as its own user (possibly www or www-data or something like that).
      I think cPanel gives you a file manager screen where you can set file ownership and permissions?
      As a test, this php code should create an empty file (the first time it is run) if the webserver has write permission in the directory, and will print a message of success or failure:
    • Sep 20 2011 | 12:03 am
      To write and read the timestamp logfile I would use something like this. Note I haven't tested this specific code.
      Public QR-code destination page:
      Page to check with jit.uldl:
        // read in entire logfile contents
        if (($file = file_get_contents(LOGFILE)) !== FALSE) {
          // convert any existing timestamps to array
          $timestamps = unserialize($file);
          // print timestamps to page
          foreach ($timestamps as $timestamp) {
            print $timestamp . SEPARATOR;
          // clear the logfile
          fopen(LOGFILE, 'w');
        else {
          print 'Could not get contents of logfile';
    • Sep 20 2011 | 11:37 pm
      Hey Mate,
      Thanks heaps fo the codes, I had a play with them last night and was able to get the logfile written. I polled the other file and got the info! It seemed that the "read" file was returning a warning if it was polled twice without having been written to in between, so i just compared the files as they came and if they didn't match, ie no warning, i knew the page had been read.
      I've just deleted a fairly lengthy explanation of an issue i was having this morning, but it turns out i just had to open up the permissions for the log file.
      I'm planning on having multiple files writing to the logfile, do you think that will be an issue, i can't really see any reason it would but i thought i'd check.
      You're not in Melbourne by any chance are you? if so it'd be great to see you at the opening on Tuesday night so we can thank you in person. The details are on...
      Also, i work as a Video editor and Animator, if i can ever lend a hand to any of your projects please let me know.
    • Sep 21 2011 | 3:38 am
      Close, I'm in Auckland. Might be in Melbourne next April/May to go climbing, a bit late, but.
      Only one script can have a file open for writing at a time, but the script should read and write fairly rapidly and closes the file as soon as it's done either. If you get to the point where there are thousands of log entries backing up then read/write time will be higher and you might have problems. As long as jit.uldl polls often it should stay fairly short.
      Was the error this one:
      else {
          print 'Could not get contents of logfile';
      If so just delete that bit of code and you'll get nothing if the logfile is empty. I wasn't sure if file_get_contents() would return an empty string or FALSE for an empty logfile.
      Exhibition looks interesting, wish I could be there. Feel free to pass my details on to others who might be needing realtime web-integration for art, it's an area I'd like to do more work in. johnp at opuslocus.com