This sample app demonstrates how to use Wiliot webhooks to receive events from Wiliot Cloud Platform. The app is written in Node.js and uses the Express framework. It also uses the ngrok tool to generate a webhook URL.
- Node.js installed on your machine
- ngrok installed on your machine
- A Wiliot account. If you don't have one, you can sign up here.
- A Wiliot device. If you don't have one, you can buy one here.
-
Clone this repository to your local machine.
-
Change directory to demos/wiliot-demo-webhooks-nodejs
$ cd demos/wiliot-demo-webhooks-nodejs
- Run the following command to install the dependencies:
$ npm install
- Run the following command to start the app:
$ npm start
- You should see the following output in the terminal:
vyshakhbabji@Vyshakhs-Mini wiliot-demo-webhooks % npm start
> demos@1.0.0 start
> node index.js
Starting ngrok . Please wait ...
Webhook url is ready to use. Your webhook url is : https://6285-2600-1700-dd90-14f0-fc10-ab-3e0a-9a1b.ngrok.io/webhook
Starting express server....
Your webhookURL is: https://6285-2600-1700-dd90-14f0-fc10-ab-3e0a-9a1b.ngrok.io/webhook
Started Server....
App is listening at http://localhost:8080
-
Copy the webhook url from the output and use it in the setting-up-webhook-connection process.
-
Open the ngrok dashboard at http://localhost:4040/inspect/http to inspect the events sent to your webhook url.
-
When you test the webhooks on Wiliot's management portal, you should see the events in the ngrok dashboard and in the terminal where you started the app similar to the following:
Event received:
Event Name temperature
Value 35.5
StartTime 1675828046616
EndTime 1675828046616
OwnerId 607737204301
CreatedOn 1675828046616
AssetId testAsset
CategoryID testCategory
Confidence 0.50
KeySet [ (key: temperature, value: 35.5) ]