Introduction

Welcome to the S2C.io Tutorials. Here you’ll learn step-by-step tutorials on using the tools of the s2c.io platform

Requirements

There is no software download required. The platform is browser-based, we recommend using Chrome, Firefox, Internet Explorer 11+ or Safari.

Security

Requests to S2C.io can be done over SSL or non-SSL. SSL is the industry standard for securing HTTP traffic. Our website defaults to HTTPS but also allows non-SSL (HTTP) traffic to our Platform. SSL secures everything in the HTTP payload, which includes potentially sensitive information (like your project ID), and definitely sensitive information (like your Platform Key). Connections to s2c.io is encrypted and authenticated using AES_128_GCM and uses ECDHE_RSA as the exchange mechanism.

Authentication

Embedded devices require an authentication key in order to get access to S2C.io . Each Device is assigned a unique key during registration.

Quotas

DescriptionFreePro
Devices 3 Unlimited
Channels 15 Unlimited
Requests 2880/24hours
(2 requests/min)
Unlimited
Applications 10 Unlimited
Users 3 Unlimited
Email Alerts 60 Unlimited
SMS Alerts 30 Unlimited

This tutorial walk you through creating an internet of things application using Node.js running from a PC as an emulator. Any device that can run node.js can easily push data to s2c.io. In order to show how node.js works with s2c.io, we need to implement the example shown in the blog diagram above. In this example, we have a gateway connected to two sensors: sensor0 and sensor1. the first sensor measures battery, distance and current. The second sensor measures pressure and voltage. We need to collect the data from the sensors and send it over the internet and visualize from anywhere in the world.
At the end of the tutorial, you will learn:
1- Add a device to s2c.io
2- Add sensors
3- Create an application to visualize data in real-time
4- Add a user who can view the visualized data
5- Add alerts to receive emails when a condition is met in the field

Step 1: Install Node.js on your PC

Go to https://nodejs.org/en/download/
Install node.js

Step 2: Create an s2c.io account

go to https://s2c.io/register/
Follow the steps to register for an account

Step 3: Add Gateway in Device Manager

1. login to your account created in previous step
2. From Admin console, click Device Manager
3. From Device Manager, click Add Gateway
4. From the list of gateways, select Embedded. This is a generic method that allows any device to push data to s2c.io
5. Enter the following:
MAC Address: this is a unique id that identify your device. e.g. 54445666
Name: this is the name of your device. it could be anything e.g.. my device
Group (optional):
6. fill out the macaddr and the name then click sumbit. you should get an acknowledgment with a green check mark. click ok to close popup menu.

Step 4: Add sensors to your gateway

As shown in the block diagram above, we have two sensors: sensor0 and sensor1. We need to tell the application which sensors are connected to the gateway. To do that: 1. Click the checkbox next to the gateway name
2. Click ToolBox, the click Sensors. This will launch Sensors Manager
3. From Sensors Manager, Click Add Sensor, then click Library
4. From select Sensor dropdown menu, select SensorA
5. Click blue + to the right of the dropdown menu
6. From select Sensor dropdown menu, select SensorB
7. Click blue + to the right of the dropdown menu
8. Give the name: sensor0 and serial number 1 to the first sensor and the name sensor1 and serial number 2 to the second sensor
9. Click Add sensors, you should get an green checkmark. click Ok. Sensors Manager should populate the two sensors you have added
10. Click Back to return to Device Manager

Step 5: Push data to s2c.io using Node.js

Now we are ready to push data to s2c.io. To do that:
1. From Device Manager, click checkbox next to the name of your device.
2. Click Edit Gateway and take note of the secure key and macaddr
3. Open your favorite code editor (e.g. Notepad++ ). Copy and paste the code from this site
make sure to update the code with your secure key and macaddr
4. save the file as s2c_example.js
5. Launch Node.js console, navigate to the directory where you saved the file
6. Type the following node s2c_example.js
7. click return you should get an acknowledgment as shown in the image above. congratulations! you have successfully push data to s2c.io
Now let's visualize our data

Step 6: Create an application for data visualization

from Admin console, click Application Manager
1. click Add
2. Fill the information as shown in picture above. Make sure to select Nodejs Template. click Ok to close popup menu
3. click Run. a new window should open showing a number of widgets of the various channels
4. From Nodejs console, type the following: node s2c_example.js
5. you should see the values in the widgets change in real-time
You have now successfully visualized your data from a web browser.

Step 7: Add a user account

now that we can visualize the data, we want to allow other people to view it. So we create user accounts. From Admin console, click user manager
1. Fill out the name, and choose a username for the user (usually his email address)
2. Set a password for your user
3. From Select Application drop-down menu, select the application name. (this allow you to select who view which application)
4. Click submit. your user should be able to login to s2c.io using the username and password that you created for them

Step 8: Add alerts

We want to add an alert and we want to recieve an email if the battery level drops below a certain value
1. From Admin console, click Alert Manager
2. Click 'Add' and fill out the information as shown in the picture above. make sure to put your email address.
3. From your text editor, change the value of the battery and make it smaller than 15.
4. From Nodejs console, run the s2c_example.js
5. After couple of minutes, you should get this email in your inbox:
My Company name
Error: Low battery
Device: 00000000121
Sensor: 0
Channel: battery
value: 10
condition: <
threshold: 15

***************
You have successfully received an email alert

This tutorial walk you through creating an internet of things application using Node.js running from a Beaglebone. Beaglebone can run node.js and easily push data to s2c.io.

Step 1: Install s2chttp Library from npm repository into your BB

1. ssh to your beaglebone and use root as the login. no password is required
2. cd /var/lib/cloud9
3. npm install s2chttp
4. cp /var/lib/cloud9/node_modules/s2chttp/examples/s2c_io_client.js /var/lib/cloud9/autorun/s2c_io_client.js
this will copy the sample code into the autorun directory

Step 2: Run Client

1. cd autorun
2. node s2c_io_client.js
3. you should get response as shown in picture. what is happening is that the client does not provide a valid authentication key with s2c.io. So, let's get a valid key. Before you go: please take a note of your macaddr as shown in picture. we will need later.

Step 3: Sign up for an account with s2c.io

To get a valid key, you need to sign-up for a free account with s2c.io
1. Go to https://s2c.io
2. click 'Register'
3. Follow the Instructions to create then activate your account
4. Login to your s2c.io account
5. Click 'Device Manager'
6. Click 'Add Gateway' and select 'Beagelebone' then fill out the information. The 'macaddr' is the one noted from the previous step
7. After your added your BB, click 'Edit Gateway' then copy the 'SecureKey'. That the key we need for the next step

Step 4: Add your API_KEY

now go back to you SSH session with your BB.
1. cd /var/lib/cloud9/autorun
2. vi s2c_io_client.js
you can now edit the client to add the key we captured from previous step.
click insert navigate to gat.API_KEY = 'YOUR API KEY HERE'
replace the API_KEY with the API KEY of your beaglebone
click Esc
type wq! then ENTER
_Note_: Get API_KEY from s2c.io device manager > Edit Config > SecureKey
3. run your client again, node s2c_io_client.js
4. look at the print out now, you should see
POST response S2C.io ACK Message: OK!. Request from IP: x2x.4x.9x.19x
now that your BB can push data to the cloud, let's visualize it

Step 5: Data Visualization

1. login to your s2c.io account 2. Click 'Application Manager' then click 'add' to create a new application with the following:
name: choose anything
description: optional
template: select 'Beaglebone'
select device: click checkbox next to you BB from the list
click 'Apply'
3. Click 'Run'
a new window open where you can see a number of widgets that display the values push by your BB
Congratulations! your BB is now pushing and you can access your data from anywhere in the world.
There are other more features that you might want to try:
- add a logo to your application
- add users to view your application
- create alerts to receive email alerts when a condition is met in the field
- modify your application by adding more widgets
- and more.....
if you need any help please email me at support at sensors2cloud.com