We've got lots and lots of data, and we need to do more than just save a copy locally.
In this log / tutorial, we're going to detail how we set up our own Google Cloud virtual machine with a simple database. You'll be able to use this to store all of your sensors' data. Now, on to the software part of our hardware project...!
Why Google Cloud Platform instead of Amazon AWS?
(Google hasn't sponsored us; we just really like their services)
- much better pricing
- easily understandable server & storage billing (I'm still getting intermittent bills from AWS for a service I shut down more than a year ago)
- simple navigation between cloud products
- much better selection of virtual machine (VM) images to start with
In all, it seems that Google looked at everything Amazon was doing with cloud computing, and Google met Amazon head-to-head where AWS does things well, and Google innovated where AWS is lacking.
Creating the VM
- Create an account at cloud.google.com
- Navigate to the Virtual Machine area
- Google Cloud Platform > (top-left menu) Compute Engine > VM instance
- Create a VM
- for the "machine type" setting, choose from the "f1" tier (the smallest option, which you'll need to scroll up to see)
- for "boot disk", we've chosen "Ubuntu 16.04 LTS" - don't choose "Minimum" build - that's for servers that won't be logged into by users, and it doesn't install some packages we'll use
- Give your VM a static IP address
- Google Cloud Platform > (top-left menu) Networking > VPC Network > External IP Addresses
- change "ephemeral" to "static"
Logging Into the VM and Setting up the Database
The 1st step here isn't necessary, but it'll speed up your log in times...
- Enable OS Login for faster SSH logins (optional)
- there's a nice tutorial from Google, here ... read it or just do the following ...
- go to Google Cloud Platform > (top-left menu) Compute Engine > Metadata
- add the key / value pair: "enable-oslogin" / "TRUE" (don't include the quotes)
- go to Google Cloud Platform > (top-left menu) IAM & Admin > (find the user to enable, click Edit) > add the Compute Engine - Compute Admin role
- Launch a Secure Shell to the new VM
- go back to Google Cloud Platform > (top-left menu) Compute Engine > VM instances
- click SSH (for the given VM instance) > Open in browser window
- Update and Upgrade your new VM
sudo apt-get update
sudo apt-get upgrade
- Install the MySQL database
- here's the stand-alone tutorial on the subject that we followed
- keep in mind that you'll need to use "sudo" in front of some of the commands because we're not the root user in our Gooogle Cloud VMs
- Allow for remote access (from our sensors) to write to the MySQL server
- here's the stand-alone tutorial on the subject that we followed
- Testing it all out, just go into your VM's console and log in to MySQL
mysql -u root -p
- enter the password when prompted
- Create a new database and enter into it
CREATE DATABASE myHardwareProject; USE myHardwareProject;
- Create a new table
CREATE TABLE test ( ID int NOT NULL AUTO_INCREMENT, sensorName varchar(20) NOT NULL, sensorValueA FLOAT(10,9), sensorValueB INT, PRIMARY KEY (ID) );
Have fun!
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.