• image

Step1 of your I.O.T. Project – Setting up your Cloud Web Services

So this week I said  would be showing you how to connect a device up into the cloud. First a basic overview of some of the technology we are going to be using. The idea behind IoT, or the Internet of Things, is to allow remote connection to an electronic device. There are two ways we can set a device up. The first is to set up the system for input, or to collect information. This would mean that the device is collecting, and/or processing data from it’s environment, and posting that information up to the cloud, where we can see it. The second configuration pattern, is to allow the device itself to be controlled from a remote location, via the cloud. The term “cloud” in this context, refers to the world wide web, or internet. The cloud can either harness data ready for us to examine with a web browser (or any other web service consuming client), or the cloud can allow us to configure the devices via a web browser. The power behind this setup is the remote nature of it. Where ever the user is in the world, as long as they have access to a web browser they can either monitor the remote environment, or control it.  The Internet of Things then, is the utilization of remote web connected devices. Examples of such devices could be a USB camera, an alarm system or a weather station. We could have for example have an Raspberry Pi board connected to a USB camera set up in the garden of our home. When an animal activates a PIR sensor connected to the Pi, the Pi takes a snap shot with the camera and uploads the photo to a remote server,where,at the end of the day,we could see what has been lurking in the garden ! Alternatively we could have a web page that allows us to change the lighting in our home. Sitting on the couch, we could bring up a web page in a browser on our phone, and dim the lights and bring the projector screen down, ready for a movie night ! The limitations are bounded by your imagination.

Let’s take a simple setup and teach you how to create your first I.o.T. project ! As with all home projects, sketch out first what you plan on doing, choosing a natural break off point for your project, this is your stage 1. Choosing the right point at which to stop and access your progress can be a critical factor in the success or failure of a project, no matter how complex or trivial the project is. Start your project using the natural stage 1 you have selected as the focus in your mind. When you have successfully hit stage 1 you can reflect on how things went, and then begin to iterate on your project, progressing to stage 2. Wash and repeat. This technique enables you to achieve something tangible using designated goals as your motivation. choose natural break off points, small and achievable. Even a simple home project needs you to focus on your next task. Once you have a rough idea of what you want to achieve in stage 1, make a list of materials you will need. Stay focused and acquire just the materials you need to get to stage 1. You will find with everything you do in engineering, changes will be made to requirements whilst the project is in development, get used to the dynamic nature of engineering, very rarely does a project come to fruition in the exact state it was first envisaged in ! So acquire just the minimum materials to get you started, that way if you change your mind it has minimal impact on your budget. Set a rough deadline and write down what state you want your project to be in when you hit that deadline. Try not to change it, and try and hit the deadline. Sometimes it’s the journey itself that is the valuable part of the project, rather than the artifact or deliverable ! In fact, all this reminds me of some important techniques in which engineering teams work towards their deliverables. In an upcoming blog entry I will describe and compare some of these important project planning and execution methodologies, including Agile !

So my example project is going to a simple global warming reversal machine. Well, not quite ! “Start small”, as they say, so let’s begin with a weather station then ! There will be two aspects to this system. The first part of our system will be the cloud web services. We will first configure a storage area for all the data our weather station produces. From this data we will create information that we can use to map changes in our local climate. Perhaps, in  the future, using social media, it will be possible to create a network of like-minded individuals, who like us, would like to collect information on climate change, but for now we are working alone.  The second part of the system will be the electronic device and sensors that we will use to collect all the local climate information.I will be using a Raspberry Pi 3 mini computer. They cost around $40 and are very simple to set up. There are lots of web sites and forums that show you how to configure one. Basically, a Raspberry Pi 3 is a mini computer that rather than running Microsoft Windows as an Operating System like your PC or Laptop, or iOS like your Mac, the Raspberry Pi is best set up to run a bespoke Operating System based on the Linux kernel called Raspbian. Raspbian is free, and there are hundreds of complementary free apps and services for Linux to go with it. But that’s all for next time. Let’s get started with our Stage 1.

Firstly we will need to configure our cloud system. There are many companies offering cloud web services. These companies are very forward thinking and have seen that the future of computing is split into infrastructure and services. The days of having a powerful PC on your desktop that you replace every 5 years are coming to an end. The future of consumer computing is mobile computers, for example the phone and tablet. The desktop PC will become a dumb terminal, sitting on your desk, you will hardly ever need to replace it, as all the power you need will be accessed through the web on remote servers. Your local PC (or web client) will just provide a portal to the hugely technically competent infrastructure designed and configured by large co-orporations like Amazon, Microsoft and Google. These companies want to offer cheap infrastructure and services that consumers use rather then running apps and services locally on their local PC or laptop. So learning how to configure cloud services will be imperative if you are thinking of working in Engineering.

For our IoT setup I will be using the free introductory services of Amazon. First we need a remote web storage area, it will be capable of holding plenty of data that our weather station will send up to via the web each 10 minutes or so. So first create yourself an Amazon web account here:

https://aws.amazon.com/

With the sign up, it might be necessary to enter credit car details. It depends on your location in the world. for this example you should not be charged though, as you will be receiving a years worth of free services. Not only are the services free for a year, you only pay for what you use anyway (in essence you are renting/leasing web infrastructure). We will only be setting up test services, so no charges will be applied. Note though, that it is possible to set up services that cost money, although this is quite difficult to do, be aware of what you are doing on the site. Like any site that has your account details, monitor what you are doing, and monitor what charges come out of your credit card. I have never been charged for anything…yet !

From here we need to create a pair of SSH keys. Security for this example in I.o.T. is based on pairs of keys. One key is used to encrypt data, this is the public key, and the other key is used to decrypt that encrypted data, this is the private key, and this is kept secret. Note that for our IoT test setup, I don’t think it matters too much if our data s compromised and people find out the temperature of a back garden in Scunthorpe !

Sign into the AWS Management Console and open the Amazon EC2 console at

https://console.aws.amazon.com/ec2

Click on the Key Pairs Security option on the left hand pane :

keypairs

when you create your pair of keys give them a name you will remember and understand in 6 months, for this example I have called them “TestMarcusIOT”. When you create this key pair, a file will be downloaded to your browser downloads folder, this file is automatically downloaded by your browser. The base file name is the name you specified as the name of your key pair, and the file name extension is .pem. Save the private key file in a safe place.

Now we need to create a Cloud Formation. So go to the AWS Cloud formation page (note this link will be dependent on your geo-location) mine for example is :

https://us-west-2.console.aws.amazon.com/cloudformation/home?region=us-west-2#

Create a new stack. And In the Template section, select Specify an Amazon S3 Template URL to type or paste the following URL for the IoT Getting Started template:

https://s3.amazonaws.com/awsprojects-code/iotGettingStartedTemplate.json

This is creating a JSON config file to set up our services. Just let this example fill in the things you don’t need to know for now !  Theses systems are all very configurable, so they can be used for many different application. This adds a lot of complexity to things, but if you just ignore those parts for now, they will be interesting to learn later, when you are an expert at IoT !

Almost done, now click next, give the stack a name, mine is “MarcusIOTTest”, and select the key pair from earlier in the keyname drop down, and then next again. On the Review screen, confirm the configuration, check the box that says “I acknowledge that AWS CloudFormation might create IAM resources”, and click Create. The environment can take a few minutes to provision completely. You can refresh periodically to monitor the creation of the stack. When AWS CloudFormation is finished creating the stack, the status will show CREATE_COMPLETE. Now select the check box beside your stack and then click on the Outputs tab below.

Take a note of the IpAddressEc2DeviceSimulator Value. This is the public IP address of your IoT Device Simulator EC2 instance. Now let’s see if we can connect to it !

PublicIPAWS

If you are using Microsoft Windows, download and install the Putty tool (google search it).

Choose the .msi file for 64 or 32 bit (depending on your Windows OS version  – Note I usually chose the 64 bit version of anything I’m downloading, if it doesn’t work go back and get the 32 bit version).

Be certain that you install both PuTTY and PuTTYGen, then launch PuTTYGen and choose Conversions -> Import Key. Browse for the downloaded pem file (e.g., MarcusIOTTest.pem) and import the key. In Putty save the key as the same file name with a .ppk extension. Click File -> Save as Private Key.

puttyGen

Ignore the dialog that asks if you want to do this without a passphrase. Close PuTTYGen.

Now close PuttyGen and open PuTTY.

On the left menu expand Connection -> SSH and select the Auth sub-menu.

Click Browse and select your PPK file from the previous step.

puttyppk

Now Select Connection and configure the keepalive to 60. This will prevent your SSH session from timing out.

Select Session on the left. In the Host Name box, enter [email protected] followed by the IP address of your Simulator EC2 instance. (e.g. [email protected] 50.17.175.10).

putty_final

Click Yes to the huge dialog, as you do trust this, and confirm the fingerprint.

You should now be connected to your instance !

connected_ssh

So that’s enough for this entry. we have now created step 1 of what we need for the back end web services. Next we will be configuring our I.o.T. device to consume our web services !

See you in a few weeks !

About the Author

Marcus O'Brien

Hi ! I’m Marcus O’Brien, I‘ve been a qualified Software Engineer for 20 years now. I chose engineering as a career because of my passion for learning anything to do with computing, be it programming languages, computer architectures or even operating systems. Now, after a journey through many diverse industries, I work for a video games company in Vancouver writing some of the best AAA and mobile game titles in the world! To keep my skills up-to-date, I work on several home projects involving many new areas of software, including genetic programming, swarm intelligence, artificial intelligence and recently robotics and automation. Technology to me is a fascinating, endless, almost infinite expanse of wonder. Every day, technology is moving us faster towards the future of mankind. Where will we end up? How will we develop and fit into this vast Universe? And more importantly, what is it going to look like when we get there?