Writing to Google Docs with MaxMSP and a Leapmotion

in data •  9 years ago 

Leapmotion

When I was doing an internship we had an opening of a project called Smartware. It’s a series of interactive vitrines where companies show their innovative business and where users can read and browse through a menu. A Leapmotion ( works like a kinect ) lets you browse though menu’s and watch videos in the vitrines. All the vitrines we built run on MacMini’s and run a Max patch.

One of the other interns is busy doing interaction research and we needed data. We want to know how long people take before they understand how the Leapmotion works and how long people stay in a certain menu. So i was asked if i could find a way to log the data and write it into a file.

I asked my colleague how the data was going to be processed and found that it would eventually end up in an Excel sheet. Recently i worked on an online survey where i posted data into a Google spreadsheet. I found a piece of code by Martin Hawksey where you can use a POST or GET method to insert data into Google Docs.

Shell & cURL

Max has a Shell tool where you can send commands to your Mac terminal. Thanks to Russau for his answer at stackoverflow.com i found cURL. The cURL function comes standard with Apple OSX and it can submit data via POST method and can even simulate a < form >.

Combining the Max Shell, cURL and Martin’s code i am now able to POST data to a Google Spreadsheet.

Setting up Google spreadsheet

It is important to do it in this order!

Create a new Google Spreadsheet and change the SHEET name (not document name) to DATA. In the first row set the column title. In my example we are using: date, time, message, count.

Go to Tools -> Script editor. This will open a new window and choose Blank Project. Now copy Martin’s code in here.

Beware that we are using POST method to submit data!

function doGet(e) { // change to doPost(e) if you are receiving POST data

Change this to:

function doPOST(e) { // change to doPost(e) if you are receiving POST data

And make sure you replace app with undefined at line 49.

Now that we have a script we can run and publish our project. Go to File -> Save and it will prompt for a save, anything is good. Now we need to Authorise our project, go to Run -> SetUp and you will see it execute and ask for authorization. Continue here and accept the authorization. Now we repeat the last step to setup the app, go to Run -> SetUp and we’re almost ready to go.

Now we are ready to deploy as web app and post data to the spreadsheet. Go to Publish -> Deploy as web app and make sure you have the same options as below and click the Save New Version button. Now we can hit the Deploy button.

Google gives us a Current web app URL that looks like this: https://script.google.com/macros/s/RANDOM-ID/exec. We need this later in our Maxpatch.

Now that we have setup Google Docs we can continue to Max.

MaxMSP

For this to work you need the Shell tool for Max. We are going to use this to send cURL commands to the terminal. Here is where the first row of our Google Document comes in. The data was date, time, message and count. The example Maxpatch below sends current date, current time the message “awesome” and a simple incremental counter. Make sure you MATCH the row data with the data you are sending via curl, so in my example:

cURL command

curl -d date=04-30-2014 -d time=13:10:07 -d message=awesome -d count=1 https://script.google.com/macros/s/RANDOM-ID/exec

You can also use -F to simulate a html form. Beware of case! You can find more curl commands here.

And it matches the first row of my spreadsheet: date, time, message, count.

Below is the maxpatch file. Copy it and open from clipboard in Max.

----------begin_max5_patcher----------
1285.3oc0ZszabaCD97t+JHDPNUaujh5oALPCfuzCoEn2JJBBzClcYhdAQpX
6Fj+6UjTxV1YUknrV5svXs7LKWoY932LblY822twJt7dByBbM3uAa178sa1H
UITroSdiUdz8IYQL4xrRJyyIEbqKTuGmbOWpmkQ2efCRIYQO.3k.FgCxILVz
dBHljUd2E.9ARAHNpXOf93m+ykEbF8eHh6Ax9JXu558wBUvG0TEwSNPK1+oZ
RBWYvgh2E3D5ItX6GJu3bED7wtOSQSNsHivkVNpSYbSbbFYnFZpzCJi+xkX3
PCqHJWtPq2WSixrd5tV1v6usPgxercq3WW7JwvjxpG.OT1TC1WVtOi.XI0zJ
NHiV7UvARMYMPMOOId4z94bawKHZEfM6PS.aEj6ZeX+DponbHHbBz4HXAJTf
AcLHOrDIfigD1Gwucz0u6AOkJ9CUDkkXIhKr.ebAvRWT1OylZpy.WlBRi3ja
fNsb6Ka2scDp3zbxMH70H30Peght6wMQ2QXk4DgpjxlB9MHvANuhc8tcJt3U
Jl4UsT3c4QI0krcrc+46+8a+iOb4uc6Nx8jD82F7bDaCtAhEA7gNhKn.c1Gv
q19vx1CFgZFCvKEMBfJvXBR4wBFQ5BF3+SR4Eu35pRR6Hb5iRtsXhH+kJp0y
VaNCJ3MlyLFjHN4bA4x7CTG.BkPA1We.w4sNHpIOlTuDOWdTF1U5ytPsiXlw
oWUQ0s54j5OQJh5NHDdTPwdLPgJNw+0DCMRRleAfV.l4DHwLXfjszUKfFrEb
3pwVD.yZBHzECGcYSVBb3e1BGMEUQIeE.E+rzSi5.Fajq1AWN9q1wQcQPCtr
l3TaIMwzBB3VvkfOz95u.+ZUTZZKb.rawN4qkhecwYShetGA+z9bpQy.IPsy
Hpkcn8PtELT+Rc79eF25PqPd6K1pvs5.vdx0T.3QHWHzY.4ZrBgDcorfd5fx
B.PNxl5vX8qCx67rYBQebKN+shanvDsBwPtqVHVFkICt5ut3frwHLuFDpmun
eymnyzlOYU0sH7mAOaN.ui8X++p+ruyekjpo+2wV74bpZvmrsUmi.ivfySbT
Bi.wL6hJR0GXBcE.SGhDpeyI9lXzZwMbdYg0TSJCEza9Z5DdFaZXS5IX09A1
agthiwbkwhqOPxxV5rN63gX8qiecqTX0QknpJRQp4lVoSWmypAsnWUqmn7bR
Cn8z0hW9M5HcBg9mCqrxl5j9aUWTJ3I2Hkv3zhHNsMb5o0HF48fEcfllRJFN
MjTJSLfjzwSEsplCxXlinQrIsG4oXlxf7mgA4Lk8jSSqJaOgi0OIDIeNPNOj
ABO8XVW6GMG62d91Ox2dfCLT5T4A1ywCbluGX6CG3ACkNAdfXLdSxgBMFkdV
lC947looztcopUekJgxu3fmKYqVhuO5Qo2JvVkAAaF3dNYPvla62dNo7QH8x
nggCyHLT5DrEK8.zb7.MxogC8G5ACjNUdf8b7.Mxo4DNbOXnzovCblSgCXyw
pwyvd7OuLGyUVkMZF7MruYsmIifCLq8L41k2Yl8Xvnq4FrizsHXGe4+aT9tg
OJcBxVgleaE1FAPQy5PXWisA+hG0HEY6aV6YpDD1lKfD4L2ZlMj8fOy3OnYG
fgLiAAmSHus4.n4zF9BsF0Lohpp9Fol0cKkFhUdzWJqEhdWHEoEJQ4vtrpIe
i1ud0BhpSNP4jDdSsZfY2G3YsU7b9w1+E3qoP+.
-----------end_max5_patcher-----------

Now every time i bang, i get a new line in my Google spreadsheet.

Good luck writing to Google Docs!

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Every time you bang (an intern)?

Seriously though, cool post and details - I read this because I've got a leapmotion.. But that shyamalan twist was confusing :P

Haha, in MaxMSP everything is visual programming and everytime the code goes down the nodes and gets executed it is called a bang!