Skip to Content

IoT messages have a new home !!

^

/o \

| # |

LL

/wp-content/uploads/2016/07/newhome_cartoon_1002662.jpg

Yes, you heard it right! Do you know that you can change the storage residence (schema/tables) of your IOT messages to the place you want!! This short blog shows you exactly how it can be achieved.



This article assumes that you have a basic idea of how to use SAP HANA IOT on both features of MMS & RDMS, in case not, please first go through one of a very good article on SCN given below –

http://scn.sap.com/community/developer-center/cloud-platform/blog/2015/06/09/using-the-sap-hcp-iot-services(http://www.slideshare.net/saphcp/sap-hcp-iot)


So, once you deploy your IoT MMS, you will see a default data binding & associated schema created automatically for you. Something like this –

/wp-content/uploads/2016/07/1_1002677.png

As you see here, the DB/schema id is taken as <trialaccountid>trial.iotmms.web automatically.

And the iotmms application creates a default binding to this default data source like this –

/wp-content/uploads/2016/07/2_1002678.png

So whenever you receive a message, the message will go into your “<trialaccount>.iotmms.web” schema in a table starting with “IOT_<messagetypeID>”. You may want to keep your IoT schema under check and would like to keep all your data at one place to your own database/schema instead of keeping it to the default.

The process of changing this starts very easy six step process, follow me –

Step1 – Stop the IOTMMS Application

Goto your cockpit and select “Java Application”, you will the application named “iotmms” on the right hand side (This application lists by itself when you deploy the “Message Management Service”).

/wp-content/uploads/2016/07/3_1002679.png

Stop the application by clicking “Stop”

/wp-content/uploads/2016/07/4_1002680.png

Click “Ok”

/wp-content/uploads/2016/07/5_1002681.png

This will stop the “iotmms” application.

Step 2 – Delete the default data binding

Click on “Data source bindings” & then click on the /wp-content/uploads/2016/07/delete_1002703.png(delete) icon

/wp-content/uploads/2016/07/6_1002682.png

Delete the binding by clicking “OK” button

/wp-content/uploads/2016/07/7_1002689.png

Step 3 – Create a new data binding.

Click “New Binding” to create a new binding.

/wp-content/uploads/2016/07/8_1002690.png

Clicking on new binding will open up a dialog like this –

/wp-content/uploads/2016/07/9_1002701.png

Keep the data source as “<default>”, select your MDC in the place of “DB/Schema ID” and your custom logon with the database user and it’s corresponding password.

Click “Save”

/wp-content/uploads/2016/07/10_1002692.png

Clicking on “Save” will create your default binding for “iotmms” application.

(Prerequisite to this step – you shall have a MDC database running on your account & you also need a database user created, I’m assuming this to be “iotadmin” for the sake of easy understandability. Ensure you give this user enough rights to access your MDC database).

This step does half of our job!!

The java application named “iotmms” looks at this databinding and finds that now it needs to use a new DB/Schema ID instead of default and the user by which it needs to perform the action is “iotadmin”.

Step 4 – Create a table

Now is the time to build your new castle! Create a table under your application/project schema.

I am planning to move all my messages to schema named “almirah” and table called “shelf2016”, so here is the script to prepare my shelf’s structure.


CREATE column TABLE "almirah"."shelf2016"
(
                "G_DEVICE" VARCHAR(255) CS_STRING,
                "G_CREATED" VARCHAR(255) CS_STRING,
                "C_MESSAGE" VARCHAR(255) CS_STRING,
                "C_REPERCUSSION" VARCHAR(255) CS_STRING
)


Step 5 – Register the Service mapping

It’s time to define a new address to let the world know the messages shall come to my new address now! To define the same, open postman and provide the following –

  1. Request type – Choose “PUT” from the list of request types.


   2. Requested resource – Put the below URL, don’t forget to substitute your hana accound id in the URL

https://iotmms<yourhanaaccountid>trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/processing/

Authorization – Choose “BasicAuth” in the type field, you will be prompted to assign the values of username & password, enter your hana trial account id and it’s corresponding password. Click “Update Request”.



   3. Headers

    1. Add “Content-type” as “application/json
    2. Note that you don’t have to touch the “Authorization” key and value pair, remember we added authorization in step 3, the values you see here are coming from there! So, touch it not!

   4. Body


{
"deviceType": "52b4aebce8643885b93b",
"messageType": "a1bb5c4916575af30c53",
"processingServices": [
    {
      "name": "sql",
      "properties": {
"mms.processing.sql.mappings": {
          "table_name": "shelf2016",
          "column_name":[
              {
"field":"G_DEVICE",
"column":"G_DEVICE"         
              },
              {
"field":"G_CREATED",
                "column": "G_CREATED"
              },
              {
"field":"message",
"column":"C_MESSAGE"         
              },
              {
"field":"repercussion",
                "column": "C_REPERCUSSION"
              }
              ]
        },
"mms.processing.sql.schema_name": "almirah",
"mms.processing.sql.hana.table_type": "column"
      }
    }
]
}


/wp-content/uploads/2016/07/11_1002693.png

Let’s read what’s in the stars now..:-p

Star 1 shows which devicetype is registering for a new address, the value of this attribute is the ID of the devicetype you want all the messages to go to new address.

Star 2 – shows you the message type for registration. As you know one device type can have many message types and hence specifying message type makes perfect sense to uniquely identify which all messages shall go to this new address.

Star 3 – tells the table in which new messages will go to

Star 4 – Tells which schema this table resides in.

So, stars are showing us the way…!!

Once you run the request by pressing “Send” button, you shall see a message like this which confirms that the registration is done and whenever a message of specified ID & device ID comes, it will go the schema and table defined in the request.

/wp-content/uploads/2016/07/12_1002694.png

Cool!  Time to Test !!

Step 6 – Resend a new message

Send a message from Postman or any rest client (including one in the cockpit) and see the messaging pouring in to the new schema & table..!

Did you see your friend just sent a message to help him on getting a new home..! Go ahead..sharing is the new caring..!! Enjoy!!

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply