Created
November 7, 2019 20:36
-
-
Save gguuss/a6cbdbbed682871170b2ac0e09291bbb to your computer and use it in GitHub Desktop.
Example showing you how to retrieve rows for plotting SQL data from IoT core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Replace the variables in this block with real values. | |
var address = '<your-server-ip-address>'; | |
var user = 'root'; | |
var userPwd = '<your-password>'; | |
var db = '<your-db-name>'; | |
var dbUrl = 'jdbc:mysql://' + address + '/' + db; | |
// Read up to 1000 rows of data from the table and log them. | |
function readFromTable() { | |
var conn = Jdbc.getConnection(dbUrl, user, userPwd); | |
var start = new Date(); | |
var stmt = conn.createStatement(); | |
stmt.setMaxRows(1000); | |
var results = stmt.executeQuery('SELECT * FROM wifistr'); | |
var numCols = results.getMetaData().getColumnCount(); | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.appendRow(["ID", "Time", "Wifi Strength"]); | |
while (results.next()) { | |
var rowArr = []; | |
for (var col = 0; col < numCols; col++) { | |
res = results.getString(col + 1); | |
if (col == 2) { | |
res=res.replace('Wifi: ',''); // can even hackily clean up db | |
res=res.replace('db',''); | |
} | |
rowArr.push(res); | |
} | |
sheet.appendRow(rowArr); | |
} | |
results.close(); | |
stmt.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment