This is a starter code to connect to ARTIK Cloud Firehose WebSocket (/live) endpoint using ARTIK Cloud Java SDK. By running this sample you will learn to:
- Connect to the ARTIK Cloud Firehose WebSocket url.
- Monitor realtime messages sent to ARTIK Cloud by the specified source device.
Consult An IoT remote control for how to develop an Android monitor app.
- Java 7 or higher
- ARTIK Cloud Java SDK (version >= 2.1.2)
- Apache Maven
-
At My ARTIK Cloud, connect a device of the type "Example Simple Smart Light" (unique type name
cloud.artik.example.simple_smartlight). You can use the one that you already own. -
Get the device ID for your newly created device in the Device Info screen.
-
Retrieve a user token using our api-console, or via oauth2 authentication with your own application.
-
Clone this repository if you haven't already done so.
-
At the root directory and run the command:
mvn clean packageThe executable
websocket-monitor-x.x.jaris generated under the target directory. -
Run the command at the target directory to learn the usage:
java -jar websocket-monitor-x.x.jar
- Start and run the following command in the target directory:
java -jar websocket-monitor-x.x.jar -device YOUR_DEVICE_ID -token YOUR_USER_TOKEN
- Send messages to your Example Simple Smart Light using the Online Device Simulator. Simulate the device with following settings:
* Simulate data on the boolean "state" field with default 5000 ms (5 secs).
* Alternative between true/false value by setting the data pattern to "alternating boolean".
- In your running sample application you will see the received messages. Here is the example output:
Connecting to: wss://api.artik.cloud/v1.1/live?authorization=bearer+aa176...&device=bb101...
Status: CONNECTING ...
Connection successful with code:[101]
Received ping with ts:[1507328677960]
Received message:[class MessageOut {
data: {state=true}
cid: null
ddid: null
sdid: bb101...
ts: 1507328710000
type: message
mid: ba31d3eb38e342a49226828ff1dac58d
uid: ff123...
sdtid: dtd1d3e0934d9348b783166938c0380128
cts: 1507328699982
mv: 1
}]
Received message:[class MessageOut {
data: {state=false}
cid: null
ddid: null
sdid: bb101...
ts: 1507328715000
type: message
mid: 8070d27294f04620a82b389c9e768aab
uid: ff123...
sdtid: dtd1d3e0934d9348b783166938c0380128
cts: 1507328704710
mv: 1
}]
Received ping with ts:[1507328707969]- Stop the simulation so it does not accrue any more data usage.
If you are not familiar with ARTIK Cloud, we have extensive documentation at https://developer.artik.cloud/documentation
The full ARTIK Cloud API specification can be found at https://developer.artik.cloud/documentation/api-reference/
Peek into advanced sample applications at https://developer.artik.cloud/documentation/tutorials/code-samples
To create and manage your services and devices on ARTIK Cloud, visit the Developer Dashboard at https://developer.artik.cloud
Licensed under the Apache License. See LICENSE.
Copyright (c) 2017 Samsung Electronics Co., Ltd.