In certain situations when we are building out our prototypes there will be instances where we will not have access to a component or device. In my case I didn't have a 2016 Tesla Model X lying around so that I can test how far it can go on one charge. :)
For this demo I created a new device through ARTIK Cloud and utilized the device simulator to generate random data. Our main goal is to create, collect and visualize data that you want your device to produce. This way you can test, experiment with ideas and concepts even before you start programming and soldering any hardware saving time, money and other resources.
Getting startedTo get started you will need to:
1 ) Signup or Login to ARTIK Cloud
2 ) Download the device simulator
After these two steps are completed we are ready to create a new device and configure our device manifest file.
Navigate to developer.artik.cloud/dashboard to create a new device or simply click on "DASHBOARD".
Click on the blue plus sign to create a new device type.
- Type in a new device name and organization identifier.
Now it's time to create and configure your device manifest file which we will use later to generate some data.
Click on "+ NEW MANIFEST " to create a new manifest.
The fields in your manifest represent a value that your sensor will be generating. In other words, if we want to capture miles or distance from our Tesla then we want to create a field that will capture miles. The field "distance" is one of many that you can use as a default. Of course you can create your own. To learn more about the device manifest navigate to developer.artik.cloud/documentation/introduction/the-manifest.html
Fill out the fields or enter your own values.
You can skip the "Device Actions" portion for this demo.
- Select the "Activate Manifest" tab. Click the blue button "ACTIVATE MANIFEST" to finish the manifest process.
Last step before we dive into the terminal and the command line we must create an actual device so it shows up in our device simulator.
- Navigate to artik.cloud/my/devices
- click on " + Connect another device..."
- type your device name you created during the manifest process.
- Select your device and then click "CONNECT DEVICE" at the bottom.
To generate sensor data we must run a script using command line. In this demo I am using the Mac terminal but you can use Windows or Linux. Before we open the terminal we need to attain a user id from developer.artik.cloud/api-console/ See the image below.
Now we can open the terminal and change your directory to where you have the device-simulator.jar file. I have mine on the Desktop. Replace the token with your Authorization code (e.g. token).
Next, type in the command below and press enter.
$ java -jar device-simulator.jar -token=authorizationtoken
Successfully entering the command with the right token will initiate the simulator.
This next process shows your list of devices, uses your device id to create base scenario JSON file that corresponds to your devices manifest, configuring the JSON file and finally generating random data. If you get stuck you can just type "?" to see the list of commands and other help information.
To see your list of devices type lower case "ld":
$ ld
Copy paste the "did" which stands for Device Id. Let's now create a template scenario using that device id like so:
$ gs 89ac176847934e4384730d903ba28f2f test
This command creates a folder and inside of it a JSON file. This folder is saved wherever you executed the device-simulator. In my case it was saved on my desktop. Your JSON file should look something like the sample JSON code below. If your device manifest has a lot of fields this JSON file will look much different. Learn more about this process and scenarios at developer.artik.cloud/documentation/tools/device-simulator.html#scenarios
{
"period": 1000,
"data": {},
"sdid": "this is your device id",
"api": "POST",
"config": {"distance": {
"min": 0,
"max": 10000,
"function": "random",
"type": "Double"
}},
"deviceToken": "this token is automatically generated"
}
Let's start generating and sending data to ARTIK Cloud. We can reuse our command from before and change the for letter of "gs" to "rs":
$ rs 89ac176847934e4384730d903ba28f2f test
If you followed the steps correctly you can run your scenario and start seeing your data being sent. In a few seconds you will also notice ARTIK Cloud capture and plot your data in the timeline automatically. Great Job!!
Comments