Blynk 物聯網平台: How to install Node.js library on Linux(control LED)

 
Blynk 官網:http://www.blynk.cc
 
Blynk一開始在 Kickstarter campaign募資平臺上,募得49,000美元(約150萬臺幣)。Blynk在 Feb 2015 上線,並且持續更新當中。
 

 
Blynk是一個讓使用者能快速建立控制和監測硬體專題的新平臺,支援 iOS 和 Android 裝置。下載 Blynk app 後,可以建立一個專題控制平臺並佈署按鈕、控制條、圖表和其他工具。使用這些工具,你可以開關腳位或檢視感測器傳來的顯示資料。
 
不管是怎樣的專題,都很可能有數百個硬體製作的教學影片,這讓硬體部分容易得多,但是建立軟體介面仍然相當困難。有了Blynk,將會讓軟體平臺的建立比硬體製作還要簡單。Blynk 是簡易專題的絕佳平臺選擇,例如監控水族箱的溫度或遙控開關電燈。以我個人來說,我都用它來實驗各式各樣物聯網應用情境。
 

 
目前Blynk支援大部分的Arduino控制板、Raspberry Pi模組、ESP8266微控器、Particle Core和其他常見的微型控制器和單板電腦,日後還會持續新增支援平臺。亦支援Arduino Wi-F和乙太網路模組,也可以透過連接電腦的USB插槽進行控制。
 
Blynk 支援自己建立一個封閉的Blynk伺服器,能夠把所有資料保留在自家網路中。本站未來將實作此例,請持續關注本站最新文章.
 
儘管目前還有其他透過網路控制硬體的平臺(Particle、 ThingSpeak、 Temboo、IFTTT),Blynk是當中最易使用的,同時不僅免費且也符合開源的MIT許可。更多詳細資訊和下載Blynk的連結,請見官方網站
 

2017-10-12 週四     How to install Node.js library on Linux

 
 
參考:
 
[準備材料]
 
樹莓派 3B *1 (MyPi4)
LED *1
220 歐姆 *1
 
 
[硬體接線]
 
 
 
BCM:
LED
Pi
+
GPIO 18
220 歐姆
220 歐姆
GND
 
[測試]
 
Create a new test file “LED.py”
touch LED.py && sudo nano LED.py
 
LED.py
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)
print "LED on"
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
print "LED off"
GPIO.output(18,GPIO.LOW)
 
sudo LED.py
 
 
[安裝]
 
install node.js  library on Linux
 
 移除舊版 node.js
sudo apt-get purge node node.js  node.js -y
確認移除舊版 node.js
sudo npt-get autoremove
 
Automatic node.js installation
 
add repositories
curl -sl https://deb.nodesource.com/setup_6.x| sudo -E bash -
 
install node.js
sudo apt-get update && sudo apt-get upgrade
sudo apt-get install build-essential nodejs -y
 
Check node.js and npm installation
node --version
v6.11.4
 
npm --v
3.10.10
 
Install Blynk globally and Run Blynk client
 
install Blynk
sudo npm install blynk-library -g
 
執行結果如下:
/usr/bin/blynk-client -> /usr/lib/node_modules/blynk-library/bin/blynk-client.js
/usr/bin/blynk-ctrl -> /usr/lib/node_modules/blynk-library/bin/blynk-ctrl.js
/usr/lib
`-- blynk-library@0.4.7
 
 
sudo npm install onoff -g
 
執行結果如下:
> epoll@0.1.22 install /usr/lib/node_modules/onoff/node_modules/epoll
> node-gyp rebuild
 
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/6.11.4"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/lib/node_modules/onoff/node_modules/epoll/.node-gyp"
make: Entering directory '/usr/lib/node_modules/onoff/node_modules/epoll/build'
  CXX(target) Release/obj.target/epoll/src/epoll.o
   SOLINK_MODULE(target) Release/obj.target/epoll.node
  COPY Release/epoll.node
make: Leaving directory '/usr/lib/node_modules/onoff/node_modules/epoll/build'
/usr/lib
`-- onoff@1.1.7
  `-- epoll@0.1.22
    +-- bindings@1.2.1
    `-- nan@2.6.2
 
Run default Blynk client
export PATH=$PATH:/opt/nodejs/bin/
unset NODE_PATH
blynk-client YourAuthToken
 
 
 
執行結果如下:
OnOff mode
Connecting to: blynk-cloud.com8441
SSL authorization...
Connected
Authorized
Blynk ready.
 
使用手機 app 執行功能
 
[Creating a new node.js project with Blynk]
 
mkdir my-awesome-project
cd my-awesome-project
npm init
 
確認以下資訊:
name: (my-awesome-project)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /home/pi/my-awesome-project/package.json:
 
{
  "name": "my-awesome-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}

Is this ok? (yes)
 
Add Blynk to project
npm install blynk-library
 
allows direct pin operations(option)
npminstallonoff--save
 
ls
node_modules  package.json
 
less package.json
{
  "name": "my-awesome-project",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "blynk-library": "^0.4.7",
    "onoff": "^1.1.7"
  }
}
package.json (END)
 
 
touch index.js && sudo nano index.js
 
index.js
var Blynk = require('blynk-library');
var Gpio= require('onoff').Gpio;
var led = new Gpio(18,'out');
 
var AUTH = 'your key'; 
 
var blynk = new Blynk.Blynk(AUTH);
 
var v0 = new blynk.VirtualPin(0);
 
v0.on('write', function(param) {
 
   if (param[0] == '1') {
     led.writeSync(1);
   } else {
     led.writeSync(0);
   }
 
   console.log('V0:',param[0]);
 
});
 
 
less index.js
 
pi@MyPi4:~/my-awesome-project $ ls
index.js  node_modules  package.json
 
node index.js
OnOff mode
Connecting to: blynk-cloud.com8441
SSL authorization...
Connected
Authorized
 
[設定 blynk app]
 

 

 
 
 
 
 
 
 
 

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *