What if you're building or testing Internet of Things (IoT) solutions based on the IBM IoT Platform service ... but don't have an actual device to connect to it? Even if you have a device, maybe you want it to emit specific types and patterns of data?
This is a heavily commented node.js application, that acts as a "fake device", connects to the IBM IoT Platform service and emits data. The type and pattern of data can easily be controlled via a few lines of code.
For a full specification of the payload, see the IBM IoT Platform docs, specifically the MQTT Connectivity for Devices section.
Note that this simulated device can only connect to your instance of the IBM IoT Platform service if it has been registered. This can either be done via the IoT Platform dashboard or its API.
Make sure to use the following information when registering this app as device:
Device ID : "my-device-simulator"
Device Token: "mydevicesimulatortoken"
Device Type : "device-simulator"
Device Authentication method : "token"
The application uses Node.js and npm. Start at step 2 if you have them installed already.
-
Install Node.js (this will also install npm)
-
Go to the project folder in the terminal and install the required npm modules:
npm install
-
Generate an .env file containing the information that you used to register the device simulator in your IoT Platform organization:
iotf_org=<myOrg> iotf_type=<myDeviceType> iotf_id=<myId>‚ iotf_authtoken=<myAuthToken>
-
Start the application:
node app.js
-
Add a web interface
- Allow the entry of the IoT platform org via web interface
- Allow customization via web interface (format and content of data packets, MQTT topics, ...)
- Display status of app (# of messages, topics, data packets, ...) via web interface
-
Simulate multiple devices in parallel (useful for load testing)
-
Make app deployable to Bluemix via "Deploy to Bluemix button"
This sample code is licensed under Apache 2.0. Full license text is available in LICENSE.
Find more open source projects on the IBM Github Page
"# tormenta"