Apex · heroku · Lightning · Salesforce

INTRODUCTION TO SALESFORCE IoT CLOUD

These words “Internet of Things”, have taken the world through a storm. The devices that we could not even think of can now communicate with each other with a simple click. Today, everyday objects are using the internet to connect to the cloud, forming what has become known as the “Internet of Things” or “IoT”. The ‘thing’ in IoT could be a person with a heart monitor or an automobile with built-in-sensors, i.e. objects that have been assigned an IP address and have the ability to collect and transfer data over a network without manual assistance or intervention. What more could have been achieved with it?

Just imagine a situation, where we could also get the data describing the daily activities of our customers along with the static data we already have about them in our Salesforce so that we could provide them more personal and customised services.

This is no more an imagination. Yes!! Salesforce has now its own IoT Cloud which handles all the above said processes to let us create experiences that lets our company focus on creating engaging, individualised experiences for all our customers.

What is Salesforce IoT?

IoT cloud is the heart of the Salesforce Customer Success Platform, that enables you to connect all the data that’s collected as your customers do their daily activities, with the data you already have about them in Salesforce, so that we can take right actions with the right customer at the right time.

How does Salesforce IoT work?

It lets us set up business logic so that meaningful actions based on customer context and real-time events(car breakdown, router instability,etc) can be taken. The logic we set up can apply to all our customers, so we don’t have to set up these experiences individually. And the parameters we define in IoT Cloud will trigger different types of actions based on the combined events and customer context.

What is Thunder?

Salesforce IoT Cloud is powered by Thunder, a scalable event processing engine, designed to ingest and analyse billions of events.

Thunder supports Salesforce’s IoT Cloud, which is designed to take in the massive volumes of data generated by devices, sensors, websites, applications, customers and partners and initiate actions for real-time responses.

Thunder is built on open source technologies:

  • Apache Kafka for messaging.
  • Apache Storm for streaming data distribution. Storm is a distributed real-time big data and complex event processing (CEP) platform.
  • Apache Spark for in-memory data processing. Spark is a parallel processing framework that allows users to run large-scale data analytics applications across clustered computers.
  • Apache Cassandra as highly scalable database. Cassandra is  a distributed database system that can serve as both a real-time operational data store for online transactional applications and a read-intensive database for large-scale business intelligence (BI) systems.
  • Heroku platform-as-a-service. Heroku is a cloud-based development PaaS provider that maintains the development environment and integrates other cloud services.

Who Uses IoT Cloud?

There are 3 key roles. They are product managers, engineers, and analysts.

  • Product Managers – They are strategists and nontechnical business users. They use clicks, not code, to set up the initial states and rules they’ll use to carry out your customer experience strategy.
  • Analysts – They are technical users. They will complete your IoT Cloud setup using either the point-and-click interface or code to access APIs. They’ll set up rules and actions triggered by incoming events and other contextual data already in Salesforce.

  • Engineers – They are power users and systems integrators. They connect events and contextual data to IoT Cloud. Just like analysts, engineers also use the point-and-click interface or code to access APIs.

IoT Cloud in Action

Our ancient systems were often designed as specific sequences of actions (do this, then do that, and so forth). But this isn’t really how people engage with apps or devices. They jump around; they leave tasks unfinished; they get interrupted. In order to finish their tasks, they have to start from the beginning. But thats not the case with Salesforce IoT. Here the the actions and interactions triggered by events don’t have to restart at the beginning. Customers can move back and forth between these states depending on the rules you set up. This lets us design experiences that engage with customers in realistic and continuous ways.

IoT Cloud – A State Machine

IoT Cloud is a state machine. A state machine is a nonlinear workflow engine that consists of states that reflect strategic groupings of objects or people. It helps us create workflows that react to different events and contextual data in non sequential, organic ways. The great thing about this is, unlike in a linear workflow, you don’t have to define a complete series of sequential steps that cover all possible combinations of events and connected data.

Key Terms

Below are some keywords that we may come across whenever we deal with Salesforce IoT.

  • State machine  – A nonlinear rules-based engine fueled by real-time events.
  • State – A rule or set of rules that are meaningful to the types of people or objects to which they are applied.
  • Orchestration – The composition of rules in various states that create the full experience for your customers or their devices.
  • Rule – The logic that tells an orchestration what to do. Rules are made up of events, conditions, actions, and, optionally, transitions.
  • Event  – Real-time events or periods of time that trigger a rule to be evaluated.
  • Action  – The part of a rule triggered by an event.
  • Condition – Additional criteria used within a rule. Conditions must be met for a rule to fire.
  • Transition – A move from one state to another, initiated by a triggering event or condition.
  • Traffic view – A graphical representation of how many people or devices are in each state.

 

Basic Workflow for Working in IoT Cloud

Screen Shot 2017-09-25 at 4.07.51 am

Combining Events and Context

One of the really cool things about IoT Cloud is that it lets you bring together event data and context data. This lets you take actions not just on events, but on events in combination with context data about the device or the customer.

 

Streaming event data or events can include data from apps, devices, and other things embedded with electronics, sensors, and software. It’s data about events that are happening to or within the app, service, device, or other object. Eg; the temperature of a device, etc.

Context data or context is generally static data about the app, device, or object. Examples are model number, version, contact name, service history, and so on.

We have Event and Data Pipes that carry out the transformation on these data respectively before actually sending them to the IoT setup.

IoT – A Simple Use Case

In this use case, we have made the use of Electric Imp platform to connect and monitor a refrigerator and a Salesforce Connected App to track the current temperature and humidity in the fridge.

What is Electric Imp?

  • The Electric Imp platform allows you to easily connect devices to the cloud via wifi.
  • Electric Imp apps are written in Squirrel, “a high level imperative, object-oriented programming language, designed to be a light-weight scripting language that fits in the size, memory bandwidth, and real-time requirements of applications like video games”.

How does it work?

  • Apps comprise 2 modules:
    • the Device module runs, on the device itself.
    • the Agent module runs in the Electric Imp cloud.
  • The platform provides a secure communication channel between the two; as a developer, to send a message from the device to the agent, you simply have the device call:
    • agent.send(“message_name”, data);
  • On the agent, you listen for messages with
    • device.on(“message_name”, function(data) {

    // Do something with the data

What it does?

It updates Salesforce with new readings every 15 seconds. Also it creates a case if any of the following cases is true :

  • The refrigerator door is open for more than 30 seconds
  • The temperature remains over 11°C for more than 15 minutes
  • The relative humidity is over 70% for more than 15 minutes.

Pre – Requisites

  • An Electric Imp developer account
  • The Electric Imp BlinkUp app (iOS or Android)
  • A new Trailhead Playground org.
  • An Electric Imp Developer Kit — to purchase please click here

Setting Up the Device

  • Plug the imp001 card into the breakout board slot
  • Power up your Imp with the AA batteries
  • The Imp001 should now have power and be blinking amber/red

After setting up, it looks like below:

team-trailhead_workshop-electric-imp_en-us_images_image_0_3d5c0ac9c5210ef26950f8287e60413c.png

Electric Imp BlinkUp

Use the Electric Imp mobile app to BlinkUp your device

  1. Log in to your Electric Imp account.
  2. Enter your WIFI credentials.
  3. Follow the instructions in the app to BlinkUp your device.

Configuring salesforce

  • Create a salesforce connected app. This CONSUMER_KEY and CLIENT_SECRET_KEY will be used in agent code to connect Electric Imp Cloud and Salesforce.
  • Create a custom object that stores all the readings taken by the device.
  • Create a lookup field from Case Object to the newly created custom object.

Coding the chip

The Electric Imp IoT Connectivity Platform has two main components—the impDevice and the impCloud. The impDevice runs the device code, which in this use case consolidates the data gathered by the temperature/humidity/light sensors. Each device is paired one-to-one with a “virtual twin”—or, as we call it, an agent—in the impCloud. The device sends this data to its agent, which runs agent code.

Click on Agent code and Device code to get the code.

Screen Shot 2017-09-25 at 4.50.13 am.png

Lastly, build and run the code in your electric imp IDE. Install the device in your fridge. When the sensor detects that the door is open, it will create a record in the SmartFridge custom object and display the following in the Electric Imp IDE log.

That simple! Your first IoT Project! Watch out this space for more information 🙂

Resources

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s