上QQ阅读APP看书,第一时间看更新
Preparing an SD card
To prepare an SD card, follow the sequence of actions as described:
- Download the latest Raspbian LITE image (available at https://www.raspberrypi.org/downloads/raspbian/).
- Connect your SD card to a computer and use Etcher (https://etcher.io/) to flash the Raspbian .img file to the SD card.
- Enable SSH:
cd /Volumes/boot
touch ssh
- To enable Wi-Fi, create the wpa_supplicant.conf file with the following content:
network={
ssid="YOUR_SSID"
psk="YOUR_WIFI_PASSWORD"
}
To create a file in a Linux console, you can use the GNU nano editor. It is pre-installed in most Linux distributives. All you need is to run the nano FILE_NAME command and follow the displayed instructions.
- Create the /home/pi/sensor folder.
- Create the /home/pi/sensor/package.json file with the following content:
{
"name": "sensor",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"request": "^2.81.0",
"rpi-dht-sensor": "^0.1.1"
}
}
- Create the /home/pi/sensor/index.js file, replacing REMOTE-SERVER-ADDRESS.com with a real value. The file should contain the following:
var rpiDhtSensor = require('rpi-dht-sensor');
var request = require('request');
var receiver = 'http://REMOTE-SERVER-ADDRESS.com:8080';
var dht = new rpiDhtSensor.DHT11(2);
function read () {
var readout = dht.read();
var data = {
temperature: readout.temperature.toFixed(2),
humidity: readout.humidity.toFixed(2)
};
console.log(data);
data.device = 'raspberry';
request.post({url: receiver, form: data}, function(err) {
if(err) console.log('Failed to send to ' + receiver);
});
setTimeout(read, 1000);
}
read();
- Create the /home/pi/sensor/Dockerfile file with the following content:
FROM hypriot/rpi-node:boron-onbuild