Difference between revisions of "EBC Exercise 38 Logging to Excel"

From eLinux.org
Jump to: navigation, search
(Initial Page)
 
m (Replaced content with "Category:ECE497 {{YoderHead}} Turns out this is too hard to do. {{YoderFoot}}")
(Tag: Replaced)
 
Line 2: Line 2:
 
{{YoderHead}}
 
{{YoderHead}}
  
Here are instructions on how to log data to an Excel spreadsheet from Python.
+
Turns out this is too hard to do.
 
 
== Create a new Excel Spreadsheet ==
 
Create a new spreadsheet:
 
* Sign into your [https://onedrive.live.com/about/en-us/ OneDrive] account.
 
* Select '''New:Excel workbook'''.
 
* Give it a meaningful name
 
* Enter some column labels
 
[[File:BlankExcel.png|480px|Blank Excel Sheet]]
 
* Note the sheetID in the path
 
[[File:SheetID.png|SheetID]]
 
 
 
== 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 https://developers.google.com/sheets/api/quickstart/nodejs] and follow step 1.
 
 
 
If you are using Python, got to
 
{https://developer.microsoft.com/en-us/graph/quick-start?platform=option-Python https://developer.microsoft.com/en-us/graph/quick-start?platform=option-Python] and follow step 2.
 
* Click the '''Get an app ID and secret''' button
 
* Click the '''Add an app''' button
 
* Give the app a name.  I used 'Logging Data to Excel'
 
* Click '''Let us help you get started'''
 
 
 
Either way put the '''credentials.json''' file in the sheets directory.
 
 
 
== Run the example ==
 
=== JavaScript ===
 
* Edit '''demo.js''' and change the '''sheetID''' string to the string you noted above.
 
* Load the API
 
bone$ '''npm install googleapis'''
 
* 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.
 
 
 
=== Python ===
 
* Edit '''demo.py''' and change the '''sheetID''' string to the string you noted above.
 
* Load the API
 
bone$ '''pip3 install --upgrade google-api-python-client oauth2client'''
 
* Run
 
 
 
Then, run the example on your Bone.  The arguments are the values to be logged on the sheet.
 
bone$ '''./demo.py --noauth_local_webserver 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.
 
 
 
== 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'''
 
[[File:Date.png|Formatting the Date]]
 
* Select all the columns and click '''Insert chart'''
 
[[File:InsertChart.png|Insert chart]]
 
* Select '''Line chart'''
 
* Select '''Use row 1 as headers'''
 
* Select '''Use column A as labels'''
 
[[File:FormatChart.png|Chart formatting options]]
 
 
 
Your data should be plotted.  Try running your script again and the chart will update.
 
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 07:09, 11 October 2018

thumb‎ Embedded Linux Class by Mark A. Yoder


Turns out this is too hard to do.




thumb‎ Embedded Linux Class by Mark A. Yoder