wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.46.tar.gz tar zxvf bcm2835-1.46.tar.gz cd bcm2835-1.46 ./configure make sudo make check sudo make install sudo npm install -g node-dht-sensor
连接传感器
GND至GND
DAT信号到GPIO7
VCC至3.3v
创建可执行文件
1 2
cd ~ git clone https://github.com/wanghurui/Blynk-dht11-22.git
var blynkLib = require('blynk-library'); var sensorLib = require('node-dht-sensor');
varAUTH = 'YOUR\_AUTH\_TOKEN';
// Setup Blynk var blynk = new blynkLib.Blynk(AUTH);
// Setup sensor, exit if failed var sensorType = 11; // 11 for DHT11, 22 for DHT22 and AM2302 var sensorPin = 4; // The GPIO pin number for sensor signal if (!sensorLib.initialize(sensorType, sensorPin)) { console.warn('Failed to initialize sensor'); process.exit(1); }
// Automatically update sensor value every 2 seconds setInterval(function() { var readout = sensorLib.read(); blynk.virtualWrite(3, readout.temperature.toFixed(1)); blynk.virtualWrite(4, readout.humidity.toFixed(1)); console.log('Temperature:', readout.temperature.toFixed(1) + 'C'); console.log('Humidity: ', readout.humidity.toFixed(1) + '%'); }, 2000);