Skip to content

Commit

Permalink
Merge pull request #2 from osaether/fix-wpanctl
Browse files Browse the repository at this point in the history
Only call wpanctl when command line arg asks for it
  • Loading branch information
osaether authored Oct 22, 2020
2 parents 3ec0fe2 + 4593ec8 commit 40141de
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 20 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,17 @@ docker run --name otbr-mqtt-sn -p 8080:80 --dns=127.0.0.1 -it --privileged otbr-
The most common network parameters can be set on the docker command line. The default values are taken from the [Nordic Semiconductor border router](https://www.nordicsemi.com/Software-and-tools/Software/nRF5-SDK-for-Thread-and-Zigbee/Download#infotabs) such that it works with the examples in the [nRF5 SDK for Thread and Zigbee](https://www.nordicsemi.com/Software-and-tools/Software/nRF5-SDK-for-Thread-and-Zigbee).
The command line options with default values are shown in the following table.

| Parameter | Command line option | Default value | Note |
|----------------------|:--------------------------------|:---------------------------------|:--------|
| Network Name | --network-name | OTBR-MQTT-SN | |
| NCP Serial Port | --ncp-path | /dev/ttyACM0 | |
| PAN ID | --panid | 0xABCD | 1 |
| Extended PAN ID | --xpanid | DEAD00BEEF00CAFE | 1 |
| NCP Channel | --ncp-channel | 11 | 1 |
| Network Key | --network-key | 00112233445566778899AABBCCDDEEFF | 1 |
| Network PSKc | --pskc | E00F739803E92CB42DAA7CCE1D2A394D | 1 |
| TUN Interface Name | --interface | wpan0 | |
| NAT64 Prefix | --nat64-prefix | 64:ff9b::/96 | |
| Default prefix route | --disable-default-prefix-route | Enabled | |
| Default prefix slaac | --disable-default-prefix-slaac | Enabled | |
| MQTT Broker | --broker | mqtt.eclipse.org | |

1: These are changed only when the Network Name is changed. To force a change you must change the Network Name.
| Parameter | Command line option | Default value |
|----------------------|:--------------------------------|:---------------------------------|
| Network Name | --network-name | OTBR-MQTT-SN |
| NCP Serial Port | --ncp-path | /dev/ttyACM0 |
| PAN ID | --panid | 0xABCD |
| Extended PAN ID | --xpanid | DEAD00BEEF00CAFE |
| NCP Channel | --ncp-channel | 11 |
| Network Key | --network-key | 00112233445566778899AABBCCDDEEFF |
| Network PSKc | --pskc | E00F739803E92CB42DAA7CCE1D2A394D |
| TUN Interface Name | --interface | wpan0 |
| NAT64 Prefix | --nat64-prefix | 64:ff9b::/96 |
| Default prefix route | --disable-default-prefix-route | Enabled |
| Default prefix slaac | --disable-default-prefix-slaac | Enabled |
| MQTT Broker | --broker | mqtt.eclipse.org |
60 changes: 56 additions & 4 deletions docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ parse_args "$@"
[ -n "$AUTO_PREFIX_ROUTE" ] || AUTO_PREFIX_ROUTE=true
[ -n "$AUTO_PREFIX_SLAAC" ] || AUTO_PREFIX_SLAAC=true
[ -n "$NAT64_PREFIX" ] || NAT64_PREFIX="64:ff9b::/96"
[ -n "$NETWORK_NAME" ] || NETWORK_NAME="OTBR-MQTT_SN"
[ -n "$NETWORK_NAME" ] || NETWORK_NAME="OTBR-MQTT-SN"
# Use same default network configuration as the Nordic Semiconductor Raspberry PI
# borderrouter (see /etc/border_router.conf on the RPI)
[ -n "$NETWORK_KEY" ] || NETWORK_KEY="00112233445566778899AABBCCDDEEFF"
Expand Down Expand Up @@ -153,23 +153,75 @@ nohup 2>&1 /app/borderrouter/MQTT-SNGateway &
# Atach to the Thread network.
###############################################################################

CNK=0
if !(wpanctl getprop Network:Key | grep -q "Network:Key = \[\"$NETWORK_KEY\"\]"); then
CNK=1
fi

CNN=0
if !(wpanctl getprop Network:Name | grep -q "Network:Name = \"$NETWORK_NAME\""); then
CNN=1
fi

CNP=0
if !(wpanctl getprop Network:PANID | grep -q "Network:PANID = \"$NETWORK_PANID\""); then
CNP=1
fi

CNX=0
if !(wpanctl getprop Network:XPANID | grep -q "Network:XPANID = \"$NETWORK_XPANID\""); then
CNX=1
fi

CNC=0
if !(wpanctl getprop NCP:Channel | grep -q "NCP:Channel = \"$NCP_CHANNEL\""); then
CNC=1
fi

CNS=0
if !(wpanctl getprop Network:PSKc | grep -q "Network:PSKc = \[\"$NETWORK_PSKC\"\]"); then
CNS=1
fi

if (( $CNK==1 )) || (( $CNN==1 )) || (( $CNP==1 )) || (( $CNX==1 )) || (( $CNC==1 )) || (( $CNS==1 )); then
wpanctl leave
sleep 1

wpanctl reset
sleep 2
fi

if (( $CNK==1 )); then
wpanctl setprop Network:Key --data $NETWORK_KEY
fi

if (( $CNN==1 )); then
wpanctl setprop Network:Name $NETWORK_NAME
fi

if (( $CNP==1 )); then
wpanctl setprop Network:PANID $NETWORK_PANID
fi

if (( $CNX==1 )); then
wpanctl setprop Network:XPANID $NETWORK_XPANID
fi

if (( $CNC==1 )); then
wpanctl setprop NCP:Channel $NCP_CHANNEL
wpanctl setprop Network:Name $NETWORK_NAME
fi

if (( $CNS==1 )); then
wpanctl setprop Network:PSKc $NETWORK_PSKC
fi

if (( $CNK==1 )) || (( $CNN==1 )) || (( $CNP==1 )) || (( $CNX==1 )) || (( $CNC==1 )) || (( $CNS==1 )); then
wpanctl attach
sleep 3
wpanctl status
fi
fi

wpanctl status


while [ $? = 0 ]
do
Expand Down

0 comments on commit 40141de

Please sign in to comment.