Skip to Content
Technical Articles
Author's profile photo Kapil Verma

MQTT Device Simulator for IoT Service Cockpit

This blog is for all those people who are currently working on IoT space of SAP or planning to do the same. I was also exploring the space & faced a problem which I solved later & sharing here for all who are currently facing the same or may face it in future.

What’s SAP IoT Service Cockpit ?¬†

So, SAP has come up with IOT Service which gives you access to SAP’s on Cloud IoT solution called Internet of Things Service Cockpit. Its a ready to use solutions, so if you want to connect your IOT device with SCP, you can do some basic configurations & with few simple steps you can achieve the same. Cockpit provide two globally accepted channels of communication with device namely MQTT & REST.

What are we doing here ?

In this blog we will focus on a MQTT channel based device, or a device which communicate with cloud through MQTT communication channel. We are focusing on MQTT as its most common communication channel in IOT space, I was using the same & faced some issue which resulted in this blog.

Why was it required ?

So, I was basically doing a simple hands on where I wanted to define a simple device on the cockpit and try to simulate a scenario where, we send data to my configured device on the cockpit. I wanted a tool which takes a CSV file as an input and uses its data to send message to cloud through MQTT. I searched a lot but was not able to find any tool that can easily connect with the IOT Cockpit.

MQTT Device Simulator

I created a simple tool in NodeJS to do the same. So, if you want to send data to Cloud you need to create some IDs , generate a certificate and then you can send data using the same(we will see all this further). So , this tool takes the certificate as its(no need to do any conversions), your iDs, the CSV file and sends the data using MQTT to Cloud in the desired interval of time. Basically with this tool you can easily simulate a MQTT based IOT device for your testing without any need of a physical device.


  1.  NodeJS is installed on your machine.
  2. You have Created your Device Model IoT Cockpit(Capability, Sensor Type & MQTT Device).
  3. You have Generated your PEM Certificate for the Device & have your Secret Key.

Setting up the Tool

Now as all the above conditions are met, we can proceed further & follow the below steps to setup the simulator.

  • Download the Repository from GitHub : The Repository looks like as above, download it as zip file. Now, extract it on your machine so we can do the tweaks according to your device.
  • Open the “certificate” folder & replace the PEM certificate with your generated PEM certificate & rename it as “device1_certificate.pem”. Open “device1_passphrase.txt” , and enter the secret key you got during the PEM certificate generation on IoT Service Cockpit.
  • Replace or copy paste your required CSV data in “data.csv”, make sure you don’t rename it to something else, keep it as “data.csv”.
  • Now, time to make some changes to “csv_to_mqtt.js”, as per your device. I have defined 2 fields in code for testing namely, temperature & humidity. You , need to add your device specific fields on line 11, 12, 13, 14.
  • On line number 24 you will find below code. You can replace “5000” with desired interval time 1000 = 1 seconds.
  • On line number 27 you will find below code. You can replace Temp & Hum or can add more required fields.
  • Final Changes to be made on line number 35. You replace Temp & Hum or can add more required fields.

That’s all , you are good to go, just save the code. Open terminal & run the code. You will get the below messages in terminal , giving status of connection & the data that has been sent.

Assigned Tags

      You must be Logged on to comment or reply to a post.
      Author's profile photo Trinoy Hazarika
      Trinoy Hazarika



      Thanks a lot for the blog. When i try to run the application. I get the below error. I am running it on a windows machine.

      Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
      at Object.createSecureContext (_tls_common.js:104:17)
      at Object.exports.connect (_tls_wrap.js:1049:48)
      at Object.buildBuilder (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\node_modules\mqtt\lib\connect\tls.js:13:20)
      at MqttClient.wrapper [as streamBuilder] (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\node_modules\mqtt\lib\connect\index.js:140:36)
      at MqttClient._setupStream (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\node_modules\mqtt\lib\client.js:277:22)
      at new MqttClient (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\node_modules\mqtt\lib\client.js:258:8)
      at Object.connect (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\node_modules\mqtt\lib\connect\index.js:143:10)
      at connectToMQTT (C:\Users\I060653\Desktop\pregis\node-mqtt-simulator\app.js:65:27)

      Did you face a similar issue ?




      Author's profile photo Kapil Verma
      Kapil Verma
      Blog Post Author

      Hi Trinoy,

      Its seems you are using incorrect PEM certificate - Key pair, either incorrect PEM certificate or Incorrect Key used. Please recheck & try again, hope it solves your issue.



      Author's profile photo Trinoy Hazarika
      Trinoy Hazarika

      Hi Kapil,

      Found out the issue. The default digest was changed from MD5 to SHA256 in Openssl 1.1 and my TLS libs was was using MD5 to decrypt the PEM file and hence the error.

      So I had to start my node app with the below argument to provide the correct cipher.

      node --tls-cipher-list="DHE-RSA-AES128-SHA256" app.js