Home automation as a weekend project using IBM’s Clouds – part 3

Today we will add a simple user interface to our Bluemix/Node-RED/MongoDB application. We could do it in a form of a Ruby in Rails app or use another platform. But let’s assume that we want to have something up and running really fast – just for PoC purposes and as a rough prototype. That’s why I am going to use RapidApps for this purpose.

First we need to add RapidApps to our application.

In Bluemix dashboard find IoT application, click it and add RapidApps service to it.

Click at just created RapidApps service and press button Start building.

First we need to create a MongoDB adapter for our database and collection.

Find Add and Adapter button and click it:

Screen Shot 2014-08-12 at 13.41.18

Press Write to open JSON editor for adapter configuration file and paste text below:

{
    "authentication": {
        "type": "Server",
        "token": "EVxKsl6bbSorMPfDoCOPfGILLVaRMoOm"
    },
    "baseurl": "https://api.mongolab.com/api/1",
    "description": "MongoDB",
    "name": "SensorData",
    "entities": [
      {
        "name": "DataValues",
        "description": "Temperature Values",
        "filter": "",
        "mapping": [
          {
            "verb": "GET",
            "path": "/DataValues",
            "description": "Get all values",
            "target": "/databases/IbmCloud_tobljl5v_c71bl94O/collections/sensor-data?apiKey={token}"
          },
          {

            "verb": "GET",
            "path": "/DataValues/{id}",
            "description": "Get one record",
            "target": "/databases/IbmCloud_tobljl5v_c71bl94O/collections/sensor-data/{id}?apiKey={token}"
          }
      ],
   "attributes": [
      {
        "name": "temp",
        "type": "number"
      },
      {
        "name": "pulse",
        "type": "number"
      } 
    ]
   }
  ]
}

Update Token value and update Target values according to your MongoDB account.

Press Save.

You should see new Adapter called SensorData:

Screen Shot 2014-08-12 at 13.44.37

Click it and at the bottom of the page you will find DataValues entities icon:

Screen Shot 2014-08-12 at 13.45.42

Click it and you should see data recorded in the MongoDB:Screen Shot 2014-08-12 at 13.46.12

So far so good…

Click Application from the left menu:

Screen Shot 2014-08-12 at 13.49.06

And start building an App and give it a name and click Start building.

Click plus next to Data menu item on the left.

Select Existing object and choose SensorData and DataValues. Then click Next.

Click Generate List Screen and Next.

Click plus next to Screens menu item on the left and give the view a name.

Click table from the palate on the right.

Screen Shot 2014-08-12 at 13.53.09

 

Choose DataValues.

Click Preview on the right in the menu bar.

Screen Shot 2014-08-12 at 13.54.26

You should see your data in a simulated phone:

Screen Shot 2014-08-12 at 13.55.08

You can install Android RapidApps on your real phone and test the app in the real world.

Maybe it’s not shinning application. On the other side now we can play with the themes, widgets and make our app nicer and add an date/time column…

How many lines of code we have written and how long does it take to make this simple data viewer? We have not written any line of code (we just did some copy&change&paste with adapter definition) and the whole game took 5 minutes…

Ok, now am I more familiar with the IoT Cloud and Bluemix and it’s time to do something useful…

 

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *