Difference between revisions of "EBC Exercise 37 Logging to Sheets"
m (→Python) |
m (→Run the example: Python first) |
||
Line 26: | Line 26: | ||
== Run the example == | == Run the example == | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Python === | === Python === | ||
* Edit '''demo.py''' and change the '''sheetID''' string to the string you noted above. | * Edit '''demo.py''' and change the '''sheetID''' string to the string you noted above. | ||
Line 41: | Line 34: | ||
The first time you will have to paste a URL into your browser and paste a string back | The first time you will have to paste a URL into your browser and paste a string back | ||
to the Bone. You can leave off the '''--noauth_local_webserver''' after the first time. | to the Bone. You can leave off the '''--noauth_local_webserver''' after the first time. | ||
+ | |||
+ | === JavaScript === | ||
+ | * Edit '''demo.js''' and change the '''sheetID''' string to the string you noted above. | ||
+ | * Then, run the example on your Bone. The arguments are the values to be logged on the sheet. | ||
+ | bone$ '''./demo.js 3.14 10''' | ||
+ | |||
+ | The first time you will have to paste a URL into your browser and paste a string back to the Bone. | ||
== Plot the Data == | == Plot the Data == |
Revision as of 06:48, 28 October 2020
Embedded Linux Class by Mark A. Yoder
Here are instructions on how to log data to a Google Sheet from JavaScript or Python.
Contents
Create a new Sheet
Create a new sheet by:
- Going to https://sheets.google.com and clicking to Start a new spreadsheet, Blank
- Give the sheet a meaningful name
- Enter some column labels
- Note the sheetID in the path
Get Credentials
Go to the class repo and change to the sheets directory
bone$ cd exercises/iot/google/sheets
If you are using JavaScipt, go to https://developers.google.com/sheets/api/quickstart/nodejs and follow steps 1 and 2.
If you are using Python, got to https://developers.google.com/sheets/api/quickstart/python and follow steps 1 and 2.
Either way put the credentials.json file in the sheets directory.
Run the example
Python
- Edit demo.py and change the sheetID string to the string you noted above.
- Run the example on your Bone. The arguments are the values to be logged on the sheet.
bone$ ./demo.py --noauth_local_webserver bone$ ./demo.py 3.14 10
The first time you will have to paste a URL into your browser and paste a string back to the Bone. You can leave off the --noauth_local_webserver after the first time.
JavaScript
- Edit demo.js and change the sheetID string to the string you noted above.
- Then, run the example on your Bone. The arguments are the values to be logged on the sheet.
bone$ ./demo.js 3.14 10
The first time you will have to paste a URL into your browser and paste a string back to the Bone.
Plot the Data
Go to your Google sheet and the new data, and a time stamp should be there.
- Select the A column and select Format:Number:Date time
- Select all the columns and click Insert chart
- Select Line chart
- Select Use row 1 as headers
- Select Use column A as labels
Your data should be plotted. Try running your script again and the chart will update.
Embedded Linux Class by Mark A. Yoder