├── README.md └── index.js /README.md: -------------------------------------------------------------------------------- 1 | # Raspberry Preserve 2 | A Raspberry Pi based BitTorrent Sync client. 3 | 4 | Once you have a clean install of a Raspberry Pi running Noobs update it by running the commands below. 5 | 6 | sudo apt-get update 7 | sudo apt-get upgrade 8 | 9 | 10 | ## Install latest Node.js 11 | 12 | sudo wget http://node-arm.herokuapp.com/node_latest_armhf.deb 13 | sudo dpkg -i node_latest_armhf.deb 14 | 15 | ## Install NPM 16 | 17 | sudo apt-get npm 18 | 19 | ## Create a project directory and initialize it 20 | 21 | create npm package 22 | npm init 23 | touch index.js 24 | nano index.js 25 | 26 | ## Add btsync repo manually and install 27 | 28 | Follow these instruction https://melgrubb.wordpress.com/2014/08/03/raspberry-pi-home-server-part-14-bittorrent-sync/ 29 | 30 | sudo apt-get btsync 31 | 32 | ## Install node packages 33 | 34 | sudo npm install bittorrent-sync —-save 35 | sudo npm install onoff --save 36 | 37 | ## Install Forever globally 38 | 39 | sudo npm install forever -g 40 | 41 | ## Fire up index.js with forevereverytime your boot up the pi 42 | 43 | crontab -u pi -e 44 | @reboot /usr/bin/sudo -u pi -H /usr/local/bin/forever start /home/pi/projects/preserve/index.js 45 | sudo reboot -h 0 46 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var util = require('util'); 2 | 3 | var Gpio = require('onoff').Gpio, 4 | led1 = new Gpio(17, 'out'), 5 | led2 = new Gpio(18, 'out'), 6 | led3 = new Gpio(22, 'out'), 7 | led4 = new Gpio(23, 'out'); 8 | 9 | var BTSync = require('bittorrent-sync'), 10 | btsync = new BTSync({ 11 | host: '0.0.0.0', 12 | port: 8888, 13 | username: 'YOURUSERNAME', 14 | password: 'YOURPASSWORD' 15 | }); 16 | 17 | 18 | var transferring = false; 19 | 20 | var currentLed = 1; 21 | 22 | var transferCheck = setInterval(function(){ 23 | 24 | btsync.getSpeed(function(err, data) { 25 | 26 | // What's hapnin? 27 | //console.log(data); 28 | //if (err) throw err; 29 | 30 | if(data.download > 0 || data.upload > 0){ 31 | transferring = true; 32 | } 33 | 34 | if(transferring){ 35 | 36 | // Cycle LEDs to show activity 37 | if(currentLed == 1){ 38 | led1.writeSync(1); 39 | led2.writeSync(1); 40 | led4.writeSync(1); 41 | led3.writeSync(0); 42 | currentLed++; 43 | } else if(currentLed == 2){ 44 | led1.writeSync(0); 45 | led2.writeSync(1); 46 | led4.writeSync(1); 47 | led3.writeSync(1); 48 | currentLed++; 49 | } else if(currentLed == 3){ 50 | led1.writeSync(1); 51 | led2.writeSync(0); 52 | led4.writeSync(1); 53 | led3.writeSync(1); 54 | currentLed++; 55 | } else if(currentLed == 4){ 56 | led1.writeSync(1); 57 | led2.writeSync(1); 58 | led4.writeSync(0); 59 | led3.writeSync(1); 60 | currentLed = 1; 61 | } 62 | 63 | } else { 64 | 65 | // Turn LEDs on solid. 66 | led1.writeSync(1); 67 | led2.writeSync(1); 68 | led3.writeSync(1); 69 | led4.writeSync(1); 70 | //led1.unexport(); // Unexport GPIO and free resources 71 | } 72 | 73 | }); 74 | 75 | 76 | }, 200); --------------------------------------------------------------------------------