Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Baba committed Feb 19, 2018
2 parents 8840f4d + f8f13dd commit f14aa9f
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 106 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# 履歴
* 2.0.0
- 接続方法を変更し接続までの時間を改善
- USBシリアル接続時とUARTシリアル接続時とをLED点滅パターンで識別できるように変更
- シリアル接続方法を従来の「自動」のほか、UARTシリアル接続のみ、UARTシリアル接続のみを指定できるオプション`SERIAL_PORT_TYPE`を追加
* 1.8.3
- アンインストール時にエラーが出る問題を修正
- ASUS Tinker Board Sにおいて、機種判定がうまくいかない場合がある問題を修正
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ $ make PI_USER=linaro PI_HOST=tinkerboard.local
### 動作確認 (RPi/ATB)

```bash
$ VERSION=1.8.3 && rm -fr tmp && mkdir tmp && cd tmp && \
$ VERSION=2.0.0 && rm -fr tmp && mkdir tmp && cd tmp && \
tar zxf ~/candy-pi-lite-service-${VERSION}.tgz
$ time sudo SRC_DIR=$(pwd) DEBUG=1 ./install.sh
$ time sudo SRC_DIR=$(pwd) DEBUG=1 CANDY_RED=0 BOOT_APN=soracom.io ./install.sh
$ time sudo SRC_DIR=$(pwd) DEBUG=1 CANDY_RED=0 BOOT_APN=soracom.io ENABLE_WATCHDOG=0 ./install.sh
$ time sudo SRC_DIR=$(pwd) DEBUG=1 CANDY_RED=0 BOOT_APN=soracom.io PPP_PING_INTERVAL_SEC=5 ./install.sh
$ time sudo SRC_DIR=$(pwd) DEBUG=1 CANDY_RED=0 BOOT_APN=soracom.io SERIAL_PORT_TYPE=usb ./install.sh

$ time sudo /opt/candy-line/candy-pi-lite/uninstall.sh
```
Expand Down
3 changes: 3 additions & 0 deletions etc/udev/rules.d/99-qws-usb-serial.rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="05c6", ATTRS{idProd

SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0121", ENV{.LOCAL_ifNum}=="02", SYMLINK+="QWS.EC21.AT", MODE="0660"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0121", ENV{.LOCAL_ifNum}=="03", SYMLINK+="QWS.EC21.MODEM", MODE="0660"

SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.LOCAL_ifNum}=="02", SYMLINK+="QWS.EC25.AT", MODE="0660"
SUBSYSTEMS=="usb", KERNEL=="ttyUSB[0-9]*", ATTRS{idVendor}=="2c7c", ATTRS{idProduct}=="0125", ENV{.LOCAL_ifNum}=="03", SYMLINK+="QWS.EC25.MODEM", MODE="0660"
18 changes: 14 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ VENDOR_HOME=/opt/candy-line

SERVICE_NAME=candy-pi-lite
GITHUB_ID=CANDY-LINE/candy-pi-lite-service
VERSION=1.8.3
VERSION=2.0.0
# Channel B
UART_PORT="/dev/ttySC1"
MODEM_BAUDRATE=${MODEM_BAUDRATE:-460800}

# v6 Maintenance LTS : April 2018 - April 2019
# v8 Active LTS Start on 2017-10-31, Maintenance LTS : April 2019 - December 2019
ARMv6_NODEJS_VERSION="6.12.0"
ARMv6_NODEJS_VERSION="6.12.3"
ARMv7_NODEJS_VERSION="6.x"
NODEJS_VERSIONS="v6"

SERVICE_HOME=${VENDOR_HOME}/${SERVICE_NAME}
Expand All @@ -51,6 +52,7 @@ COFIGURE_ENOCEAN_PORT=${COFIGURE_ENOCEAN_PORT:-1}
CANDY_PI_LITE_APT_GET_UPDATED=${CANDY_PI_LITE_APT_GET_UPDATED:-0}
CANDY_RED_BIND_IPV4_ADDR=${CANDY_RED_BIND_IPV4_ADDR:-false}
DISABLE_DEFAULT_ROUTE_ADJUSTER=${DISABLE_DEFAULT_ROUTE_ADJUSTER:-0}
SERIAL_PORT_TYPE=${SERIAL_PORT_TYPE:-auto}

REBOOT=0

Expand Down Expand Up @@ -359,15 +361,22 @@ function install_candy_red {
exit 1
fi
apt-get remove -y nodered nodejs nodejs-legacy npm
rm -f \
/usr/bin/node \
/usr/bin/npm \
/usr/sbin/node \
/usr/sbin/npm \
/usr/local/bin/node \
/usr/local/bin/npm
echo ${MODEL_NAME} | grep -o "ARMv6"
if [ "$?" == "0" ]; then
cd /tmp
wget https://nodejs.org/dist/v${ARMv6_NODEJS_VERSION}/node-v${ARMv6_NODEJS_VERSION}-linux-armv6l.tar.gz
tar zxf node-v${ARMv6_NODEJS_VERSION}-linux-armv6l.tar.gz
cd node-v${ARMv6_NODEJS_VERSION}-linux-armv6l/
cp -R * /usr/local/
cp -R * /usr/
else
curl -sL https://deb.nodesource.com/setup_6.x | sudo bash -
curl -sL https://deb.nodesource.com/setup_${ARMv7_NODEJS_VERSION} | sudo bash -
apt-get install -y nodejs
fi
fi
Expand Down Expand Up @@ -424,6 +433,7 @@ function install_service {
cp -f ${SRC_DIR}/systemd/fallback_apn ${SERVICE_HOME}

for e in VERSION \
SERIAL_PORT_TYPE \
DISABLE_DEFAULT_ROUTE_ADJUSTER \
PPP_PING_INTERVAL_SEC \
NTP_DISABLED \
Expand Down
139 changes: 124 additions & 15 deletions systemd/_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ MODEM_BAUDRATE=${MODEM_BAUDRATE:-%MODEM_BAUDRATE%}
UART_PORT="/dev/ttySC1"
QWS_UC20="/dev/QWS.UC20"
QWS_EC21="/dev/QWS.EC21"
QWS_EC25="/dev/QWS.EC25"
QWS_UC20_PORT="${QWS_UC20}.MODEM"
QWS_EC21_PORT="${QWS_EC21}.MODEM"
QWS_EC25_PORT="${QWS_EC25}.MODEM"
IF_NAME="${IF_NAME:-ppp0}"
DELAY_SEC=${DELAY_SEC:-1}
SHOW_CANDY_CMD_ERROR=0
Expand All @@ -39,6 +41,9 @@ function log {
}

function detect_usb_device {
if [ -n "${USB_SERIAL_PORT}" ]; then
return
fi
USB_SERIAL=`lsusb | grep "2c7c:0121"`
if [ "$?" == "0" ]; then
USB_SERIAL_PORT=${QWS_EC21_PORT}
Expand All @@ -48,6 +53,12 @@ function detect_usb_device {
if [ "$?" == "0" ]; then
USB_SERIAL_PORT=${QWS_UC20_PORT}
USB_SERIAL_AT_PORT="${QWS_UC20}.AT"
else
USB_SERIAL=`lsusb | grep "2c7c:0125"`
if [ "$?" == "0" ]; then
USB_SERIAL_PORT=${QWS_EC25_PORT}
USB_SERIAL_AT_PORT="${QWS_EC25}.AT"
fi
fi
fi
USB_SERIAL=""
Expand All @@ -56,6 +67,43 @@ function detect_usb_device {
fi
}

function look_for_usb_device {
if [ "${SERIAL_PORT_TYPE}" == "uart" ]; then
return
fi
MAX=40
COUNTER=0
while [ ${COUNTER} -lt ${MAX} ];
do
detect_usb_device
if [ "${SERIAL_PORT_TYPE}" == "auto" ] || [ -n "${USB_SERIAL_PORT}" ]; then
break
fi
sleep 1
let COUNTER=COUNTER+1
done
if [ "${SERIAL_PORT_TYPE}" == "usb" ] && [ -z "${USB_SERIAL_PORT}" ]; then
log "[ERROR] USB Serial Ports are missing."
exit 2
fi
}

function retry_usb_auto_detection {
USB_SERIAL_DETECTED=""
if [ "${SERIAL_PORT_TYPE}" != "auto" ]; then
return
fi
if [ -z "${USB_SERIAL_PORT}" ]; then
detect_usb_device
if [ -n "${USB_SERIAL_PORT}" ]; then
USB_SERIAL_DETECTED=1
MODEM_INIT=0
MODEM_SERIAL_PORT=""
AT_SERIAL_PORT=""
fi
fi
}

function look_for_modem_at_port {
MODEM_SERIAL_PORT=`/usr/bin/env python -c "import candy_board_qws; print(candy_board_qws.SerialPort.resolve_modem_port())"`
AT_SERIAL_PORT="${USB_SERIAL_AT_PORT:-${MODEM_SERIAL_PORT}}"
Expand All @@ -68,7 +116,7 @@ function look_for_modem_at_port {
AT_SERIAL_PORT=""
return
fi
log "Modem Serial port: ${MODEM_SERIAL_PORT} and AT Serial port: ${AT_SERIAL_PORT} are selected"
log "[INFO] Modem Serial port: ${MODEM_SERIAL_PORT} and AT Serial port: ${AT_SERIAL_PORT} are selected"
}

function init_serialport {
Expand Down Expand Up @@ -97,6 +145,7 @@ function init_serialport {
break
fi
sleep 1
let COUNTER=COUNTER+1
done
if [ "${RET}" != "0" ]; then
log "[ERROR] Modem returned error"
Expand All @@ -122,6 +171,7 @@ function init_serialport {
break
fi
sleep 1
let COUNTER=COUNTER+1
done
if [ "${RET}" != "0" ]; then
log "[ERROR] Modem returned error"
Expand All @@ -141,7 +191,7 @@ function candy_command {
RESULT=`/usr/bin/env python /opt/candy-line/${PRODUCT_DIR_NAME}/server_main.py $1 $2 ${MODEM_SERIAL_PORT} ${CURRENT_BAUDRATE} /var/run/candy-board-service.sock`
RET=$?
if [ "${SHOW_CANDY_CMD_ERROR}" == "1" ] && [ "${RET}" != "0" ]; then
log "candy_command[category:$1][action:$2] => [${RESULT}]"
log "[INFO] candy_command[category:$1][action:$2] => [${RESULT}]"
fi
}

Expand Down Expand Up @@ -219,13 +269,80 @@ function wait_for_serial_available {
fi
}

function wait_for_network_registration {
# init_modem must be performed prior to this function
REG_KEY="ps"
if [ "$1" == "True" ]; then
REG_KEY="cs"
fi
MAX=180
COUNTER=0
while [ ${COUNTER} -lt ${MAX} ];
do
candy_command network show
RET="$?"
if [ "${RET}" == "0" ]; then
STAT=`
/usr/bin/env python -c \
"import json;r=json.loads('${RESULT}');
print('N/A' if r['status'] != 'OK' else r['result']['registration']['${REG_KEY}'])" 2>&1`
if [ "$?" != "0" ]; then
RET=1
elif [ "${STAT}" == "Registered" ]; then
log "[INFO] OK. Registered in the home ${REG_KEY} network"
break
elif [ "${STAT}" == "Roaming" ]; then
log "[INFO] OK. Registered in the ROAMING ${REG_KEY} network"
break
else
log "[INFO] Waiting for network registration => Status:${STAT}"
RET=1
fi
fi
sleep 1
let COUNTER=COUNTER+1
done
if [ "${RET}" != "0" ]; then
log "[ERROR] Network Registration Failed"
exit 1
fi
}

function test_functionality {
# init_modem must be performed prior to this function
candy_command modem show
if [ "$?" != 0 ]; then
log "[INFO] Restarting ${PRODUCT} Service as the module isn't connected properly"
exit 1
fi
FUNC=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['functionality'])" 2>&1`
log "[INFO] Phone Functionality => ${FUNC}"
if [ "${FUNC}" == "Anomaly" ]; then
log "[ERROR] The module doesn't work properly. Functionality Recovery in progress..."
candy_command modem reset
log "[INFO] Restarting ${PRODUCT} Service as the module has been reset"
exit 1
fi
}

function save_apn {
# init_modem must be performed prior to this function
candy_command apn "{\"action\":\"set\",\"name\":\"$1\",\"user_id\":\"$2\",\"password\":\"$3\",\"type\":\"$4\"}"
log "[INFO] Saved APN => $1"
if [ "$5" == "True" ]; then
log "[INFO] Network Re-registering"
candy_command network deregister
candy_command network register
fi
}

function adjust_time {
# init_modem must be performed prior to this function
candy_command modem show
MODEL=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['model'])"`
DATETIME=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['datetime'])"`
TIMEZONE=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['timezone'])"`
EPOCHTIME=`/usr/bin/env python -c "import time,datetime;print(int(datetime.datetime.strptime('${DATETIME}', '%y/%m/%d,%H:%M:%S').strftime('%s'))-time.timezone+${DELAY_SEC})"`
MODEL=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['model'])" 2>&1`
DATETIME=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['datetime'])" 2>&1`
TIMEZONE=`/usr/bin/env python -c "import json;r=json.loads('${RESULT}');print(r['result']['timezone'])" 2>&1`
EPOCHTIME=`/usr/bin/env python -c "import time,datetime;print(int(datetime.datetime.strptime('${DATETIME}', '%y/%m/%d,%H:%M:%S').strftime('%s'))-time.timezone+${DELAY_SEC})" 2>&1`
date -s "@${EPOCHTIME}"
log "[INFO] Module Model: ${MODEL}"
log "[INFO] Network Timezone: ${TIMEZONE}"
Expand All @@ -234,21 +351,13 @@ function adjust_time {

function init_modem {
MODEM_INIT=0
detect_usb_device
wait_for_ppp_offline
perst
look_for_usb_device
wait_for_serial_available
if [ "${MODEM_INIT}" == "0" ]; then
exit 1
fi
adjust_time
if [ -z "${USB_SERIAL_PORT}" ]; then
detect_usb_device # retry
if [ -n "${USB_SERIAL_PORT}" ]; then
log "[INFO] Restarting ${PRODUCT} Service as new USB serial ports are detected"
exit 1
fi
fi
}

function stop_ntp {
Expand Down
4 changes: 2 additions & 2 deletions systemd/apn-list.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"soracom.io":{"user":"sora","password":"sora"}
,"lte-d.ocn.ne.jp":{"user":"mobileid@ocn","password":"mobile"}
,"3g-d-2.ocn.ne.jp":{"user":"mobileid@ocn","password":"mobile"}
,"lte-d.ocn.ne.jp":{"user":"mobileid@ocn","password":"mobile","nw":"lte"}
,"3g-d-2.ocn.ne.jp":{"user":"mobileid@ocn","password":"mobile","nw":"3g"}
,"iijmio.jp":{"user":"mio@iij","password":"iij"}
}
9 changes: 4 additions & 5 deletions systemd/environment.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
# Software Version
VERSION=%VERSION%

# 'auto' for automatic serial port selection, 'usb' for USB serial use only, 'uart' for ignoring USB serial
SERIAL_PORT_TYPE=%SERIAL_PORT_TYPE%

# 1 for enabling LED blinking, 0 for disabling it
BLINKY=1
# Blinking interval in seconds, > 0 and <= 60
BLINKY_INTERVAL_SEC=0.4

# LTE/3G access point name defined in `apn-list.json`
# As of v1.7.0, APN in the `apn` file overrides this value.
#APN=
BLINKY_INTERVAL_SEC=0.8

# Network retaining request interval in PPP Modem-mode (<5: disabled)
PPP_PING_INTERVAL_SEC=%PPP_PING_INTERVAL_SEC%
Expand Down
2 changes: 1 addition & 1 deletion systemd/modem_reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PRODUCT_DIR_NAME="candy-pi-lite"

function init {
. /opt/candy-line/${PRODUCT_DIR_NAME}/_common.sh > /dev/null 2>&1
if [ -e "${UART_PORT}" ] || [ -e "${QWS_UC20_PORT}" ] || [ -e "${QWS_EC21_PORT}" ]; then
if [ -e "${UART_PORT}" ] || [ -e "${QWS_UC20_PORT}" ] || [ -e "${QWS_EC21_PORT}" ] || [ -e "${QWS_EC25_PORT}" ]; then
. /opt/candy-line/${PRODUCT_DIR_NAME}/_pin_settings.sh > /dev/null 2>&1
else
log "[ERROR] Modem is missing"
Expand Down
Loading

0 comments on commit f14aa9f

Please sign in to comment.