Skip to content
This repository has been archived by the owner on Aug 27, 2020. It is now read-only.

rmey/iotreceiver

Repository files navigation

iotreceiver

Overview

The example shows how sensor data from the IBM Bluemix Watson IoT Platform can be stored in a Cloudant NoSQL DB. It connects as application client and waits for messages of a certain sensortype in my case some "BME280" sensors I connected at home via an own gateway with the IoT Platform. You can change the sensor type in server.js. This small service has the task to subscribe to the sensor events and save them in a database as JSON document for later processing (temperature, humidity, ...). The application run as multiple instances for high availability, because the IoT Platform supports shared connect options for an application client. To not exceed the limit of my Cloudant instance for write rates I added a rate limiter for the database calls.

alt tag

Run with node.js

To run the example locally you need to set Environment Variables or create 2 JSON files ".cloudant.json" and .ibmiotf.json formated like the example files provided.:

export IOTF='{"org": "YOUR ORG","id": "YOUR APP NAME","auth-key": "YOUR APP KEY","auth-token": "YOUR TOKEN","type" : "shared"}'
export CLOUDANT_URL="https://.....-bluemix.cloudant.com"
npm install
node server.js

Run as local Docker Container

With a local Docker engine you need to start the Container with the environment variables described above:

docker build -t "iotreceiver" .
docker run -it -e IOTF="$IOTF" -e CLOUDANT_URL="$CLOUDANT_URL"

Run as IBM Container scalable group

With the following command the IBM Container Group on IBM Bluemix will be created with auto recovery and anti co-location/anti affinity settings enabled. Please note that the scalable group does not require to expose a public route, but it needs to expose a HTTP port for health checking to enable auto recovery.

cf ic init
docker tag iotreceiver registry.YOURREGION.bluemix.net/YOURNAMESPACE/iotreceiver
docker push registry.YOURREGION.bluemix.net/YOURNAMESPACE/iotreceiver
cf ic group create --name iotreceiver -m 64 -e CLOUDANT_URL="$CLOUDANT_URL" -P -e IOTF="$IOTF" --anti --auto registry.YOURREGION.bluemix.net/YOURNAMESPACE/iotreceiver

Run as Cloud Foundry App

To run the example in Bluemix / Cloud Foundry with multiple instances. The Cloudant Service could in that case also provided via the VCAP_SERVICE environment as bound service.

cf push iotreceiver -m 64M -i 2 --no-start
cf set-env iotreceiver IOTF "$IOTF"
cf set-env iotreceiver CLOUDANT_URL "$CLOUDANT_URL"
cf restage iotreceiver

Links to more information

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published