From 9dd396b89b721b77f738b719234b9507ab229d3f Mon Sep 17 00:00:00 2001 From: Mr Skrivning Date: Thu, 21 Aug 2014 00:11:24 +0200 Subject: [PATCH 1/4] Fixed appending of commands + a serial initialization what worked better (only tested Serial, not ethernet) --- NodeJsController/NodeJsController.js | 34 +++++++++++++++++++++------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/NodeJsController/NodeJsController.js b/NodeJsController/NodeJsController.js index f033e1c..6c52630 100644 --- a/NodeJsController/NodeJsController.js +++ b/NodeJsController/NodeJsController.js @@ -4,6 +4,7 @@ const gwPort = 9999; //const gwType = 'Serial'; //const gwPort = 'COM4'; +//const gwPort = '/dev/ttyUSB0'; //const gwBaud = 115200; const dbAddress = '127.0.0.1'; @@ -116,6 +117,7 @@ const P_ULONG32 = 5; const P_CUSTOM = 6; var fs = require('fs'); +var appendedString=""; function crcUpdate(old, value) { var c = old ^ value; @@ -516,6 +518,22 @@ function sendRebootMessage(destination, gw) { gw.write(td); } + +function appendData(str, db, gw) { + pos=0; + while (str.charAt(pos) != '\n' && pos < str.length) { + appendedString=appendedString+str.charAt(pos); + pos++; + } + if (str.charAt(pos) == '\n') { + rfReceived(appendedString.trim(), db, gw); + appendedString=""; + } + if (pos < str.length) { + appendData(str.substr(pos+1,str.length-pos-1), db, gw); + } +} + function rfReceived(data, db, gw) { if ((data != null) && (data != "")) { console.log('<- ' + data); @@ -526,7 +544,10 @@ function rfReceived(data, db, gw) { var command = +datas[2]; var ack = +datas[3]; var type = +datas[4]; - var rawpayload = datas[5].trim(); + var rawpayload=""; + if (datas[5]) { + rawpayload = datas[5].trim(); + } var payload; if (command == C_STREAM) { payload = []; @@ -635,9 +656,7 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err gw.on('connect', function() { console.log('connected to ethernet gateway at ' + gwAddress + ":" + gwPort); }).on('data', function(rd) { - var rds = rd.toString().split('\n'); - for (var i = 0; i < rds.length; i++) - rfReceived(rds[i].trim(), db, gw); + appendData(rd.toString(), db, gw); }).on('end', function() { console.log('disconnected from gateway'); }).on('error', function() { @@ -646,14 +665,13 @@ dbc.connect('mongodb://' + dbAddress + ':' + dbPort + '/' + dbName, function(err gw.setEncoding('ascii'); }); } else if (gwType == 'Serial') { - gw = require('serialport').SerialPort(gwPort, { baudrate: gwBaud }, false); + var SerialPort = require('serialport').SerialPort; + gw = new SerialPort(gwPort, { baudrate: gwBaud }); gw.open(); gw.on('open', function() { console.log('connected to serial gateway at ' + gwPort); }).on('data', function(rd) { - var rds = rd.toString().split('\n'); - for (var i = 0; i < rds.length; i++) - rfReceived(rds[i].trim(), db, gw); + appendData(rd.toString(), db, gw); }).on('end', function() { console.log('disconnected from gateway'); }).on('error', function() { From b936e0aebed36394801162bdcb1195cd38d2ceff Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Thu, 21 Aug 2014 00:50:57 +0200 Subject: [PATCH 2/4] RPi init script to run NodeJsController at boot time execute the following to install: chmod 755 *.sh sudo cp NodeJsControllerInitScript.sh /etc/init.d/mysensors sudo update-rc.d mysensors defaults sudo mkdir -p /usr/local/var/run sudo chmod -R 777 /usr/local/var/run --- NodeJsController/NodeJsController.sh | 8 + .../NodeJsControllerInitScript.sh | 160 ++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 NodeJsController/NodeJsController.sh create mode 100644 NodeJsController/NodeJsControllerInitScript.sh diff --git a/NodeJsController/NodeJsController.sh b/NodeJsController/NodeJsController.sh new file mode 100644 index 0000000..99bf500 --- /dev/null +++ b/NodeJsController/NodeJsController.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# pidfile must be first argument +PIDFILE=$1 +mkdir -p /home/pi/logs +cd /home/pi/Arduino/NodeJsController +/opt/node/bin/node NodeJsController.js >>/home/pi/logs/NodeJsController.log 2>&1 $PIDFILE diff --git a/NodeJsController/NodeJsControllerInitScript.sh b/NodeJsController/NodeJsControllerInitScript.sh new file mode 100644 index 0000000..2c934a5 --- /dev/null +++ b/NodeJsController/NodeJsControllerInitScript.sh @@ -0,0 +1,160 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: mysensors +# Required-Start: $remote_fs $syslog $mongodb +# Required-Stop: $remote_fs $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: MySensors NodeJs Controller +# Description: MySensors NodeJs Controller +### END INIT INFO + +# Author: Foo Bar +# +# Please remove the "Author" lines above and replace them +# with your own name if you copy and modify this script. + +# Do NOT "set -e" + +# PATH should only include /usr/* if it runs after the mountnfs.sh script +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="MySensors NodeJs Controller" +NAME="NodeJsController.sh" +PIDFILE="/usr/local/var/run/$NAME.pid" +DAEMON="/home/pi/Arduino/NodeJsController/$NAME" +DAEMON_ARGS="$PIDFILE" +DAEMON_USER="pi" +SCRIPTNAME=/etc/init.d/$NAME + +# Exit if the package is not installed +[ -x "$DAEMON" ] || exit 0 + +# Read configuration variable file if it is present +[ -r /etc/default/$NAME ] && . /etc/default/$NAME + +# Load the VERBOSE setting and other rcS variables +. /lib/init/vars.sh + +# Define LSB log_* functions. +# Depend on lsb-base (>= 3.2-14) to ensure that this file is present +# and status_of_proc is working. +. /lib/lsb/init-functions + +# +# Function that starts the daemon/service +# +do_start() +{ + # Return + # 0 if daemon has been started + # 1 if daemon was already running + # 2 if daemon could not be started + start-stop-daemon --start --quiet --chuid $DAEMON_USER --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \ + || return 1 + start-stop-daemon --start --quiet --chuid $DAEMON_USER --pidfile $PIDFILE --exec $DAEMON -- \ + $DAEMON_ARGS \ + || return 2 + # Add code here, if necessary, that waits for the process to be ready + # to handle requests from services started subsequently which depend + # on this one. As a last resort, sleep for some time. +} + +# +# Function that stops the daemon/service +# +do_stop() +{ + # Return + # 0 if daemon has been stopped + # 1 if daemon was already stopped + # 2 if daemon could not be stopped + # other if a failure occurred + start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME + RETVAL="$?" + [ "$RETVAL" = 2 ] && return 2 + # Wait for children to finish too if this is a daemon that forks + # and if the daemon is only ever run from this initscript. + # If the above conditions are not satisfied then add some other code + # that waits for the process to drop all resources that could be + # needed by services started subsequently. A last resort is to + # sleep for some time. + start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON + [ "$?" = 2 ] && return 2 + # Many daemons don't delete their pidfiles when they exit. + rm -f $PIDFILE + return "$RETVAL" +} + +# +# Function that sends a SIGHUP to the daemon/service +# +do_reload() { + # + # If the daemon can reload its configuration without + # restarting (for example, when it is sent a SIGHUP), + # then implement that here. + # + start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME + return 0 +} + +case "$1" in + start) + [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME" + do_start + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + stop) + [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME" + do_stop + case "$?" in + 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;; + 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;; + esac + ;; + status) + status_of_proc "$DAEMON" "$NAME" && exit 0 || exit $? + ;; + #reload|force-reload) + # + # If do_reload() is not implemented then leave this commented out + # and leave 'force-reload' as an alias for 'restart'. + # + #log_daemon_msg "Reloading $DESC" "$NAME" + #do_reload + #log_end_msg $? + #;; + restart|force-reload) + # + # If the "reload" option is implemented then remove the + # 'force-reload' alias + # + log_daemon_msg "Restarting $DESC" "$NAME" + do_stop + case "$?" in + 0|1) + do_start + case "$?" in + 0) log_end_msg 0 ;; + 1) log_end_msg 1 ;; # Old process is still running + *) log_end_msg 1 ;; # Failed to start + esac + ;; + *) + # Failed to stop + log_end_msg 1 + ;; + esac + ;; + *) + #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2 + echo "Usage: $SCRIPTNAME {start|stop|status|restart|force-reload}" >&2 + exit 3 + ;; +esac + +: + From c8c56078b1f3f6a997f72c8090392b941e429575 Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Thu, 21 Aug 2014 16:45:24 +0200 Subject: [PATCH 3/4] Renamed files (init requires file names < 15 characters) and added initial version of readme for e2e setup --- .../{NodeJsController.sh => MySensors.sh} | 0 ...erInitScript.sh => MySensorsInitScript.sh} | 2 +- NodeJsController/Readme.html | 298 ++++++++++++++++++ NodeJsController/package.json | 3 +- 4 files changed, 301 insertions(+), 2 deletions(-) rename NodeJsController/{NodeJsController.sh => MySensors.sh} (100%) rename NodeJsController/{NodeJsControllerInitScript.sh => MySensorsInitScript.sh} (99%) create mode 100644 NodeJsController/Readme.html diff --git a/NodeJsController/NodeJsController.sh b/NodeJsController/MySensors.sh similarity index 100% rename from NodeJsController/NodeJsController.sh rename to NodeJsController/MySensors.sh diff --git a/NodeJsController/NodeJsControllerInitScript.sh b/NodeJsController/MySensorsInitScript.sh similarity index 99% rename from NodeJsController/NodeJsControllerInitScript.sh rename to NodeJsController/MySensorsInitScript.sh index 2c934a5..38a9feb 100644 --- a/NodeJsController/NodeJsControllerInitScript.sh +++ b/NodeJsController/MySensorsInitScript.sh @@ -19,7 +19,7 @@ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="MySensors NodeJs Controller" -NAME="NodeJsController.sh" +NAME="MySensors.sh" PIDFILE="/usr/local/var/run/$NAME.pid" DAEMON="/home/pi/Arduino/NodeJsController/$NAME" DAEMON_ARGS="$PIDFILE" diff --git a/NodeJsController/Readme.html b/NodeJsController/Readme.html new file mode 100644 index 0000000..a2ca54e --- /dev/null +++ b/NodeJsController/Readme.html @@ -0,0 +1,298 @@ +

MySensors with NodeJS Controller and OTA bootloader on RPi

+

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. +

Hardware

+

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

+

Download and install latest Raspbian version on a fresh SD-Card

+

Tutorials for this task are available on the internet (download, copy to SD)

+

Setup base parameters

+

(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

        +
      +
    • 8. Advanced Options +
        +
      • A2. Hostname +

        mysensors

        +
      • A3. Memory Split +

        16

        +
      +
    +
  • Finish +
  • Reboot +
+

Install latest updates

+
    +
  • login as pi / test +
  • sudo apt-get update +
  • sudo apt-get upgrade +
  • sudo reboot +
+

Install Remote Desktop

+

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)

+
    +
  • login as pi / test +
  • sudo apt-get install xrdp +
  • 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) +
+

Install NodeJS (here: latest stable version available for RPi: 0.10.28)

+
    +
  • 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) +
+

Install MongoDB

+
    +
  • 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” +
+

Install Arduino (and update to latest 1.0.5)

+
    +
  • login as pi / test +
  • sudo apt-get install arduino +
  • wget http://arduino.googlecode.com/files/arduino-1.0.5-linux32.tgz +
  • tar zxvf arduino-1.0.5-linux32.tgz +
  • rm arduino-1.0.5-linux32.tgz +
  • cd arduino-1.0.5 +
  • rm -rf hardware/tools +
  • sudo cp -ru lib /usr/share/arduino +
  • sudo cp -ru libraries /usr/share/arduino +
  • sudo cp -ru tools /usr/share/arduino +
  • sudo cp -ru hardware /usr/share/arduino +
  • sudo cp -ru examples /usr/share/doc/arduino-core +
  • sudo cp -ru reference /usr/share/doc/arduino-core +
  • cd ~ +
  • rm -rf arduino-1.0.5 +
+

Enable programming via GPIO UART (for serial gateway only)

+
    +
  • login as pi / test +
  • wget https://github.com/SpellFoundry/avrdude-rpi/archive/master.zip +
  • unzip master.zip +
  • rm master.zip +
  • cd avrdude-rpi-master +
  • sudo cp autoreset /usr/bin +
  • sudo cp avrdude-autoreset /usr/bin +
  • sudo mv /usr/bin/avrdude /usr/bin/avrdude-original +
  • sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude +
  • cd .. +
  • rm -rf avrdude-rpi-master +
+

Install MySensors from Git branch development (here: password: test)

+
    +
  • login as pi / test +
  • git clone https://github.com/mysensors/Arduino.git +
  • cd Arduino +
  • git checkout development +
  • cd NodeJsController +
  • npm install +
  • nano NodeJsController.js (optional : removing sample firmwares) +

    const fwHexFiles = [ ];

    +
  • 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 +
+

Start NodeJsController on boot

+
    +
  • 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 +
+

Configure Arduino

+
    +
  • start graphical UI (startx on RPi or via RDP) +
  • start Arduino IDE +
  • File - Preferences +
      +
    • set sketchbook location to /home/pi/Arduino +
    • enable verbose output for compilation +
    • enable verbose output for upload +
    +
  • Close Arduino IDE +
+ +

Serial Gateway

+

Hardware

+
    +
  • as described for the standard Serial Gateway +
  • 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 +
+

Disable default use of serial port

+
    +
  • 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 +
+

Flash (assuming that the ATmega has a valid Arduino bootloader installed)

+
    +
  • login as pi / test +
  • start Arduino IDE +
      +
    • Tools - Board - Arduino - Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 +
    • Tools - Serial Port - /dev/ttyUSB9 +
    • File - Sketchbook - SerialGateway +
    • File - Upload +
    +
+

Setup NodeJsController

+
    +
  • 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 +
+ +

Ethernet Gateway

+

Hardware

+
    +
  • as described for the standard Ethernet Gateway +
  • 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 +
+

Adjust Sourcecode (here: address 10.0.1.99 / port: 9999)

+
    +
  • [I you are running into compilation errors due to missing files in the utility directory, do the following] +cp -R ~/Arduino/libraries/UIPEthernet/src/utility ~/Arduino/libraries/UIPEthernet/utility +
  • nano ~/Arduino/libraries/MySensors/MyConfig.h +

    //#define DEBUG

    +
  • start Arduino IDE +
      +
    • File - Sketchbook - EthernetGateway +
    • Edit source code +

      #define IP_PORT 9999
      +IPAddress myIp (10, 0, 1, 99);

      +
    • Optional : adjust source code to given hardware +
        +
      • Correct include for Ethernet module type (if not using ENC28J60) +
      • Switch MyGateway constructor if using inclusion mode button and LEDs +
      +
    • File - Save +
    +

    Flash (assuming that the ATmega has a valid Arduino bootloader installed)

    +
      +
    • Connect ethernet gateway to RPi (setup as above for serial gateway or via USB FTDI cable +
    • login as pi / test +
    • start Arduino IDE +
        +
      • Tools - Board - Arduino - Arduino Pro or Pro Mini (5V, 16 MHz) w/ ATmega328 +
      • Tools - Serial Port - /dev/ttyUSB9 (or /dev/ttyUSB0 if connecting through USB cable) +
      • File - Sketchbook - EthernetGateway +
      • File - Upload +
      +
    +

    Setup NodeJsController

    +
      +
    • nano ~/Arduino/NodeJsController/NodeJsController.js +

      const gwAddress = '10.0.1.99';

      +
    • sudo service mysensors restart +
    + +

    Sensor Node Bootloader

    +

    Hardware

    +
      +
    • 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) +
    +

    Compile Bootloader (can be skipped but good to see if everything is working)

    +
      +
    • cd ~/Arduino/Bootloader +
    • make +
    • this should compile the bootloader and produce three files in the same directory: MyOtaBootloader.o / MyOtaBootloader.elf / MyOtaBootloader.hex +
    +

    Flash Bootloader

    +
      +
    • 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 +
    + +

    End-to-End Test

    +

    Add Firmware to Controller

    +
      +
    • nano ~/Arduino/NodeJsController/NodeJsController.js +

      const fwHexFiles = [ 'DallasTemperatureSensor.cpp.hex' ];
      +const fwDefaultType = 0;

      +
    • sudo service mysensors restart +
    +

    Flash Firmware OTA

    +
      +
    • tail -f ~/logs/NodeJsController.log +
    • Power up sensor node with OTA bootloader +
    +

    Check functionality

    +
      +
    • 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 +
    diff --git a/NodeJsController/package.json b/NodeJsController/package.json index f9ec6ff..a4866a6 100644 --- a/NodeJsController/package.json +++ b/NodeJsController/package.json @@ -3,7 +3,8 @@ "version": "0.0.1", "description": "MySensors Controller based on Node JS", "dependencies": { + "mongodb": "~1.4.7", "net": "~1.0.2", - "mongodb": "~1.4.7" + "serialport": "^1.4.5" } } From 961828a6e5dfc6fa985af4b624922f4a0cb4170e Mon Sep 17 00:00:00 2001 From: ToSa27 Date: Sat, 23 Aug 2014 18:42:24 +0200 Subject: [PATCH 4/4] installation instructions --- NodeJsController/Readme.html | 49 ++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/NodeJsController/Readme.html b/NodeJsController/Readme.html index a2ca54e..6766851 100644 --- a/NodeJsController/Readme.html +++ b/NodeJsController/Readme.html @@ -10,12 +10,12 @@
    • login as pi / raspberry
    • sudo nano /etc/network/interfaces -

      #iface eth0 inet dhcp
      -iface eth0 inet static
      +

      #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

      +nameserver 10.0.1.1

    • sudo raspi-config
      • 1. Expand Filesystem @@ -44,6 +44,7 @@ nameserver 10.0.1.1

      • sudo apt-get upgrade
      • sudo reboot
      +

      Install NodeJS (here: latest stable version available for RPi: 0.10.28)

      • login as pi / test @@ -61,8 +63,8 @@ nameserver 10.0.1.1

      • 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"
        +

        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) @@ -96,6 +98,7 @@ export PATH

      • 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”
      +

      Install MySensors from Git branch development (here: password: test)

      • login as pi / test @@ -137,7 +141,7 @@ export PATH

      • cd NodeJsController
      • npm install
      • nano NodeJsController.js (optional : removing sample firmwares) -

        const fwHexFiles = [ ];

        +

        const fwHexFiles = [ ];

      • 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

      Start NodeJsController on boot

      @@ -151,6 +155,7 @@ export PATH

    • sudo reboot
    • to confirm that NodeJsController is starting at boot, check the log file /home/pi/logs/NodeJsController.log
    +

    Serial Gateway

    Hardware

      -
    • as described for the standard Serial Gateway +
    • 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)
      @@ -176,17 +182,18 @@ 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
    -

    Disable default use of serial port

    +

    Disable default use of RPi serial port

    • sudo nano /etc/inittab -

      #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

      +

      #T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

    • sudo nano /boot/cmdline.txt - remove part of the file: -

      console=ttyAMA0,115200

      +

      console=ttyAMA0,115200

    • cd /dev
    • sudo ln -s ttyAMA0 ttyUSB9
    • sudo apt-get install minicom
    • sudo reboot
    +

    Setup NodeJsController

    • 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;

      +

      //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

    Ethernet Gateway

    Hardware

      -
    • as described for the standard Ethernet Gateway +
    • 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
    +

    Setup NodeJsController

    • nano ~/Arduino/NodeJsController/NodeJsController.js -

      const gwAddress = '10.0.1.99';

      +

      const gwAddress = '10.0.1.99';

    • sudo service mysensors restart