202 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Deploying TensorFlow Models to Kubernetes on IBM Cloud
Mon, Dec 11th 2017 37
Tutorials how to build Solutions on the IBM Cloud
Mon, Dec 11th 2017 118
Sample Application how to use TensorFlow in OpenWhisk
Fri, Dec 1st 2017 30
Deploying the TensorFlow Inception Model on the IBM Cloud
Tue, Nov 28th 2017 12
Visual Recognition with TensorFlow and OpenWhisk
Mon, Nov 27th 2017 17
Watson Conversation How-Tos have been published
Tue, Nov 21st 2017 10
Building Facebook Messenger Bots with Botkit and Watson
Thu, Nov 16th 2017 12
Top 10
Tutorials how to build Solutions on the IBM Cloud
Mon, Dec 11th 2017 118
Deploying TensorFlow Models to Kubernetes on IBM Cloud
Mon, Dec 11th 2017 37
Sample Application how to use TensorFlow in OpenWhisk
Fri, Dec 1st 2017 30
Deploying Angular 2 Apps to Bluemix
Tue, Apr 11th 2017 21
Visual Recognition with TensorFlow and OpenWhisk
Mon, Nov 27th 2017 17
New Slots Filling Functionality in Watson Conversation
Fri, Jun 23rd 2017 16
How to deploy and run Swift Kitura Applications with Docker
Thu, Mar 3rd 2016 14
Understanding Natural Language Text via Watson Knowledge Studio
Tue, Apr 4th 2017 14
How to build Facebook Chatbots with IBM Watson
Thu, May 12th 2016 13
Managing Microservices on Kubernetes with Istio
Wed, May 31st 2017 13


How to invoke OpenWhisk Actions for certain IoT Device Events
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Niklas Heidloff    

Serverless Computing is often useful in event-driven Internet of Things (IoT) scenarios. For example when IoT sensors exceed a certain temperature actions are invoked to fix the issue.

OpenWhisk is IBM’s serverless computing offering in Bluemix. In order to implement a use case like above with the experimental OpenWhisk service, at this point you need to deploy a non-serverless application which receives MQTT events from IoT devices and invokes the appropriate OpenWhisk actions. While such a model seems to defeat the purpose of a serverless architecture, it allows developers to add their own filtering logic. For example rather than invoking hundreds of actions for hundreds of device events, you can invoke the potentially processing-intensive actions only for certain events, for example when the temperature is too hot.

Below is a simple sample how you could do this. Here is a sample action.

openwhiskiot1

function main(params) {
   params = JSON.stringify(params);
   return { "message": "you sent me " + params };
}

For testing purposes you can invoke events via MQTT tools.

openwhiskiot2

The following code shows a Node.js application that can be deployed via Cloud Foundry or Docker on Bluemix.

var cfenv = require("cfenv");
var appEnv = cfenv.getAppEnv();
var express = require('express');
var app = express();
app.get('/', function (req, res) {
   res.send('up');
});
app.listen(appEnv.port, appEnv.bind, function() {
   console.log('listening on port ' + appEnv.port);
});

var openwhisk = require('openwhisk');
var ow = openwhisk({ api: 'https://openwhisk.ng.bluemix.net/api/v1/', 
   api_key: 'xxx:xxx', 
   namespace: 'niklas_heidloff@de.ibm.com_dev' });

var Client = require("ibmiotf");
var appClientConfig = {
   "org" : "1o56n8",
   "id" : 'myapp',
   "auth-key" : "a-1o56n8-xxx",
   "auth-token" : "xxx"
}
var appClient = new Client.IotfApplication(appClientConfig);
appClient.connect();

appClient.on("connect", function () {
   // change this for the device events you're interested in   
   appClient.subscribeToDeviceEvents("TestDeviceType","+","+","json");
});

appClient.on("deviceEvent", function (deviceType, deviceId, eventType, format, payload) {
   // add your own filter logic here    
   payload = JSON.parse(payload);
   ow.actions.invoke({ actionName: "openwhisk",
      params: payload }).then(result => {
         console.log('success', result);
      })
});

The Node application uses iot-nodejs for the MQTT part and openwhisk as a convenience library to invoke actions.

{
  "name": "mqtt-to-openwhisk",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {
    "ibmiotf": "^0.2.12",
    "openwhisk": "2.0.0",
    "express": "4.13.4",
    "cfenv": "1.0.3"
  },
  "scripts": {
    "test": "echo "Error: no test specified" && exit 1",
    "start": "node app.js"
  },
  "author": "",
  "license": ""
}

Invoked actions show up in the OpenWhisk dashboard.

openwhiskiot3

As alternative to deploying a Node application you could also use Node-RED, the incoming IoT node and the openwhisk node.

The post How to invoke OpenWhisk Actions for certain IoT Device Events appeared first on Niklas Heidloff.



---------------------
http://heidloff.net/article/openwhisk-actions-iot-device-events
May 09, 2016
6 hits



Recent Blog Posts
37
Deploying TensorFlow Models to Kubernetes on IBM Cloud
Mon, Dec 11th 2017 1:45p   Niklas Heidloff
Ansgar Schmidt and I open sourced a sample that shows how to use TensorFlow to recognize certain types of flowers. The first version of the sample used the MobileNet model which we deployed to the serverless platform OpenWhisk to run the predictions. This article describes how to deploy a TensorFlow model to Kubernetes. TensorFlow supports various image recognition models that can be retrained for certain objects. MobileNet is small and can be run in OpenWhisk. The more precise and bigger Incept
118
Tutorials how to build Solutions on the IBM Cloud
Mon, Dec 11th 2017 8:21a   Niklas Heidloff
In addition to Patterns and How-Tos there is another good resource for developers to learn how to use the IBM Cloud. The Solution Tutorials provide step-by-step instructions on how to implement common patterns based on best practices and proven technologies. I like these tutorials for several reasons: They cover typical scenarios many developers need to understand when getting started with the IBM Cloud. They are well written and easy to follow. Every tutorial is one page with all the content y
30
Sample Application how to use TensorFlow in OpenWhisk
Fri, Dec 1st 2017 8:03a   Niklas Heidloff
TensorFlow provides predefined models that can be retrained to recognize certain objects in images. OpenWhisk is a serverless platform that executes functions in the cloud. With Kubernetes you can run heavy workloads in the cloud, for example the training of new TensorFlow models. Check out our open source sample that shows how to use these technologies together to recognize certain types of flowers. Get the code from GitHub or try out the live demo. Let me summarize how Ansgar Schmidt and I hav
12
Deploying the TensorFlow Inception Model on the IBM Cloud
Tue, Nov 28th 2017 11:22a   Niklas Heidloff
As a developer I’m trying to better understand how developers work together with data scientists to build applications that leverage machine learning. In this context one key question is how developers can access models from their applications. Below is a quick introduction to TensorFlow Serving and a description how to deploy TensorFlow models onto the IBM Cloud. Here is the description of TensorFlow Serving from the home page: “TensorFlow Serving is a flexible, high-performance ser
17
Visual Recognition with TensorFlow and OpenWhisk
Mon, Nov 27th 2017 2:01p   Niklas Heidloff
My colleague Ansgar Schmidt and I have built a new demo which uses TensorFlow to predict types of flowers. The model is trained in a Kubernetes cluster on the IBM Cloud. Via a web application pictures can be uploaded to initiate the prediction code which is executed as OpenWhisk function. We’d like to open source and document this demo soon. Keep an eye on our blogs. For now here is a screenshot of the web application. As starting point for this demo we’ve used a codelab from Google
10
Watson Conversation How-Tos have been published
Tue, Nov 21st 2017 8:22a   Niklas Heidloff
I’ve written two How-Tos which describe how to use the Watson Conversation tools Ansgar Schmidt and I had open sourced. The new page on developer.ibm.com contains How-Tos which describe everything that might be of interest for developers using the IBM Cloud. In contrast to patterns How-Tos are typically shorter and sometimes contain ‘only’ documentation and no source code. Inspecting Watson Conversations REST Requests “This how-to explains how to set up and use the commu
12
Building Facebook Messenger Bots with Botkit and Watson
Thu, Nov 16th 2017 10:54a   Niklas Heidloff
I’ve implemented a sample Facebook Messenger bot which leverages the Node.js library Botkit and IBM Watson Conversation. With Botkit you can build bots for Slack, Facebook Messenger, Twilio and other messaging clients. For natural language understanding different services can be used, for example IBM Watson, Api.ai, Wit.ai or Rasa. Most of the code can be shared for Slack and Facebook Messenger bots. Check out the code on GitHub. Similarly to my sample Slack bot, the Facebook Messenger bo
9
Creating Alexa Skills with OpenWhisk and IBM Watson
Thu, Nov 16th 2017 8:43a   Niklas Heidloff
My first code pattern (formerly known as developer journeys) has been published on developer.ibm.com/code. The pattern describes how to build Alexa skills with OpenWhisk. Rather than using intent and entity identification from Alexa, Watson Conversation is used. This allows developers to define conversation flows declaratively and developers can reuse conversations that are available in the Bot Asset Exchange. My colleague Mark Sturdevant improved the documentation and created a video. Check out
6
Integrating Applications without writing Code
Tue, Nov 14th 2017 2:52p   Niklas Heidloff
IBM App Connect is an IPaaS (Integration Platform as a Service) to connect different applications without having to write code. Similarly to IFTTT users are typically business users or citizen developers from line of business departments. App Connect provides currently roughly 50 connectors to integrate applications like Salesforce, SAP, Slack and Gmail. See the documentation for details. Users can graphically build flows that are either event-triggered, for example if a document is changed in a
3
Pictures from W-JAX 2017
Fri, Nov 10th 2017 10:32a   Niklas Heidloff
This week I attended W-JAX in Munich, Germany, which is a developer conference with 1400 attendees with a focus on Java and enterprise technologies. My colleagues and I presented and demonstrated the IBM Cloud and the IBM Code developer site. Below are some pictures. The IBM team: Discussions with developers at the booth: I gave a session about Slack bots and IBM Watson Conversation: One thing I really liked was a demo another company gave at their booth. They connected Anki Overdrive cars to




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition