Step 1: Get prerequisites
You are going to need following tools:
You can verify your installation by running the following in a Terminal window:
$ git --version git version 2.17.1 $ node -v v10.4.1 $ npm -v 6.1.0
Step 2: Download Sample Project
We have provided a simple sample to get you started. In the Terminal window run following command to clone the sample repository to your local machine:
git clone https://github.com/wiihey/nodejs-mqtt-client-demo.git
Step 3: Build and Run
Change to the directory that holds the sample:
You need to install the dependencies to build the sample. Run the following command:
Wait for a while. Once it is finished, you can run the app:
When the app starts, it displays
WiiHey DaaS Client Started in the terminal window.
$ node src/index.js WiiHey DaaS Client Started Connected to WiiHey DaaS Platform
Appendix: Configure APP-ID and APP-KEY
Should you receive APP-ID and APP-KEY when purchasing WiiHey product. You will need configure them in the code in order to receive messages properly.
Please find following code in
src/index.js and modify accordingly.
// Please change APP_ID and APP_KEY to those provided by WiiHey Customer Service var APP_ID = "demo"; var APP_KEY = "demo123";
Appendix: Work with Devices
When Device sends message to WiiHey DaaS Platform, you may see output like this: