JS module providing interaction with Arduino Cloud
$ npm install arduino-iot-js
import ArduinoCloud from 'arduino-iot-js';
// connect establishes a connection with mqtt, using token as the password
// options = {
// host: 'BROKER_URL', // Default is wss.iot.arduino.cc
// port: BROKER_PORT, // Default is 8443
// ssl: true/false, // Default is true
// token: 'YOUR_BEARER_TOKEN' // Required!
// apiUrl: 'AUTH SERVER URL', // Default is https://auth.arduino.cc
// onDisconnect: message => { /* Disconnection callback */ }
// }
ArduinoCloud.connect(options).then(() => {
// Connected
});
ArduinoCloud.disconnect().then(() => {
// Disconnected
});
ArduinoCloud.subscribe(topic, cb).then(topic => {
// Subscribed to topic, messaged fired in the cb
});
ArduinoCloud.unsubscribe(topic).then(topic => {
// Unsubscribed to topic
});
ArduinoCloud.sendMessage(topic, message).then(() => {
// Message sent
});
ArduinoCloud.openCloudMonitor(deviceId, cb).then(topic => {
// Cloud monitor messages fired to cb
});
ArduinoCloud.writeCloudMonitor(deviceId, message).then(() => {
// Message sent to cloud monitor
});
ArduinoCloud.closeCloudMonitor(deviceId).then(topic => {
// Close cloud monitor
});
// Send a property value to a device
// - value can be a string, a boolean or a number
// - timestamp is a unix timestamp, not required
ArduinoCloud.sendProperty(thingId, name, value, timestamp).then(() => {
// Property value sent
});
// Register a callback on a property value change
//
ArduinoCloud.onPropertyValue(thingId, propertyName, updateCb).then(() => {
// 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
});
// Re-connect with a new authentication token, keeping the subscriptions
// to the Things topics
ArduinoCloud.updateToken(newToken).then(() => {
// Successful reconnection with the provided new token
});
First of all you need a valid Hydra Arduino token, you can get it from Arduino Create IoT Cloud
Then you can use this token to run tests
$ TOKEN=YOUR_HYDRA_TOKEN_HERE npm run test