diff --git a/build.sh b/build.sh index 06d9abc..f35fbb6 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,6 @@ #!/bin/bash -e +IMG_NAME='Raspbian' run_sub_stage() { log "Begin ${SUB_STAGE_DIR}" diff --git a/stage2/EXPORT_IMAGE b/stage2/EXPORT_IMAGE deleted file mode 100644 index 8ef6ebe..0000000 --- a/stage2/EXPORT_IMAGE +++ /dev/null @@ -1 +0,0 @@ -IMG_SUFFIX="-lite" diff --git a/stage2/EXPORT_NOOBS b/stage2/EXPORT_NOOBS deleted file mode 100644 index b741334..0000000 --- a/stage2/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspbian Lite" -NOOBS_DESCRIPTION="A port of Debian Stretch for the Raspberry Pi (minimal version)" diff --git a/stage3/02-wpantund/00-packages b/stage3/02-wpantund/00-packages new file mode 100644 index 0000000..dcf4cbb --- /dev/null +++ b/stage3/02-wpantund/00-packages @@ -0,0 +1,4 @@ +dbus libreadline5 +#gcc g++ libdbus-1-dev libboost-dev libreadline-dev +#libtool autoconf autoconf-archive +#make diff --git a/stage3/02-wpantund/00-run.sh b/stage3/02-wpantund/00-run.sh new file mode 100755 index 0000000..8980428 --- /dev/null +++ b/stage3/02-wpantund/00-run.sh @@ -0,0 +1,21 @@ +#!/bin/bash -e + +#install -m 755 files/wpantund ${ROOTFS_DIR}/usr/sbin/ +#install -m 755 files/wpanctl ${ROOTFS_DIR}/usr/bin/ +#install -d files/etc ${ROOTFS_DIR}/ +#install -d files/usr ${ROOTFS_DIR}/ + +install -d ${ROOTFS_DIR}/usr/local/bin/ ${ROOTFS_DIR}/usr/local/sbin/ ${ROOTFS_DIR}/usr/local/libexec/wpantund/ +install -m 755 files/usr/local/bin/wpanctl ${ROOTFS_DIR}/usr/local/bin/ +install -m 755 files/usr/local/sbin/wpantund ${ROOTFS_DIR}/usr/local/sbin/ +install -m 755 files/usr/local/libexec/wpantund/ncp-spinel.la ${ROOTFS_DIR}/usr/local/libexec/wpantund/ +install -m 755 files/usr/local/libexec/wpantund/ncp-dummy.so ${ROOTFS_DIR}/usr/local/libexec/wpantund/ +install -m 755 files/usr/local/libexec/wpantund/ncp-dummy.la ${ROOTFS_DIR}/usr/local/libexec/wpantund/ +install -m 755 files/usr/local/libexec/wpantund/ncp-spinel.so ${ROOTFS_DIR}/usr/local/libexec/wpantund/ +install -m 644 files/etc/dbus-1/system.d/wpantund.conf ${ROOTFS_DIR}/etc/dbus-1/system.d/ +install -m 644 files/etc/wpantund.conf ${ROOTFS_DIR}/etc/ +install -m 644 files/etc/systemd/system/wpantund.service ${ROOTFS_DIR}/etc/systemd/system/ + +on_chroot << EOF + systemctl disable wpantund +EOF diff --git a/stage3/02-wpantund/files/etc/dbus-1/system.d/wpantund.conf b/stage3/02-wpantund/files/etc/dbus-1/system.d/wpantund.conf new file mode 100644 index 0000000..bf26bf1 --- /dev/null +++ b/stage3/02-wpantund/files/etc/dbus-1/system.d/wpantund.conf @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/stage3/02-wpantund/files/etc/systemd/system/wpantund.service b/stage3/02-wpantund/files/etc/systemd/system/wpantund.service new file mode 100644 index 0000000..68c35c2 --- /dev/null +++ b/stage3/02-wpantund/files/etc/systemd/system/wpantund.service @@ -0,0 +1,10 @@ +[Unit] +Description=Sub-GHz network daemon +After=network.target + +[Service] +ExecStart=/usr/local/sbin/wpantund -o NCPSocketName /dev/ttyACM0 -o WPANInterfaceName wpan0 +StandardOutput=null + +[Install] +Alias=wpantund diff --git a/stage3/02-wpantund/files/etc/wpantund.conf b/stage3/02-wpantund/files/etc/wpantund.conf new file mode 100644 index 0000000..1d98db8 --- /dev/null +++ b/stage3/02-wpantund/files/etc/wpantund.conf @@ -0,0 +1,154 @@ +# Example wpantund configuration file +# + +# The desired name of the network interface (not supported on all platforms) +# Default value is `wpan0`. +# +#Config:TUN:InterfaceName wpan0 + +# Path to serial port used to communicate with the NCP. +# Has special meaning when prefixed with `system:` or `serial:`. +# If the path is an IPv4 address/port, it will use a TCP socket. +# +#Config:NCP:SocketPath "/dev/tty.usbmodem1234" +#Config:NCP:SocketPath "127.0.0.1:4901" +#Config:NCP:SocketPath "system:/usr/local/sbin/spi-server -p - -s /dev/spidev2.0" +#Config:NCP:SocketPath "serial:/dev/ttyO1,raw,b115200,crtscts=1" + +# The desired NCP driver to use. +# Default value is `spinel`. +# +#Config:NCP:DriverName spinel + +# Describes what type of serial reliability layer should be used, if any. +# Generally this is set appropriately automatically, so you usually +# don't need to bother setting this. +# +# Optional. Default value is automatic. +# +#Config:NCP:ReliabilityLayer libsoot + +# The default transmit power of the NCP, measured in dBm +# (0 dBm is one milliwatt, can be negative) +# +# Optional. Default value is NCP-specific. +# +#NCP:TXPower 0 + +# The CCA threshold value, measured in dBm +# +# Optional. Default value is NCP-specific. +# +#NCP:CCAThreshold -70 + +# Path to reset pin. This socket is opened and values sent to it +# based on the desired reset state. wpantund sends `0\n` to +# assert the reset pin and sends `1\n` to deassert the reset pin. +# Can be used with the same `system:` and `serial:` prefixes defined +# above to handle special cases. On linux, you would generally +# set this to the `value` file of the RESET GPIO. +# +# Optional. If not set, only software resets will be possible. +# +#Config:NCP:HardResetPath "/sys/class/gpio/gpio49/value" + +# Path to power pin. The semantics are similar to those for +# `NCPHardResetPath` above, except that wpantund sends `0\n` to +# indicate that the NCP power should be disabled and `1\n` to +# indicate that the NCP power should be enabled. +# +# Optional. If not set, only software induced sleep will be used +# for low-power states. +# +#Config:NCP:PowerPath "/sys/class/gpio/gpio11/value" + +# Syslog mask adjustment. This property is a set of +# boolean masks for manipulating the bitmask used by `syslog()`. +# The string can contain the following words that represent +# the associated bit. The presence of the word in the string +# indicates that that bit should be set. Prefixing the word with +# a `-` (dash/minus) indicates that that bit should be cleared. +# The following keywords are supported: +# +# * `all` (All log levels) +# * `emerg` +# * `alert` +# * `crit` +# * `err` +# * `warn` +# * `notice` +# * `info` +# * `debug` +# +# So, for example, to get all log messages except debugging +# messages, you would use `all -debug`. +# +# Optional. The default value for non-debug builds is +# `all -info -debug`. +# +#Daemon:SyslogMask "all -info -debug" + +# Drop root privileges to the given user (and that user's group) +# after setting up all network interfaces and socket connections. +# Doing this helps mitigate the implications of security exploits, +# but may interfere with how hard resets are performed for certain +# NCPs. +# +# Optional. Default value is empty, which means that privileges +# are not dropped. +# +#Config:Daemon:PrivDropToUser "nobody" + +# Call `chroot()` to change the root directory to the directory +# indicated, after setting up all network interfaces and socket +# connections, but before privileges are dropped for `PrivDropToUser` +# (if set). Doing this helps mitigate the implications of security +# exploits, but may interfere with how hard resets are performed +# for certain NCPs. +# +# Optional. Default value is empty, which means that `chroot` is +# not called. +# +#Config:Daemon:Chroot "/var/empty" + +# Automatic firmware update enable/disable. This flag determines +# if the automatic firmware update mechanism (which uses the +# properties `FirmwareCheckCommand` and `FirmwareUpgradeCommand`, +# described below) is enabled or disabled. This flag is used +# when the driver determines that it doesn't know how to talk to +# the version of the firmware that is running on the NCP. +# +# If set to true, the NCP association state will then be set to +# `upgrading` and the firmware update process will begin. If set to +# false, the NCP association state will change to `fault`. +# +# This property may be changed at runtime to more strictly +# control when a firmware update is allowed to take place. +# +# Optional. The default value is false---which will prevent +# automatic wpantund-driven firmware updates. +# +#Daemon:AutoFirmwareUpdate true + +# Firmware update check command. This command is executed with +# the retrieved version string of the NCP appended as the last +# argument. If the command returns `0`, a firmware update is +# necessary. This configuration option is fairly useless without +# the `FirmwareUpgradeCommand` option also being set, defined below. +# +# Optional. If left blank, wpantund-driven firmware updates will +# be disabled. +# +#Config:NCP:FirmwareCheckCommand "test 'MyFunStack/1.0' !=" +#Config:NCP:FirmwareCheckCommand "/usr/local/sbin/zb-loader --is-update-required /usr/share/ncp-firmware/ip-modem-app.bin" + +# Firmware upgrade command. This is the command that is actually +# executed that performs the firmware update. Before calling this +# command, `wpantund` disconnects entirely from the NCP. While +# this command is executing, the association state reported +# for this interface will be `upgrading`. +# +# Optional. If left blank, wpantund-driven firmware updates will +# be disabled. +# +#Config:NCP:FirmwareUpgradeCommand "/usr/local/sbin/zb-loader /dev/ttyO1 --app-easyload /usr/share/ncp-firmware/ip-modem-app.bin" diff --git a/stage3/02-wpantund/files/usr/local/bin/wpanctl b/stage3/02-wpantund/files/usr/local/bin/wpanctl new file mode 100755 index 0000000..cc0e8b4 Binary files /dev/null and b/stage3/02-wpantund/files/usr/local/bin/wpanctl differ diff --git a/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.la b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.la new file mode 100755 index 0000000..cfaf55a --- /dev/null +++ b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.la @@ -0,0 +1,41 @@ +# ncp-dummy.la - a libtool library file +# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.11 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='ncp-dummy.so' + +# Names of this library. +library_names='ncp-dummy.so ncp-dummy.so ncp-dummy.so' + +# The name of the static archive. +old_library='' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs=' -lutil' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for ncp-dummy. +current=0 +age=0 +revision=0 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=yes + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/local/libexec/wpantund' diff --git a/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.so b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.so new file mode 100755 index 0000000..e721530 Binary files /dev/null and b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-dummy.so differ diff --git a/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.la b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.la new file mode 100755 index 0000000..b4083b2 --- /dev/null +++ b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.la @@ -0,0 +1,41 @@ +# ncp-spinel.la - a libtool library file +# Generated by libtool (GNU libtool) 2.4.2 Debian-2.4.2-1.11 +# +# Please DO NOT delete this file! +# It is necessary for linking the library. + +# The name that we can dlopen(3). +dlname='ncp-spinel.so' + +# Names of this library. +library_names='ncp-spinel.so ncp-spinel.so ncp-spinel.so' + +# The name of the static archive. +old_library='' + +# Linker flags that can not go in dependency_libs. +inherited_linker_flags='' + +# Libraries that this one depends upon. +dependency_libs=' -lutil' + +# Names of additional weak libraries provided by this library +weak_library_names='' + +# Version information for ncp-spinel. +current=0 +age=0 +revision=0 + +# Is this an already installed library? +installed=yes + +# Should we warn about portability when linking against -modules? +shouldnotlink=yes + +# Files to dlopen/dlpreopen +dlopen='' +dlpreopen='' + +# Directory that this library needs to be installed in: +libdir='/usr/local/libexec/wpantund' diff --git a/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.so b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.so new file mode 100755 index 0000000..1288a8d Binary files /dev/null and b/stage3/02-wpantund/files/usr/local/libexec/wpantund/ncp-spinel.so differ diff --git a/stage3/02-wpantund/files/usr/local/sbin/wpantund b/stage3/02-wpantund/files/usr/local/sbin/wpantund new file mode 100755 index 0000000..e751b1d Binary files /dev/null and b/stage3/02-wpantund/files/usr/local/sbin/wpantund differ diff --git a/stage3/03-nodejs/00-run.sh b/stage3/03-nodejs/00-run.sh new file mode 100755 index 0000000..c302374 --- /dev/null +++ b/stage3/03-nodejs/00-run.sh @@ -0,0 +1,143 @@ +#!/bin/bash -e + +BASE_DIR=$(pwd) + + +######################## +# Install dependencies # +######################## +#dpkg --add-architecture i386 + +apt-get update +apt-get install -y make python build-essential +apt-get install -y curl +apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf +#apt-get install -y gcc-multilib g++-multilib +#apt-get install -y libc6-dev-i386 + +#apt-get install -y libc6-dev + +apt-get --purge remove node +apt-get --purge remove nodejs +curl -sL https://deb.nodesource.com/setup_6.x | /bin/bash -e - +apt-get install -y nodejs +npm install -g npm@5.3.0 +#npm cache clean --force + +#ln -s /usr/include/asm-generic /usr/include/asm + + +################# +# Checkout node # +################# +NODE_BUILD_PATH=${BASE_DIR}/build/node +if [ ! -d "$NODE_BUILD_PATH" ]; then + git clone https://github.com/nodejs/node.git $NODE_BUILD_PATH +fi +cd $NODE_BUILD_PATH +git checkout v6.11.2 + + +####################### +# Cross-build Node.js # +####################### + +#export BASEDIR=$(pwd) +#export STAGING_DIR=${BASEDIR}/staging_dir +#export V8SOURCE=${BASEDIR}/v8m-rb +export PREFIX=arm-linux-gnueabihf- +export LIBPATH=${ROOTFS_DIR}/usr/lib/arm-linux-gnueabihf/ +export TARGET_PATH=${ROOTFS_DIR} + +# ARM cross-compile exports +export CC=${PREFIX}gcc +export CXX=${PREFIX}g++ +export AR=${PREFIX}ar +export RANLIB=${PREFIX}ranlib +export LINK=${PREFIX}g++ +export CPP="${PREFIX}gcc -E" +export STRIP=${PREFIX}strip +export OBJCOPY=${PREFIX}objcopy +export LD=${PREFIX}g++ +export OBJDUMP=${PREFIX}objdump +export NM=${PREFIX}nm +export AS=${PREFIX}as +export PS1="[${PREFIX}] \w$ " +#export LDFLAGS='-Wl,-L'${LIBPATH} +export LDFLAGS='-Wl,-rpath-link '${LIBPATH} + +export TARGET_ARCH="-march=armv7l" +#export TARGET_TUNE="-mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp -mthumb-interwork -mno-thumb" +export CXX_TARGET_ARCH="-march-armv7l" + +export V8_TARGET_ARCH="-march-armv7l" +export CXX_host="g++ -m32" +export CC_host="gcc -m32" +export LINK_host="g++ -m32" + + +make clean +make distclean + +#./configure --prefix=${TARGET_PATH} --dest-cpu=arm --dest-os=linux --without-snapshot --with-arm-float-abi=hard --with-arm-fpu=vfpv3 +./configure --prefix=${TARGET_PATH} --dest-cpu=arm --dest-os=linux --without-snapshot --with-arm-float-abi=hard --with-arm-fpu=vfpv3 --without-intl + +#./configure --without-snapshot --dest-cpu=arm --dest-os=linux --with-arm-float-abi=softfp --with-intl=full-icu --download=all + +make snapshot=off -j4 +make install + + +######################### +# Install node packages # +######################### +cd ${BASE_DIR} + +echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" +# WAR for node-gyp build +#mkdir -p ${ROOTFS_DIR}/lib/node_modules/node-red/node_modules/bcrypt +#chown -R $USER:$GROUP ${ROOTFS_DIR}/lib/node_modules/node-red/node_modules/bcrypt + +#mkdir -p ${ROOTFS_DIR}/lib/node_modules/node-red/node_modules/bcrypt/build +#chown -R $USER:$GROUP ${ROOTFS_DIR}/lib/node_modules/node-red/node_modules/bcrypt/build + +#ls -la ${ROOTFS_DIR}/lib/node_modules/node-red/node_modules/bcrypt/build +#ls -la ${ROOTFS_DIR} +echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" + +export npm_config_arch=arm +export npm_config_nodedir=${NODE_BUILD_PATH} + +npm_install () { + npm install -g --prefix=${TARGET_PATH} --target_arch=arm --target_platform=linux "$1" +} + +#npm --prefix=${TARGET_PATH} --target_arch=arm --target_platform=linux cache clean --force + +npm_install npm@5.3.0 +npm_install node-red +npm_install coap +npm_install node-red-dashboard + +# Running `npm_install repos/node-red-contrib-juliet` fails, this is a workaround +cd repos/node-red-contrib-juliet +npm install --target_arch=arm --target_platform=linux +npm_install + + +####################################### +# Install WPAN service Node-RED flows # +####################################### +cd ${BASE_DIR} + +NODE_DIR=${ROOTFS_DIR}/home/pi/.node-red +install -m 755 -d ${NODE_DIR} +install -m 755 -d ${NODE_DIR}/scripts/ +install -m 644 -D files/flows_*.json ${NODE_DIR}/ +install -m 755 -D files/*.sh ${NODE_DIR}/scripts/ +install -m 755 -D files/usbreset ${ROOTFS_DIR}/usr/sbin/ + +on_chroot << EOF + chown -R pi:pi /home/pi/.node-red +EOF + diff --git a/stage3/03-nodejs/01-run.sh b/stage3/03-nodejs/01-run.sh new file mode 100755 index 0000000..8d42842 --- /dev/null +++ b/stage3/03-nodejs/01-run.sh @@ -0,0 +1,14 @@ +#!/bin/bash -e + +export NODE_SERVICE_DIR=node-service + +git clone https://github.com/node-red/raspbian-deb-package.git ${NODE_SERVICE_DIR} + +install -m 644 ${NODE_SERVICE_DIR}/resources/nodered.service ${ROOTFS_DIR}/lib/systemd/system/ +install -m 755 ${NODE_SERVICE_DIR}/resources/node-red-start ${ROOTFS_DIR}/usr/bin +install -m 755 ${NODE_SERVICE_DIR}/resources/node-red-stop ${ROOTFS_DIR}/usr/bin +install -m 755 ${NODE_SERVICE_DIR}/resources/node-red-log ${ROOTFS_DIR}/usr/bin + +on_chroot << EOF +systemctl enable nodered +EOF diff --git a/stage3/03-nodejs/files/flows_raspberrypi.json b/stage3/03-nodejs/files/flows_raspberrypi.json new file mode 100644 index 0000000..eb4e901 --- /dev/null +++ b/stage3/03-nodejs/files/flows_raspberrypi.json @@ -0,0 +1 @@ +[{"id":"bd93e9de.473388","type":"tab","label":"Network"},{"id":"e53f9061.9c4d3","type":"ui_base","theme":{"name":"theme-light","lightTheme":{"default":"#0094CE","baseColor":"#0094CE","baseFont":"Helvetica Neue","edited":true,"reset":false},"darkTheme":{"default":"#097479","baseColor":"#097479","baseFont":"Helvetica Neue","edited":false},"customTheme":{"name":"Untitled Theme 1","default":"#4B7930","baseColor":"#4B7930","baseFont":"Helvetica Neue"},"themeState":{"base-color":{"default":"#0094CE","value":"#0094CE","edited":false},"page-titlebar-backgroundColor":{"value":"#0094CE","edited":false},"page-backgroundColor":{"value":"#fafafa","edited":false},"page-sidebar-backgroundColor":{"value":"#ffffff","edited":false},"group-textColor":{"value":"#1bbfff","edited":false},"group-borderColor":{"value":"#ffffff","edited":false},"group-backgroundColor":{"value":"#ffffff","edited":false},"widget-textColor":{"value":"#111111","edited":false},"widget-backgroundColor":{"value":"#0094ce","edited":false},"widget-borderColor":{"value":"#ffffff","edited":false}}},"site":{"name":"Node-RED Dashboard","hideToolbar":"false","allowSwipe":"false","dateFormat":"DD/MM/YYYY","sizes":{"sx":48,"sy":48,"gx":6,"gy":6,"cx":6,"cy":6,"px":0,"py":0}}},{"id":"b906bcb7.f06be","type":"ui_group","z":"","name":"Children","tab":"e3049028.c223c","order":2,"disp":true,"width":"12"},{"id":"b13d62f5.31f88","type":"ui_group","z":"","name":"Commission","tab":"e3049028.c223c","order":1,"disp":true,"width":"12"},{"id":"e3049028.c223c","type":"ui_tab","z":"","name":"Network","icon":"dashboard"},{"id":"e6f912cf.849d","type":"ui_group","z":"","name":"Children","tab":"884ab15e.0ae4b","order":2,"disp":true,"width":"12"},{"id":"e29ed2ef.a1302","type":"ui_group","z":"","name":"Commission","tab":"884ab15e.0ae4b","order":1,"disp":true,"width":"12"},{"id":"884ab15e.0ae4b","type":"ui_tab","z":"","name":"Network","icon":"dashboard"},{"id":"9d33a1f2.63778","type":"ui_template","z":"bd93e9de.473388","group":"e6f912cf.849d","name":"Children","order":0,"width":"12","height":"6","format":"
\n\n
 
","storeOutMessages":true,"fwdInMessages":true,"x":769.000057220459,"y":552.2222499847412,"wires":[[]]},{"id":"ff6af5b7.28e038","type":"exec","z":"bd93e9de.473388","command":"wpanctl commissioner -a ","addpay":true,"append":"","useSpawn":"","timer":"","name":"","x":401.66664123535156,"y":407.27778816223145,"wires":[[],["88328cda.658ba","4f2b0374.d0aacc"],[]]},{"id":"efd51aeb.51b088","type":"function","z":"bd93e9de.473388","name":"validate","func":"const regex = /^[0-9ABCDEFGHJKLMNPRSTUVWXY]{6,32}$/g;\n\nvar psk = msg.payload\n\nif (regex.exec(psk)) {\n msg.payload = psk\n return msg;\n}","outputs":1,"noerr":0,"x":207.66664123535156,"y":406.77778816223145,"wires":[["ff6af5b7.28e038"]]},{"id":"88328cda.658ba","type":"debug","z":"bd93e9de.473388","name":"","active":true,"console":"false","complete":"false","x":613.8888320922852,"y":444.0000066757202,"wires":[]},{"id":"4f2b0374.d0aacc","type":"function","z":"bd93e9de.473388","name":"Report status","func":"if (msg.payload.indexOf(\"Joiner added.\") != -1) {\n msg.payload = \"PSK set\";\n} else {\n msg.payload = \"Error setting PSK\";\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":623.6666412353516,"y":406.77778816223145,"wires":[["cc129c3.7ef226"]]},{"id":"bc0d93e0.1fc82","type":"ui_text_input","z":"bd93e9de.473388","name":"psk","label":"Device PSK","group":"e29ed2ef.a1302","order":2,"width":0,"height":0,"passthru":false,"mode":"text","delay":"0","topic":"","x":75.66664123535156,"y":405.77778816223145,"wires":[["efd51aeb.51b088"]]},{"id":"e736f6ee.354a38","type":"ui_text","z":"bd93e9de.473388","group":"e29ed2ef.a1302","order":1,"width":0,"height":0,"name":"info","label":"","format":"Enter PSK and press enter","layout":"row-left","x":75.66664123535156,"y":365.77778816223145,"wires":[]},{"id":"cc129c3.7ef226","type":"ui_toast","z":"bd93e9de.473388","position":"top right","displayTime":"3","outputs":0,"ok":"OK","cancel":"","topic":"","name":"","x":833.6666412353516,"y":405.77778816223145,"wires":[]},{"id":"e23a4677.b06998","type":"function","z":"bd93e9de.473388","name":"Format list","func":"var lines = msg.payload.split(/[\\r\\n]+/g);\n// msg.payload = \"
  • Foo
  • \";\n// msg.payload += \"
  • Bar
  • \";\n\nmsg.payload = \"\";\nfor (var i=1; i\";\n msg.payload += \"\";\n msg.payload += \"\";\n msg.payload += \"\";\n msg.payload += \"\";\n}\nmsg.payload += \"
    IDRSSIAge
    \" + data[0] + \"\" + data[4] + \"\" + data[7] + \"/\" + data[6] + \"
    \";\n\nreturn msg;","outputs":1,"noerr":0,"x":592.1111145019531,"y":553.000020980835,"wires":[["9d33a1f2.63778","c9a8c96b.7acd58"]]},{"id":"8be3f12b.1cfc4","type":"inject","z":"bd93e9de.473388","name":"","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"x":120.11111450195312,"y":565.000020980835,"wires":[["2a6433e.e72a9cc"]]},{"id":"2a6433e.e72a9cc","type":"exec","z":"bd93e9de.473388","command":"wpanctl getprop Thread:ChildTable","addpay":false,"append":"","useSpawn":"","timer":"","name":"","x":350.1111145019531,"y":565.500020980835,"wires":[["e23a4677.b06998"],[],[]]},{"id":"c9a8c96b.7acd58","type":"debug","z":"bd93e9de.473388","name":"","active":false,"console":"false","complete":"payload","x":776.7778167724609,"y":587.5555839538574,"wires":[]},{"id":"f9573c64.6aa9e","type":"exec","z":"bd93e9de.473388","command":"sudo /home/pi/.node-red/scripts/wpan_restart.sh","addpay":false,"append":"","useSpawn":"","timer":"","name":"Restart WPAN","x":661.8888893127441,"y":229.50000762939453,"wires":[["a428d14d.40eaa"],[],[]]},{"id":"bfc62ce3.01d9","type":"inject","z":"bd93e9de.473388","name":"","topic":"","payload":"","payloadType":"date","repeat":"15","crontab":"","once":false,"x":119.88888931274414,"y":227.00000762939453,"wires":[["573051e4.fe521"]]},{"id":"573051e4.fe521","type":"exec","z":"bd93e9de.473388","command":"wpanctl status","addpay":false,"append":"","useSpawn":"","timer":"","name":"","x":290.88888931274414,"y":228.00000762939453,"wires":[["d4b47b7a.844848"],[],[]]},{"id":"d4b47b7a.844848","type":"function","z":"bd93e9de.473388","name":"Detect problem","func":"if (msg.payload.indexOf('\"NCP:State\" => \"associated\"') == -1)\n return msg;","outputs":1,"noerr":0,"x":481.88888931274414,"y":229.00000762939453,"wires":[["f9573c64.6aa9e"]]},{"id":"a428d14d.40eaa","type":"debug","z":"bd93e9de.473388","name":"","active":true,"console":"false","complete":"false","x":836.1111373901367,"y":216.0000114440918,"wires":[]},{"id":"202f24de.7185ec","type":"comment","z":"bd93e9de.473388","name":"Network status daemon","info":"From time to time USB error occurs and wpan interface is desctructed.\nThis daemon checks the status of wpan0 interfacte and restart the USB and network if error condition is detected.\n","x":122.94444274902344,"y":180.33334255218506,"wires":[]},{"id":"b0c1c76b.ffbac8","type":"comment","z":"bd93e9de.473388","name":"Commissioning field","info":"","x":111.66667175292969,"y":325.5555648803711,"wires":[]},{"id":"7fbd13a9.85f0ac","type":"comment","z":"bd93e9de.473388","name":"Children list","info":"","x":96.11111026340063,"y":512.2222330305311,"wires":[]},{"id":"1bbaa16b.45aa4f","type":"inject","z":"bd93e9de.473388","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":117.77777862548828,"y":90,"wires":[["b7c98adf.b161c8"]]},{"id":"27122492.19828c","type":"comment","z":"bd93e9de.473388","name":"Initial configuration","info":"Check if OpenThread network configuration is present and if not - create new configuration.","x":116.66666666666667,"y":41.11111111111111,"wires":[]},{"id":"2e34e33e.44faac","type":"exec","z":"bd93e9de.473388","command":"sudo /home/pi/.node-red/scripts/wpan_new_configuration.sh","addpay":false,"append":"","useSpawn":"","timer":"","name":"Create new settings","x":680.0000076293945,"y":91.11110496520996,"wires":[[],[],[]]},{"id":"b7c98adf.b161c8","type":"file in","z":"bd93e9de.473388","name":"wpan_network_key","filename":"/home/pi/.node-red/scripts/wpan_network_key","format":"utf8","x":301.11107635498047,"y":91.11111831665039,"wires":[["3da60ba7.b24b44"]]},{"id":"3da60ba7.b24b44","type":"function","z":"bd93e9de.473388","name":"Validate key","func":"if (!msg.payload || msg.payload.length != 32) {\n msg.payload = 0;\n return msg;\n}","outputs":1,"noerr":0,"x":482.7777442932129,"y":92.22223377227783,"wires":[["2e34e33e.44faac"]]}] \ No newline at end of file diff --git a/stage3/03-nodejs/files/flows_raspberrypi_cred.json b/stage3/03-nodejs/files/flows_raspberrypi_cred.json new file mode 100644 index 0000000..e67977f --- /dev/null +++ b/stage3/03-nodejs/files/flows_raspberrypi_cred.json @@ -0,0 +1 @@ +{"$":"f240ab1c9f66a39a3e45e7de7649ac74L9Q="} \ No newline at end of file diff --git a/stage3/03-nodejs/files/usbreset b/stage3/03-nodejs/files/usbreset new file mode 100755 index 0000000..58b6826 Binary files /dev/null and b/stage3/03-nodejs/files/usbreset differ diff --git a/stage3/03-nodejs/files/wpan_configure.sh b/stage3/03-nodejs/files/wpan_configure.sh new file mode 100755 index 0000000..4fed8b2 --- /dev/null +++ b/stage3/03-nodejs/files/wpan_configure.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +XPANID=`cat /home/pi/.node-red/scripts/wpan_network_xpanid` +NETWORK_KEY=`cat /home/pi/.node-red/scripts/wpan_network_key` +NETWORK_NAME=`cat /home/pi/.node-red/scripts/wpan_network_name` + +wpanctl setprop Network:XPANID $XPANID +wpanctl setprop Network:Key $NETWORK_KEY +wpanctl form -c 11 $NETWORK_NAME diff --git a/stage3/03-nodejs/files/wpan_new_configuration.sh b/stage3/03-nodejs/files/wpan_new_configuration.sh new file mode 100755 index 0000000..bdd8676 --- /dev/null +++ b/stage3/03-nodejs/files/wpan_new_configuration.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +CONFIG_ROOT=/home/pi/.node-red/scripts + +# Insecure /dev/urandom can be used xpanid and name +XPANID=`head -c 64 /dev/urandom | sha256sum -b | head -c 16` +NETWORK_NAME=RPi-`head -c 64 /dev/urandom | sha256sum -b | head -c 4` + +echo -n $XPANID > $CONFIG_ROOT/wpan_network_xpanid +echo -n $NETWORK_NAME > $CONFIG_ROOT/wpan_network_name + +# Secure /dev/random MUST be used when generating network key +head -c 64 /dev/random | sha256sum -b | head -c 32 > $CONFIG_ROOT/wpan_network_key diff --git a/stage3/03-nodejs/files/wpan_reset_usb.sh b/stage3/03-nodejs/files/wpan_reset_usb.sh new file mode 100755 index 0000000..81121d2 --- /dev/null +++ b/stage3/03-nodejs/files/wpan_reset_usb.sh @@ -0,0 +1,8 @@ +#!/bin/bash +USBNAME=STMicroelectronics +LSUSB=$(lsusb | grep --ignore-case $USBNAME) +FOLD="/dev/bus/usb/"$(echo $LSUSB | cut --delimiter=' ' --fields='2')"/"$(echo $LSUSB | cut --delimiter=' ' --fields='4' | tr --delete ":") +echo $LSUSB +echo "-----------" +echo $FOLD +usbreset $FOLD diff --git a/stage3/03-nodejs/files/wpan_restart.sh b/stage3/03-nodejs/files/wpan_restart.sh new file mode 100755 index 0000000..5dd59a1 --- /dev/null +++ b/stage3/03-nodejs/files/wpan_restart.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +ROOT_DIR=`dirname $0` + +$ROOT_DIR/wpan_reset_usb.sh +sleep 1 + +systemctl restart wpantund.service +sleep 1 + +$ROOT_DIR/wpan_configure.sh +sleep 1 + +wpanctl commissioner -e diff --git a/stage3/03-nodejs/repos/node-red-contrib-juliet b/stage3/03-nodejs/repos/node-red-contrib-juliet new file mode 160000 index 0000000..1733029 --- /dev/null +++ b/stage3/03-nodejs/repos/node-red-contrib-juliet @@ -0,0 +1 @@ +Subproject commit 1733029da8a9ac402c6204fb4c74d99f2eb71fe4 diff --git a/stage3/04-hwrng/00-packages b/stage3/04-hwrng/00-packages new file mode 100644 index 0000000..eda5ef0 --- /dev/null +++ b/stage3/04-hwrng/00-packages @@ -0,0 +1 @@ +rng-tools diff --git a/stage3/04-hwrng/00-run-chroot.sh b/stage3/04-hwrng/00-run-chroot.sh new file mode 100755 index 0000000..14e56a2 --- /dev/null +++ b/stage3/04-hwrng/00-run-chroot.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +echo 'HRNGDEVICE=/dev/hwrng' | tee --append /etc/default/rng-tools + +systemctl enable rng-tools diff --git a/stage3/EXPORT_IMAGE b/stage3/EXPORT_IMAGE new file mode 100644 index 0000000..a494a3b --- /dev/null +++ b/stage3/EXPORT_IMAGE @@ -0,0 +1 @@ +IMG_SUFFIX='-nodejs' diff --git a/stage4/EXPORT_IMAGE b/stage4/EXPORT_IMAGE deleted file mode 100644 index ee20363..0000000 --- a/stage4/EXPORT_IMAGE +++ /dev/null @@ -1 +0,0 @@ -IMG_SUFFIX="-4GB" diff --git a/stage5/EXPORT_IMAGE b/stage5/EXPORT_IMAGE deleted file mode 100644 index 2b0f09d..0000000 --- a/stage5/EXPORT_IMAGE +++ /dev/null @@ -1 +0,0 @@ -IMG_SUFFIX="" diff --git a/stage5/EXPORT_NOOBS b/stage5/EXPORT_NOOBS deleted file mode 100644 index 4823501..0000000 --- a/stage5/EXPORT_NOOBS +++ /dev/null @@ -1,2 +0,0 @@ -NOOBS_NAME="Raspbian" -NOOBS_DESCRIPTION="A port of Debian Stretch for the Raspberry Pi (full desktop version)"