Skip to content

Commit e2a50ac

Browse files
author
Stefania
committed
first commit
0 parents  commit e2a50ac

15 files changed

+9724
-0
lines changed

.babelrc

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"env": {
3+
"commonjs": {
4+
"presets": [
5+
["env", {
6+
"useBuiltIns": false
7+
}]
8+
]
9+
},
10+
"es": {
11+
"presets": [
12+
["env", {
13+
"useBuiltIns": false,
14+
"modules": false
15+
}]
16+
]
17+
}
18+
}
19+
}

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# 2 space indentation
7+
[*.js]
8+
charset = utf-8
9+
indent_style = space
10+
indent_size = 2
11+
insert_final_newline = true
12+
trim_trailing_whitespace = true

.eslintrc.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
"extends": "airbnb-base",
3+
"env": {
4+
"browser": true,
5+
"jest": true
6+
}
7+
};

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
lib
3+
dist
4+
es
5+
.tmp

LICENSE.txt

+689
Large diffs are not rendered by default.

README.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
[![License: GPL v3](https://img.shields.io/badge/License-GPL%20v3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
2+
3+
# arduino-iot-js
4+
5+
JS module providing interaction with Arduino Cloud
6+
7+
## Installation
8+
9+
```bash
10+
$ npm install git+ssh://[email protected]/arduino/arduino-iot-js.git
11+
```
12+
13+
## How to use
14+
```javascript
15+
import ArduinoCloud from 'arduino-iot-js';
16+
17+
// connect establishes a connection with mqtt, using token as the password
18+
// Development Vernemq server host is wss.iot.oniudra.cc port 8443, token is your Hydra bearer token
19+
// options = {
20+
// host: 'BROKER_URL', // Default is wss.iot.oniudra.cc
21+
// port: BROKER_PORT, // Default is 8443
22+
// ssl: true/false, // Default is true
23+
// env: 'dev', // Api env, default is dev (for now!)
24+
// token: 'YOUR_BEARER_TOKEN' // Required!
25+
// apiUrl: 'AUTH SERVER URL', // https://auth-dev.arduino.cc for dev
26+
// onDisconnect: message => { /* Disconnection callback */ }
27+
// }
28+
ArduinoCloud.connect(options).then(connectionId => {
29+
// Connected
30+
});
31+
32+
ArduinoCloud.disconnect(connectionId).then(() => {
33+
// Disconnected
34+
});
35+
36+
ArduinoCloud.subscribe(connectionId, topic, cb).then(topic => {
37+
// Subscribed to topic, messaged fired in the cb
38+
});
39+
40+
ArduinoCloud.unsubscribe(connectionId, topic).then(topic => {
41+
// Unsubscribed to topic
42+
});
43+
44+
ArduinoCloud.sendMessage(connectionId, topic, message).then(() => {
45+
// Message sent
46+
});
47+
48+
ArduinoCloud.openCloudSerialMonitor(connectionId, deviceId, cb).then(topic => {
49+
// Serial monitor messages fired to cb
50+
});
51+
52+
ArduinoCloud.writeCloudSerialMonitor(connectionId, deviceId, message).then(() => {
53+
// Message sent to serial monitor
54+
});
55+
56+
ArduinoCloud.closeCloudSerialMonitor(connectionId, deviceId).then(topic => {
57+
// Close serial monitor
58+
});
59+
60+
// Send a property value to a device
61+
// - value can be a string, a boolean or a number
62+
// - timestamp is a unix timestamp, not required
63+
ArduinoCloud.sendProperty(connectionId, deviceId, name, value, timestamp).then(() => {
64+
// Property value sent
65+
});
66+
67+
// Register a callback on a property value change
68+
//
69+
ArduinoCloud.onPropertyValue(connectionId, deviceId, propertyName, updateCb).then(() => {
70+
// updateCb(message) will be called every time a new value is available. Value can be string, number, or a boolean depending on the property type
71+
});
72+
73+
```
74+
75+
## Run tests
76+
First of all you need a valid Hydra Arduino token, you can get it from [Create Cloud Dev](https://create-dev.arduino.cc/cloud/)
77+
78+
After you can use this token to run tests
79+
80+
```bash
81+
$ TOKEN=YOUR_HYDRA_TOKEN_HERE npm run test
82+
```

jest.config.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = {
2+
globals: {
3+
token: process.env.TOKEN,
4+
},
5+
verbose: true,
6+
setupFiles: [
7+
'./jest.setup.js',
8+
],
9+
};

jest.setup.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// File jest.setup.js
2+
// eslint-disable-next-line import/no-extraneous-dependencies
3+
require('whatwg-fetch');

0 commit comments

Comments
 (0)