Git Product home page Git Product logo

node-wio-link's Introduction

node-wio-link

NPM Version

A node.js client library for using the Wio Link API.

Table Of Contents

Documentation

Official Documentation: http://seeed-studio.github.io/Wio_Link/

Built-In Grove APIs: https://github.com/Seeed-Studio/Wio_Link/wiki/Built-in-Grove-APIs

All methods return a promise, which either resolves to the data received, or rejects with an error.

User Management

// Creates a new user account.
wioClient.user.create(String email, String password)

// Changes the password of an existing account.
wioClient.user.changePassword(String userToken, String newPassword)

// Retrieve the password of an existing account.
wioClient.user.retrievePassword(String email)

// Log in to the server with the given credentials.
wioClient.user.login(String email, String password)

Node Management

// Creates a new node.
wioClient.nodeManagement.create(String userToken, String name, optional String boardType)

// List the nodes associated with the user.
wioClient.nodeManagement.list(String userToken)

// Rename an existing node.
wioClient.nodeManagement.rename(String userToken, String newName, String nodeSN)

// Delete an existing node.
wioClient.nodeManagement.delete(String userToken, String nodeSN)

Grove Driver

// Retrieve all of the grove drivers' information.
wioClient.groveDriver.info(String userToken)

// Retrieve the status of last driver scanning.
wioClient.groveDriver.scanStatus(String userToken)

Boards/Platform

// List all of the supported boards.
wioClient.boards.list(String userToken)

Single Node

// Lists all of the available resources on a node.
wioClient.node.wellKnown(String nodeToken)

// Read the property of a Grove module.
wioClient.node.read(String nodeToken, String groveInstName, String property, String...args)

// Write to a Grove module.
wioClient.node.write(String nodeToken, String groveInstName, String PropertyOrMethodOrAction, String...args)

// Put the node to sleep.
wioClient.node.sleep(String nodeToken, Number sleepAmount)

// Retrieve the API reference page from the node.
wioClient.node.resources(String nodeToken)

// Trigger the OTA process for the node.
wioClient.node.otaTrigger(String nodeToken, Object data, optional Number buildPhase)

// Track the OTA status of the node.
wioClient.node.otaStatus(String nodeToken)

// Get the configuration of the node.
wioClient.node.config(String nodeToken)

// Change the data exchange server for the node.
wioClient.node.changeDataExchangeServer(String nodeToken, String address, String dataxurl)

Coding on the fly

// Upload a user's logic block to a node.
wioClient.cotf.uploadULB(String nodeToken, Object data)

// Download a user's logic block from a node.
wioClient.cotf.downloadULB(String nodeToken)

// Get the value of a variable on the node.
wioClient.cotf.getVariable(String nodeToken, String varName)

// Set the value of a variable on the node.
wioClient.cotf.setVariable(String nodeToken, String varName, String varValue)

// Call a function on the node.
wioClient.cotf.callFunction(String nodeToken, String funcName, String arg)

Custom API calls

In case there's a few APIs that aren't covered in this library, a bunch of custom functions are available to use. They will return the response received from making the call.

// Perform a custom HEAD request
wioClient.custom.head(String url)

// Perform a custom GET request
wioClient.custom.get(String url, Object parameters)

// Perform a custom POST request
wioClient.custom.post(String url, Object parameters)

// Perform a custom PUT request
wioClient.custom.put(String url, Object parameters)

// Perform a custom DELETE request
wioClient.custom.delete(String url)

Examples

Using Promises

// serverLocation can be 'us' or 'cn'
const wioClient = require('node-wio-link')(serverLocation);

wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality')
  .then(data => console.log(data))
  .catch(error => console.log(error));

Using Async/Await

// serverLocation can be 'us' or 'cn'
const wioClient = require('node-wio-link')(serverLocation);

(async function() {
  try {
    const airQuality = await wioClient.node.read(nodeToken, 'GroveAirqualityA0', 'quality');
    console.log(airQuality);
  } catch (error) {
    console.log(error);
  }
})();

node-wio-link's People

Contributors

tejashah88 avatar

Watchers

 avatar  avatar

Forkers

hokiedsp

node-wio-link's Issues

POST to light change to Ws2812 light strip

It seems that https://us.wio.seeed.io/v1/node/.... does not like application/json post request, when change/set value to OUTPUT device.

For example, if I want to set LED strip color with a post request:
node/GroveLedWs2812D0/clear/20/00FF00
It would error out as: { error: 'Can not accept application/json post request.' }

The fix is to add another header to your index.js file, line 21, such as:
'Content-Type': 'application/x-www-form-urlencoded',
then it would get around the problem.

calling read(), or write() on

I am trying to light up a light strip as:
wioClient.node.write(nodeToken, 'GroveLedWs2812D0', 'clear', '32', '880000')

but got the following error:
TypeError: arguments.splice is not a function
at Object.write (/PATH/PROJ/node_modules/node-wio-link/index.js:73:110)

In general it has problem with "arguments.splice", same issue with "wioClient.node.read()".

Add testing

  • Add unit tests
  • Add regression testing for previous issues
  • Add Travis CI integration
  • Add coveralls.io integration

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.