Ex #1: Send a Tweet

In this example, you will use Enzo Online to send a Tweet from any device, program, or chip connected to the Internet.

Create a Twitter Application

The first step is to create an Application registered with Twitter, so that the IoT device can tweet on your behalf. To create your Twitter application, visit https://apps.twitter.com/. Login with your Twitter account.

NOTE: Your Twitter profile must have a phone number specified; visit your settings on Twitter and add a mobile phone number before proceeding.

  • Click on the button "Create New App"
  • Enter a Name, Description, a website URL you own, and agree to the developer agreement terms. You do not need to specify a Callback URL.
  • Click on Create Twitter Application
That's it! You have registered a new Application with Twitter; by default you can read from and write to your Twitter timeline. From the Application page click on Keys and Access Tokens then click on Create my Access Tokens at the bottom of the page. Copy the following information as you will need them later:

  • Consumer Key (API Key)
  • Consumer Secret (API Secret)
  • Access Token
  • Access Token Secret

Configure Enzo Online

The next step is to configure Enzo Online with the above Twitter secrets, so your IoT device can tweet through basic HTTP calls. Let's configure an Enzo Twitter Service:

  • Login to Enzo Online (https://portal.enzounified.com)
  • Click on the Twitter service on the left menu
  • Click on the Create button
  • In the name field, enter the configuration name (for example: twitterconfig)
  • Select the Instance where the Enzo Twitter service will be running on
  • In the remaining fields, enter the API Keys and Access Token information previously obtained from your Twitter application
  • Click Save

Send a Tweet

The following shows you how to send a tweet programmatically.

                                    
import sys 
import urllib 
import urllib2 
import requests

enzourl="https://daas001.enzounified.com/bsc/twitter/postStatus" 
enzoAuthId="ENZO_AUTH_ID" 
configName="twitterconfig"

headers={'status':'Sending a tweet using Python - @enzo_unified', 
'authToken':enzoAuthId, 
'_configName':configName, 
} 

response=requests.post(enzourl,headers=headers, data = { }) 
                                    

                                    
POST https://daas001.enzounified.com/bsc/twitter/poststatus HTTP/1.1
authToken: YOUR_AUTH_TOKEN
_config: twitterconfig
status: Sending a tweet using HTTP commands

                                    

                                    
var request = require('request');
const enzoUrl = "https://daas001.enzounified.com/bsc/twitter/poststatus";

var headers = {
    '_configName': 'twitterConfig',
    'authToken': 'ENZO_AUTH_ID',
    'status': 'Sending a tweet from Node.js - @enzo_unified'
}

var options = {
    url: enzoUrl,
    method: 'POST',
    headers: headers
}

// FUNCTION: send a tweet
function sendTweet() {
  request(options, function (error, response, body) {
    if (!error && response.statusCode === 200) {
      console.log('Tweet sent');
    }
    else
    {
       console.log('Status Code ERROR: ' + response.statusCode);
    }
  });
}

// Send the tweet now
sendTweet();

                                    



Ex #2: Execute SQL Command

In this example, you will use Enzo Online to send an SQL statement through HTTP to an existing MySQL database, SQL Server database, or an Azure SQL Database.

Configure Enzo Online

To send or retrieve data from a database you must first create a Connection String in Enzo Online. After creating the Connection String, you will need to create a DB Proxy configuration setting, which will be using the Connection String.

  • Login to the Enzo Portal
  • Create a Connection String
    • Click on Connection Strings on the left menu
    • Click on Create
    • Enter a name for this connection string (ex: conn001)
    • Select the Enzo Instance where the connection string will be created
    • The complete connection string to your database (the database must be accessible from the Internet)
    • Click Create
  • Create a DB Proxy configuration
    • Click on DB Proxy on the left menu
    • Click on Create
    • Enter a name for this DB Proxy configuration (ex: dbconfig001)
    • Select the Enzo Instance where you previously created the connection string
    • Select the connection string previously created (conn001)
    • Click Create

Send an SQL command

The following shows you how to read data from a SQL Server Database table called 'table1'.

                                    
import sys 
import urllib 
import urllib2 
import requests

enzourl="https://daas001.enzounified.com/bsc/db/gettable" 
enzoAuthId="ENZO_AUTH_ID" 
configName="dbconfig001"

headers={'tablename':'table1', 
'authToken':enzoAuthId, 
'_configName':configName, 
} 

response=requests.get(enzourl,headers=headers, data = { }) 
                                    

                                    
POST https://daas001.enzounified.com/bsc/db/gettable HTTP/1.1
authToken: YOUR_AUTH_TOKEN
_config: dbconfig001
tablename: table1

                                    

                                    
var request = require('request');
const enzoUrl = "https://daas001.enzounified.com/bsc/db/gettable";

var headers = {
    '_configName': 'dbconfig001',
    'authToken': 'ENZO_AUTH_ID',
    'tablename': 'table1'
}

var options = {
    url: enzoUrl,
    method: 'GET',
    headers: headers
}

// FUNCTION: send a tweet
function getData() {
  request(options, function (error, response, body) {
    if (!error && response.statusCode === 200) {
      console.log('Got data back');
    }
    else
    {
       console.log('Status Code ERROR: ' + response.statusCode);
    }
  });
}

// call method now
getData();

                                    



LAB #1: Send MXChip Temperature Data to Azure Tables

Download Lab Instructions Download Lab Materials (solution)
Estimated Completion Time: 1 hour

In this tutorial, you will use Enzo Online to forward telemetry data coming from an MXChip to an Azure Table. This tutorial is broken up in multiple steps allowing you to configure and test the overall plumbing of the solution without an actual physical device, and finally test the complete solution if you do have an MXChip device available.

This Lab uses the following technologies:

  • MXChip Device
  • C++
  • Enzo Online
  • Azure Table



LAB #2: Simple Security System with Raspberry Pi, Enzo Online and Azure Cognitive Services

Download Lab Instructions
Estimated Completion Time: 2 hours

The purpose of this lab is to create a simple security monitoring system that uses a few key services to assist with image analysis and log storage for auditing purposes. This project leverages small IoT devices that can easily be placed in sensitive areas to monitor activity. This is a conceptual project and should be considered a simple prototype to demonstrate the use of key cloud technologies.

This lab is divided in the following sections: Configuration, Image Analysis, Auditing, and Alerting.

This Lab uses the following technologies:

  • Raspberry Pi 3 or higher
  • Python 3
  • Camera
  • Azure Cognitive Services
  • Azure Table
  • Twilio
  • Enzo Online
  • PuTTY



LAB #3: Logging application events in Loggly and raising SMS alerts from Loggly with Twilio

Download Lab Instructions
Estimated Completion Time: 2 hours

The purpose of this lab is to allow Python developers to log application events into Loggly and configure Loggly to send a SMS text message using the Twilio service. This is done by leveraging Enzo Online to so that developers can abstract the logging service, and so that Loggly can use Twilio for sending SMS messages.

This Lab uses the following technologies:

  • Python 3
  • Twilio
  • Enzo Online
  • Loggly