Monitor with GoogleDrive (App Note)
If you own a LabJack device, have Python installed, and have a Google account, you may find this App Note to be of interest. You can create a program that posts collected data to a Google Sheets spreadsheet so you can view your collected data from anywhere, for free!
Google Sheets Logging with Python 3
The program below was contributed by Darby Bates of University of Toronto and is adapted and maintained by LabJack Corporation engineers.
Follow these steps to log data from a LabJack device to a spreadsheet with the Python 3 Google API:
Ensure that you have a distribution of Python 3 installed.
Ensure that you have the LabJack LJM Python package installed.
Ensure that you have the other necessary Python packages installed including gspread and oauth2client.
Download and unzip the example Python logging script. Ensure that you have downloaded the proper Python script (
T7Pro_GoogleSheet.py
) and not the deprecated Python 2 script from the second section of this App Note.Login to the Google devolopers API console with your Google account.
From your Google API dashboard, click
CREATE PROJECT
.Name your project (this name cannot be changed later so double check spelling, formatting, etc.). Then click
CREATE
.For your new project, click
+ENABLE APIS AND SERVICES
.In the Search for API's & Services search box, search for "Google Sheets API" and then after selecting the API, click
ENABLE
.Similarly, in the Search for API's & Services search box, search for and enable the "Google Drive API".
From the same project, from the Navigation menu (the three horizontal lines in the top left of the console) navigate to APIs and Services > Dashboard.
Select the Credentials tab on the left hand side of the console and then click
+CREATE CREDENTIALS
.In the credentials creation menu, select Create service account. Then name your service account and click
CREATE
.In the service account permissions menu under role, select
Project
→Editor
and clickCONTINUE
.Select
+CREATE KEY
and choose to download the key inJSON
format.Place this downloaded key in the same directory as the example python script and rename it as
client_secret.json
.With your Google account create a new Google Sheet, and give it a unique name.
Enter this unique name in line 22 of the python script:
SPREADSHEETNAME = 'LJ Test Sheet' #Edit spreadsheet name here between the '' characters, replacing LJ Test Sheet with your sheet's unique name.
From your Google API dashboard for the same project created in step 7, select the Credentials tab on the left and then under service accounts, click on the service account created in step 13. Copy the email address in the email text box. This email can also be found in the downloaded JSON file in the field client email.
Then, in your Google sheet created in step 17, share the sheet with email address of the service account, and give it edit permissions.
Now, the Google sheet, the APIs, and the service account should be formatted correctly and the program is ready to run. Navigate to the directory that contains the example python script and the renamed JSON key and run the python script.
If the script ran correctly, the second row of your Google sheet should now contain a timestamp, and the values read from AIN0, AIN1, and AIN2 from your connected LabJack device.
Every time that the script is run, the second row of the sheet will be updated and all older data will be pushed down one row.
Google Sheets Logging with Python 2 (Deprecated)
Follow these steps to log data from a LabJack device to a spreadsheet with the Python 2 Google API and a U3
Make sure that LabJackPython is installed.
Download and install Google's Python API.
Try Google's API example located in the root directory and then samples/spreadsheets to make sure you installed it properly
to run:python spreadsheetExample.py --user [yourUserName] --pw [yourPassword]
The program should display all of the spreadsheet files created in your Google Drive account, and let you open and change values of the file.
Download the example program that opens a U3 device and stores information to a created Google Drive spreadsheet.
Create a spreadsheet and modify the example program's
SPREADSHEET_NAME
,WORKSHEET_NAME
,GOOGLE_USER_NAME
, andGOOGLE_PASSWORD
string constants.If needed, change the LabJack device being opened. The program was written for a U3, so change U3s to U6s or UE9s.
Run program!
Two Step Verification
Do you have two step verification enabled on your account? If so you need to generate a new application-specific password and use that as your password for the example program.
Files
googleDocsSpreadsheetExample.py_.txt