Skip to content

Commit be4f65d

Browse files
committed
Renamed files (init requires file names < 15 characters) and added initial version of readme for e2e setup
1 parent cad5b8c commit be4f65d

File tree

4 files changed

+301
-2
lines changed

4 files changed

+301
-2
lines changed
File renamed without changes.

NodeJsControllerInitScript.sh renamed to MySensorsInitScript.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# PATH should only include /usr/* if it runs after the mountnfs.sh script
2020
PATH=/sbin:/usr/sbin:/bin:/usr/bin
2121
DESC="MySensors NodeJs Controller"
22-
NAME="NodeJsController.sh"
22+
NAME="MySensors.sh"
2323
PIDFILE="/usr/local/var/run/$NAME.pid"
2424
DAEMON="/home/pi/Arduino/NodeJsController/$NAME"
2525
DAEMON_ARGS="$PIDFILE"

Readme.html

+298
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
<h1>MySensors with NodeJS Controller and OTA bootloader on RPi</h1>
2+
<p>My RPi runs Arduino to compile and flash sketches and the bootloader. With this setup no separate PC/Mac is needed. Exactly the same could be achieved (faster) using a PC/Mac for all the Arduino compilation and flashing activities – just skip the steps and execute on PC/Mac instead.
3+
<h2>Hardware</h2>
4+
<p>Headless Raspberry Pi model B with wired Ethernet</p>
5+
<p>I'm connecting a monitor only for first time boot to get the IP address and then connect via Putty/xRDP</p>
6+
<h2>Download and install latest Raspbian version on a fresh SD-Card</h2>
7+
<p>Tutorials for this task are available on the internet (<a href="http://downloads.raspberrypi.org/raspbian_latest">download</a>, <a href="http://sourceforge.net/projects/win32diskimager">copy to SD</a>)</p>
8+
<h2>Setup base parameters</h2>
9+
<p>(adjust to your needs - here: RPi-IP: 10.0.1.5 / Router-IP: 10.0.1.1 / password: test / timezone: Europe,Berlin / hostname: mysensors)</p>
10+
<ul>
11+
<li>login as pi / raspberry
12+
<li>sudo nano /etc/network/interfaces
13+
<p>#iface eth0 inet dhcp<br/>
14+
iface eth0 inet static<br/>
15+
address 10.0.1.5<br/>
16+
netmask 255.255.255.0<br/>
17+
gateway 10.0.1.1<br/>
18+
nameserver 10.0.1.1</p>
19+
<li>sudo raspi-config
20+
<ul>
21+
<li>1. Expand Filesystem
22+
<li>2. Change User Password<br/>
23+
<p>test</p>
24+
<li>4. Internationalisation Options
25+
<ul>
26+
<li>I2. Change Timezone
27+
<p>Europe / Berlin</p>
28+
</ul>
29+
<li>8. Advanced Options
30+
<ul>
31+
<li>A2. Hostname
32+
<p>mysensors</p>
33+
<li>A3. Memory Split
34+
<p>16</p>
35+
</ul>
36+
</ul>
37+
<li>Finish
38+
<li>Reboot
39+
</ul>
40+
<h2>Install latest updates</h2>
41+
<ul>
42+
<li>login as pi / test
43+
<li>sudo apt-get update
44+
<li>sudo apt-get upgrade
45+
<li>sudo reboot
46+
</ul>
47+
<h2>Install Remote Desktop</h2>
48+
<p>Optional… my RPi is headless and I use xRDP to connect from a Windows PC to run a graphical UI if needed (e.g. for Arduino IDE)</p>
49+
<ul>
50+
<li>login as pi / test
51+
<li>sudo apt-get install xrdp
52+
<li><i>to confirm it's working as expected try to connect from a remote computer to the RPi (e.g. from a Windows PC using the "Remote Desktop Connection" tool)</i>
53+
</ul>
54+
<h2>Install NodeJS (here: latest stable version available for RPi: 0.10.28)</h2>
55+
<ul>
56+
<li>login as pi / test
57+
<li>sudo mkdir /opt/node
58+
<li>wget http://nodejs.org/dist/v0.10.28/node-v0.10.28-linux-arm-pi.tar.gz
59+
<li>tar xvzf node-v0.10.28-linux-arm-pi.tar.gz
60+
<li>rm node-v0.10.28-linux-arm-pi.tar.gz
61+
<li>sudo cp -r node-v0.10.28-linux-arm-pi/* /opt/node
62+
<li>rm -rf node-v0.10.28-linux-arm-pi/
63+
<li>sudo nano /etc/profile
64+
<p>NODE_JS_HOME="/opt/node"<br/>
65+
PATH="$PATH:$NODE_JS_HOME/bin"<br/>
66+
export PATH</p>
67+
<li>sudo reboot
68+
<li><i>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)</i>
69+
</ul>
70+
<h2>Install MongoDB</h2>
71+
<ul>
72+
<li>login as pi / test
73+
<li>sudo useradd -c mongodb -d /home/mongodb -m -U mongodb
74+
<li>sudo mkdir -p /opt/mongo/bin
75+
<li>sudo mkdir /var/lib/mongodb
76+
<li>sudo chown mongodb:nogroup /var/lib/mongodb
77+
<li>sudo mkdir /var/log/mongodb
78+
<li>sudo chown mongodb:nogroup /var/log/mongodb
79+
<li>wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongo
80+
<li>wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongod
81+
<li>wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/mongodump
82+
<li>wget https://github.com/brice-morin/ArduPi/raw/master/mongodb-rpi/mongo/bin/bsondump
83+
<li>sudo mv mongo /opt/mongo/bin/
84+
<li>sudo mv mongod /opt/mongo/bin/
85+
<li>sudo mv mongodump /opt/mongo/bin/
86+
<li>sudo mv bsondump /opt/mongo/bin/
87+
<li>sudo chmod -R 775 /opt/mongo/bin
88+
<li>sudo ln -s /opt/mongo/bin/mongod /usr/bin/mongod
89+
<li>wget https://raw.githubusercontent.com/skrabban/mongo-nonx86/master/debian/mongodb.conf
90+
<li>wget https://raw.githubusercontent.com/skrabban/mongo-nonx86/master/debian/init.d
91+
<li>sudo mv mongodb.conf /etc/mongodb.conf
92+
<li>sudo mv init.d /etc/init.d/mongodb
93+
<li>sudo chmod 755 /etc/init.d/mongodb
94+
<li>sudo update-rc.d mongodb defaults
95+
<li>sudo reboot
96+
<li><i>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)</i>
97+
<li><i>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”</i>
98+
</ul>
99+
<h2>Install Arduino (and update to latest 1.0.5)</h2>
100+
<ul>
101+
<li>login as pi / test
102+
<li>sudo apt-get install arduino
103+
<li>wget http://arduino.googlecode.com/files/arduino-1.0.5-linux32.tgz
104+
<li>tar zxvf arduino-1.0.5-linux32.tgz
105+
<li>rm arduino-1.0.5-linux32.tgz
106+
<li>cd arduino-1.0.5
107+
<li>rm -rf hardware/tools
108+
<li>sudo cp -ru lib /usr/share/arduino
109+
<li>sudo cp -ru libraries /usr/share/arduino
110+
<li>sudo cp -ru tools /usr/share/arduino
111+
<li>sudo cp -ru hardware /usr/share/arduino
112+
<li>sudo cp -ru examples /usr/share/doc/arduino-core
113+
<li>sudo cp -ru reference /usr/share/doc/arduino-core
114+
<li>cd ~
115+
<li>rm -rf arduino-1.0.5
116+
</ul>
117+
<h2>Enable programming via GPIO UART (for serial gateway only)</h2>
118+
<ul>
119+
<li>login as pi / test
120+
<li>wget https://github.com/SpellFoundry/avrdude-rpi/archive/master.zip
121+
<li>unzip master.zip
122+
<li>rm master.zip
123+
<li>cd avrdude-rpi-master
124+
<li>sudo cp autoreset /usr/bin
125+
<li>sudo cp avrdude-autoreset /usr/bin
126+
<li>sudo mv /usr/bin/avrdude /usr/bin/avrdude-original
127+
<li>sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude
128+
<li>cd ..
129+
<li>rm -rf avrdude-rpi-master
130+
</ul>
131+
<h2>Install MySensors from Git branch development (here: password: test)</h2>
132+
<ul>
133+
<li>login as pi / test
134+
<li>git clone https://github.com/mysensors/Arduino.git
135+
<li>cd Arduino
136+
<li>git checkout development
137+
<li>cd NodeJsController
138+
<li>npm install
139+
<li>nano NodeJsController.js (optional : removing sample firmwares)
140+
<p>const fwHexFiles = [ ];</p>
141+
<li><i>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</i>
142+
</ul>
143+
<h2>Start NodeJsController on boot</h2>
144+
<ul>
145+
<li>cd ~/Arduino/NodeJsController
146+
<li>chmod 755 *.sh
147+
<li>sudo cp MySensorsInitScript.sh /etc/init.d/mysensors
148+
<li>sudo mkdir -p /usr/local/var/run
149+
<li>sudo chmod -R 777 /usr/local/var/run
150+
<li>sudo update-rc.d mysensors defaults
151+
<li>sudo reboot
152+
<li><i>to confirm that NodeJsController is starting at boot, check the log file /home/pi/logs/NodeJsController.log</i>
153+
</ul>
154+
<h2>Configure Arduino</h2>
155+
<ul>
156+
<li>start graphical UI (startx on RPi or via RDP)
157+
<li>start Arduino IDE
158+
<li>File - Preferences
159+
<ul>
160+
<li>set sketchbook location to /home/pi/Arduino
161+
<li>enable verbose output for compilation
162+
<li>enable verbose output for upload
163+
</ul>
164+
<li>Close Arduino IDE
165+
</ul>
166+
167+
<h1>Serial Gateway</h1>
168+
<h2>Hardware</h2>
169+
<ul>
170+
<li>as described for the standard Serial Gateway
171+
<li>I'm using the version with inclusion mode button and LEDs based on no Arduino but a plain ATmega328p on a breadboard
172+
<li>Connect directly to the serial GPIO pins of the RPi:
173+
<p>Arduino GND <-> Raspberry Pi GND (pin 6)<br/>
174+
Arduino RX <-> Raspberry Pi TX (pin 8)<br/>
175+
Arduino TX <-> Raspberry Pi RX (pin 10)<br/>
176+
Arduino RESET <-> Raspberry Pi GPIO22 (pin 15)</p>
177+
<li>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
178+
</ul>
179+
<h2>Disable default use of serial port</h2>
180+
<ul>
181+
<li>sudo nano /etc/inittab
182+
<p>#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100</p>
183+
<li>sudo nano /boot/cmdline.txt - remove part of the file:
184+
<p>console=ttyAMA0,115200</p>
185+
<li>cd /dev
186+
<li>sudo ln -s ttyAMA0 ttyUSB9
187+
<li>sudo apt-get install minicom
188+
<li>sudo reboot
189+
</ul>
190+
<h2>Flash (assuming that the ATmega has a valid Arduino bootloader installed)</h2>
191+
<ul>
192+
<li>login as pi / test
193+
<li>start Arduino IDE
194+
<ul>
195+
<li>Tools - Board - Arduino - Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
196+
<li>Tools - Serial Port - /dev/ttyUSB9
197+
<li>File - Sketchbook - SerialGateway
198+
<li>File - Upload
199+
</ul>
200+
</ul>
201+
<h2>Setup NodeJsController</h2>
202+
<ul>
203+
<li>nano ~/Arduino/NodeJsController/NodeJsController.js
204+
<p>//const gwType = 'Ethernet';<br/>
205+
//const gwAddress = '10.0.1.99';<br/>
206+
//const gwPort = 9999;<br/>
207+
const gwType = 'Serial';<br/>
208+
const gwPort = '/dev/ttyAMA0';<br/>
209+
const gwBaud = 115200;</p>
210+
<li>sudo service mysensors restart
211+
</ul>
212+
213+
<h1>Ethernet Gateway</h1>
214+
<h2>Hardware</h2>
215+
<ul>
216+
<li>as described for the standard Ethernet Gateway
217+
<li>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
218+
</ul>
219+
<h2>Adjust Sourcecode (here: address 10.0.1.99 / port: 9999)</h2>
220+
<ul>
221+
<li>[I you are running into compilation errors due to missing files in the utility directory, do the following]
222+
cp -R ~/Arduino/libraries/UIPEthernet/src/utility ~/Arduino/libraries/UIPEthernet/utility
223+
<li>nano ~/Arduino/libraries/MySensors/MyConfig.h
224+
<p>//#define DEBUG</p>
225+
<li>start Arduino IDE
226+
<ul>
227+
<li>File - Sketchbook - EthernetGateway
228+
<li>Edit source code
229+
<p>#define IP_PORT 9999<br/>
230+
IPAddress myIp (10, 0, 1, 99);</p>
231+
<li>Optional : adjust source code to given hardware
232+
<ul>
233+
<li>Correct include for Ethernet module type (if not using ENC28J60)
234+
<li>Switch MyGateway constructor if using inclusion mode button and LEDs
235+
</ul>
236+
<li>File - Save
237+
</ul>
238+
<h2>Flash (assuming that the ATmega has a valid Arduino bootloader installed)</h2>
239+
<ul>
240+
<li>Connect ethernet gateway to RPi (setup as above for serial gateway or via USB FTDI cable
241+
<li>login as pi / test
242+
<li>start Arduino IDE
243+
<ul>
244+
<li>Tools - Board - Arduino - Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328
245+
<li>Tools - Serial Port - /dev/ttyUSB9 (or /dev/ttyUSB0 if connecting through USB cable)
246+
<li>File - Sketchbook - EthernetGateway
247+
<li>File - Upload
248+
</ul>
249+
</ul>
250+
<h2>Setup NodeJsController</h2>
251+
<ul>
252+
<li>nano ~/Arduino/NodeJsController/NodeJsController.js
253+
<p>const gwAddress = '10.0.1.99';</p>
254+
<li>sudo service mysensors restart
255+
</ul>
256+
257+
<h1>Sensor Node Bootloader</h1>
258+
<h2>Hardware</h2>
259+
<ul>
260+
<li>as described for a simple Sensor Node
261+
<li>here: no Arduino but a plain ATmega328p on a breadboard
262+
<li>using DallasTemperature example (one sensor connected to pin 3)
263+
</ul>
264+
<h2>Compile Bootloader (can be skipped but good to see if everything is working)</h2>
265+
<ul>
266+
<li>cd ~/Arduino/Bootloader
267+
<li>make
268+
<li><i>this should compile the bootloader and produce three files in the same directory: MyOtaBootloader.o / MyOtaBootloader.elf / MyOtaBootloader.hex</i>
269+
</ul>
270+
<h2>Flash Bootloader</h2>
271+
<ul>
272+
<li>cd ~/Arduino/Bootloader
273+
<li>nano Makefile
274+
<li>adjust avrdude settings to the available programmer. In my case (mySmartUSB MK3 programmer temporarily connected to RPi USB port):
275+
<p>ISP_PORT = /dev/ttyUSB0<br/>
276+
ISP_SPEED = 115200<br/>
277+
ISP_PROTOCOL = stk500v2<br/>
278+
ISP_MCU = m328p</p>
279+
<li>make load
280+
</ul>
281+
282+
<h1>End-to-End Test</h1>
283+
<h2>Add Firmware to Controller</h2>
284+
<ul>
285+
<li>nano ~/Arduino/NodeJsController/NodeJsController.js
286+
<p>const fwHexFiles = [ 'DallasTemperatureSensor.cpp.hex' ];<br/>
287+
const fwDefaultType = 0;</p>
288+
<li>sudo service mysensors restart
289+
</ul>
290+
<h2>Flash Firmware OTA</h2>
291+
<ul>
292+
<li>tail -f ~/logs/NodeJsController.log
293+
<li>Power up sensor node with OTA bootloader
294+
</ul>
295+
<h2>Check functionality</h2>
296+
<ul>
297+
<li>in addition to watching the log file (tail command above) you can connect to the mongo db using a client (e.g. <a href="http://robomongo.org">Robomongo</a>) and check if new values are written to the database as a real end-to-end test
298+
</ul>

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"version": "0.0.1",
44
"description": "MySensors Controller based on Node JS",
55
"dependencies": {
6+
"mongodb": "~1.4.7",
67
"net": "~1.0.2",
7-
"mongodb": "~1.4.7"
8+
"serialport": "^1.4.5"
89
}
910
}

0 commit comments

Comments
 (0)