Headless Raspberry Pi model B with wired Ethernet
I'm connecting a monitor only for first time boot to get the IP address and then connect via Putty/xRDP
Tutorials for this task are available on the internet (download, copy to SD)
(adjust to your needs - here: RPi-IP: 10.0.1.5 / Router-IP: 10.0.1.1 / password: test / timezone: Europe,Berlin / hostname: mysensors)
- login as pi / raspberry
- sudo nano /etc/network/interfaces
#iface eth0 inet dhcp
iface eth0 inet static
address 10.0.1.5
netmask 255.255.255.0
gateway 10.0.1.1
nameserver 10.0.1.1 - sudo raspi-config
- 1. Expand Filesystem
- 2. Change User Password
test
- 4. Internationalisation Options
- I2. Change Timezone
Europe / Berlin
- I2. Change Timezone
- 8. Advanced Options
- A2. Hostname
mysensors
- A3. Memory Split
16
- A2. Hostname
- Finish
- Reboot
- login as pi / test
- sudo apt-get update
- sudo apt-get upgrade
- sudo reboot
- login as pi / test
- sudo mkdir /opt/node
- wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz
- tar xvzf node-v0.10.28-linux-arm-pi.tar.gz
- rm node-v0.10.28-linux-arm-pi.tar.gz
- sudo cp -r node-v0.10.28-linux-arm-pi/* /opt/node
- rm -rf node-v0.10.28-linux-arm-pi/
- sudo nano /etc/profile
NODE_JS_HOME="/opt/node"
PATH="$PATH:$NODE_JS_HOME/bin"
export PATH - sudo reboot
- to confirm it's working as expected login as pi/test and run "node -v" which should return the installed node version (here: v0.10.28)
- login as pi / test
- sudo useradd -c mongodb -d /home/mongodb -m -U mongodb
- sudo mkdir -p /opt/mongo/bin
- sudo mkdir /var/lib/mongodb
- sudo chown mongodb:nogroup /var/lib/mongodb
- sudo mkdir /var/log/mongodb
- sudo chown mongodb:nogroup /var/log/mongodb
- wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongo
- wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongod
- wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongodump
- wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/bsondump
- sudo mv mongo /opt/mongo/bin/
- sudo mv mongod /opt/mongo/bin/
- sudo mv mongodump /opt/mongo/bin/
- sudo mv bsondump /opt/mongo/bin/
- sudo chmod -R 775 /opt/mongo/bin
- sudo ln -s /opt/mongo/bin/mongod /usr/bin/mongod
- wget https://raw.githubusercontent.com/skrabban/mongo-nonx86/master/debian/mongodb.conf
- wget https://raw.githubusercontent.com/skrabban/mongo-nonx86/master/debian/init.d
- sudo mv mongodb.conf /etc/mongodb.conf
- sudo mv init.d /etc/init.d/mongodb
- sudo chmod 755 /etc/init.d/mongodb
- sudo update-rc.d mongodb defaults
- sudo reboot
- to confirm it's working as expected login as pi/test and run "/opt/mongo/bin/mongo" which should start the mongo shell (type "exit" to close the shell again)
- if the RPi loses power without proper shutdown while mongod is running, you can't restart without manually removing the pid file first. To do so run “sudo rm /var/lib/mongodb/mongod.lock”
- login as pi / test
- git clone https://github.com/mysensors/Arduino.git
- cd Arduino
- git checkout development
- cd NodeJsController
- npm install
- to confirm that the NodeJsController is working as expected and connects to the local mongo DB: "node NodeJsController.js" which should start the controller, connect to the database and run into an error connecting to the gateway. Stop node again via Ctrl-c
- cd ~/Arduino/NodeJsController
- chmod 755 *.sh
- sudo cp MySensorsInitScript.sh /etc/init.d/mysensors
- sudo mkdir -p /usr/local/var/run
- sudo chmod -R 777 /usr/local/var/run
- sudo update-rc.d mysensors defaults
- sudo reboot
- to confirm that NodeJsController is starting at boot, check the log file /home/pi/logs/NodeJsController.log
- as described for the standard Serial Gateway - using the standard Serial Gateway sketch with DEBUG (in MyConfig.h) disabled
- I'm using the version with inclusion mode button and LEDs based on no Arduino but a plain ATmega328p on a breadboard
- Connect directly to the serial GPIO pins of the RPi:
Arduino GND <-> Raspberry Pi GND (pin 6)
Arduino RX <-> Raspberry Pi TX (pin 8)
Arduino TX <-> Raspberry Pi RX (pin 10)
Arduino RESET <-> Raspberry Pi GPIO22 (pin 15) - Right now I'm using a separate power supply for the serial gateway instead of the 3.3V or 5V pins of the RPi because I ran in some issues with power consumption during programming
- sudo nano /etc/inittab
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
- sudo nano /boot/cmdline.txt - remove part of the file:
console=ttyAMA0,115200 - cd /dev
- sudo ln -s ttyAMA0 ttyUSB9
- sudo apt-get install minicom
- sudo reboot
- nano ~/Arduino/NodeJsController/NodeJsController.js
//const gwType = 'Ethernet';
//const gwAddress = '10.0.1.99';
//const gwPort = 9999;
//const gwType = 'Serial';
//const gwPort = '/dev/ttyAMA0';
//const gwBaud = 115200; - sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
- as described for the standard Ethernet Gateway - using the standard Ethernet Gateway sketch with DEBUG (in MyConfig.h) disabled
- I'm using the version with inclusion mode button and LEDs based on no Arduino but a plain ATmega328p on a breadboard and the ENC28J60 Ethernet module
- here: 10.0.1.99 / port: 9999
- nano ~/Arduino/NodeJsController/NodeJsController.js
const gwAddress = '10.0.1.99';
- sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
- as described for a simple Sensor Node
- here: no Arduino but a plain ATmega328p on a breadboard
- using DallasTemperature example (one sensor connected to pin 3)
- cd ~/Arduino/Bootloader
- make
- this should compile the bootloader and produce three files in the same directory: MyOtaBootloader.o / MyOtaBootloader.elf / MyOtaBootloader.hex
- cd ~/Arduino/Bootloader
- nano Makefile
- adjust avrdude settings to the available programmer. In my case (mySmartUSB MK3 programmer temporarily connected to RPi USB port):
ISP_PORT = /dev/ttyUSB0
ISP_SPEED = 115200
ISP_PROTOCOL = stk500v2
ISP_MCU = m328p - make load
- use Arduino IDE or codebender or whatever other way to compile your sketch
- copy the compiled DallasTemperatureSensor.cpp.hex file to the NodeJsController directory (if using the Arduino IDE, enable verbose logging in preferences and then watch the compilation process to find the temp directory where the output is stored)
- nano ~/Arduino/NodeJsController/NodeJsController.js
const fwHexFiles = [ 'DallasTemperatureSensor.cpp.hex' ];
const fwDefaultType = 0; - sudo service mysensors restart (at this point stop/restart doesn't work. use "sudo killall node" followed by "sudo service mysensors start" instead)
- tail -f ~/logs/NodeJsController.log
- Power up sensor node with OTA bootloader
- in addition to watching the log file (tail command above) you can connect to the mongo db using a client (e.g. Robomongo) and check if new values are written to the database as a real end-to-end test once the bootloader finished uploading the firmware