跳转到主要内容

面向英特尔® XDK IOT EDITION 的 NODE.JS* 模板

editor 提交于

<center><img src="http://intel.eetrend.com/files/2016-03/wen_zhang_/100001240-1088-886320…; alt=""></center>

<strong>简介</strong>

英特尔® XDK IoT Edition 是一种 HTML5 混合与 Node.js 应用开发环境,支持您部署、运行和调试面向不同物联网平台(比如英特尔® Galileo 和英特尔® Edison 开发板)的应用。借助作为英特尔® 物联网开发人员套件一部分发布的 Linux* 映像和Grove* Starter Kit Plus – 英特尔® IoT Edition,您的开发平台能够连接英特尔 XDK IoT Editon 并运行 Node.js 应用。除具备开发功能之外,英特尔 XDK IoT Edition 还可提供不同的 Node.js 模板和示例(基于英特尔物联网平台运行)。如欲了解有关入门的更多信息,请参阅英特尔® XDK IoT Edition 入门。

<strong>目的</strong>

英特尔® XDK IoT Edition 中的模板可提供无与伦比的功能,例如,通过不同的方式处理出入于传感器(连接开发板的 I/O 针脚)的模拟数据和数字数据。为实现与传感器之间的通信,每个相关模板都使用 MRAA Sensor Communication Library。该通用库旨在帮助开发人员和传感器制造商以更简单的方法在所支持的硬件上映射其传感器和制动器,并通过高级语言和结构控制下层通信协议。

<strong>设计注意事项</strong>

模板使用需在开发板上安装 MRAA 库和英特尔® XDK 后台程序。这两点要求包含在与英特尔物联网开发人员套件一同发布的 Linux 映像之中,该映像支持开发板与英特尔® XDK IoT Edition 之间实现通信,以及对 I/O 针脚的访问。

<strong>开发和测试</strong>

每个模板均在第一代和第二代英特尔® Galileo 开发板以及英特尔® Edison 开发板上进行测试。

<strong>面向英特尔® XDK IoT Edition 的 Node.js 模板</strong>

板载 LED 闪烁

这款简单的 Node.js 应用可使英特尔® 物联网平台上的 LED 指示灯闪烁。

资料来源:https://github.com/gomobile/iotapp-template-onboard-led-blink

1 var mraa = require('mraa'); //require mraa
2 ​console.log('MRAA Version: ' + mraa.getVersion()); //write the mraa version to the Intel XDK console
3 var myOnboardLed = new mraa.Gpio(13); //LED hooked up to digital pin 13 (or built in pin on Galileo Gen1 & Gen2 plus Edison Arduino Breakout board)
4 myOnboardLed.dir(mraa.DIR_OUT); //set the gpio direction to output

模拟读取

这款简单的 Node.js 应用可读取英特尔® 物联网平台上模拟针脚的数据。

资料来源:https://github.com/gomobile/iotapp-template-analog-read

1 var mraa = require('mraa'); //require mraa
2 console.log('MRAA Version:' + mraa.getVersion()); //write the mraa version to the console
3 var analogPin0 = new mraa.Aio(0); //setup access analog input Analog pin #0 (A0)
4 var analogValue = analogPin0.read(); //read the value of the analog pin
5 console.log(analogValue); //write the value of the analog pin to the console

数字读取

这款简单的 Node.js 应用可读取英特尔® 物联网平台上数字针脚的数据。

资料来源:https://github.com/gomobile/iotapp-template-digital-read

1 var mraa = require('mraa'); //require mraa
2 console.log('MRAA Version:' + mraa.getVersion()); //write the mraa version to the console
3 var myDigitalPin6 = new mraa.Gpio(6); //setup digital read on Digital pin #6 (D6)
4 myDigitalPin6.dir(mraa.DIR_IN); //set the gpio direction to input

数字写入

这款简单的 Node.js 应用可将数据写入英特尔® 物联网平台上的数字针脚。

资料来源:https://github.com/gomobile/iotapp-template-digital-write

1 var mraa = require('mraa'); //require mraa
2 console.log('MRAA Version:' + mraa.getVersion()); //write the mraa version to the console
3 var myDigitalPin5 = new mraa.Gpio(5); //setup digital read on Digital pin #5 (D5)
4 myDigitalPin5.dir(mraa.DIR_OUT); //set the gpio direction to output
5 myDigitalPin5.write(1); //set the digital pin to high (1)
PWM

这款简单的 Node.js 应用可读取和写入模拟数值,以通过英特尔® 物联网平台上的数字针脚 (PWM) 调暗 LED 指示灯。

资料来源:https://github.com/gomobile/iotapp-template-pwm

1 var mraa = require("mraa"); //require mraa
2 //Initialize PWM on Digital Pin #3 (D3) and enable the pwm pin
3 var pwm3 = new mraa.Pwm(3, -1, false);
4 pwm3.enable(true);