.
With Evothings Studio, you develop your mobile applications using familiar web technologies. With ARTIK cloud, you send sensors' data to the cloud for storage and data analytics.
This project makes use of one of the Evothings sample application and adds some codes to send accelerometer data to ARTIK cloud.
.
.
Setup a Hexewear device at ARTIK cloudNote: Refer to this posting to find out details about working with ARTIK cloud.
Create a device type (Hexiwear Accelerometer)
Connect a device (Hexiwear Accelerometer HA01)
.
.
.
Setup Evothings Studio.
Follow this guide to setup the Evothings Studio.
.
.
The Code.
This project uses the node.js module "node-rest-client". In order to run node.js module in browser, a software tool called Browserify is used. You can find out more about Browserify at this link. Follows is the node-rest-client related code in app.js:
.
var Client = require("node-rest-client").Client;
...
// artik cloud node-rest-client functions
app.artikcloud = "https://api.artik.cloud/v1.1/messages";
app.bearer = "Bearer device-token";
app.sdid = "device-id";
app.c = new Client();
app.build_args = function(ax, ay, az, ts) {
var args = {
headers: {
"Content-Type": "application/json",
"Authorization": app.bearer
},
data: {
"sdid": app.sdid,
"ts": ts,
"type": "message",
"data": {
"x": ax,
"y": ay,
"z": az
}
}
};
return args;
};
// end artik cloud functions
...
// Try to connect the smartphone to the GATT server.
app.connect = function() {
...
var args = app.build_args(ax, ay, az, new Date().valueOf());
app.c.post(app.artikcloud, args, function(data, response) {
console.log(data);
});
...
};
.
Take note the following line in index.html file. The bundle-app.js file is used instead of the normal app.js file. Refer to the next section for instructions how to package this file.
<script src="bundle-app.js"></script>
.
Package the bundle-app.js.
Assuming that you have node.js and npm installed, follow these instructions to package the bundle-app.js.
.
npm install -g browserify
npm install node-rest-client
browserify app.js -o bundle-app.js
.
Build and run the mobile app.
Please beware that you will hit the "Plan quota exceeded" and "DEVICE MINUTE rate limit exceeded" errors very soon.
You need to generate a key in order to connect to a phone.
.
Enter the key generated above.
.
A "Connected" message appears.
.
Click RUN on the app to launch it on the connected phones.
.
.
.
.
.
.
.
Comments