[ intel Edison ] Node.js + REST API 開關燈才夠潮!

將目前最潮的 Node.js + Edison + REST API 簡單結合~點亮你的世界 如何使用 Node.js以及 REST API 請參考 [intel Edison] Node.js + intel Edison 快速實作 REST API

  • Step 1. 準備所需要的裝置

    1.LED Socket Kit

    2.Seeed studio BASE SHIELD

    3.Edison Imgur

  • Step 2. 初始化 所需要的 GPIO 腳位

var mraa = require('mraa'); //require mraa  
console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console

//var myOnboardLed = new mraa.Gpio(5, false, true); //LED hooked up to digital pin (or built in pin on Galileo Gen1)
var myOnboardLed = new mraa.Gpio(5); 

myOnboardLed.dir(mraa.DIR_OUT); //set the gpio direction to output  
  • Step 3. 初始化 Node.js 的 express 框架
var app = require('express')();  
var http = require('http').Server(app);  
http.listen(1339, function () {//指定為1339 Port  
    'use strict';
    console.log('listening on *:1339');
  • Step 4.REST API

    1.開燈API:http://<Edison URL>:1339/open

    2.關燈API:http://<Edison URL>:1339/close

app.get('/open', function (req, res) {//開燈  
    'use strict';
app.get('/close', function (req, res) {//關燈  
    'use strict';
  • Step 5. 使用Postman 測試

    1.開燈API:http://<Edison URL>:1339/open Imgur Imgur

    2.關燈API:http://<Edison URL>:1339/close Imgur Imgur



Having being a full stack engineer. His interests in Node.js, ARM mbed, IoT solutions, iOS Contact us : [email protected]

ALL RIGHTS RESERVED. COPYRIGHT © 2016. Designed and Coded by Makee.io