Skip to content

Commit

Permalink
feat: add files to gemtek package and remove meta data
Browse files Browse the repository at this point in the history
  • Loading branch information
jburhenn committed Apr 8, 2022
1 parent d4a9d4c commit d344d3a
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 35 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ tektelic: armv5
upx build/armv5/dps-client
cd packaging/tektelic; ./package.sh $(VERSION)

gemtek: LDFLAGS="-s -w -X main.version=$(VERSION) -X main.commandScriptPath=/mnt/data/app/azureiot/command-ctrl.sh -X main.metaDataScriptPath=/mnt/data/app/azureiot/meta-data.sh"
gemtek: mipsle
upx build/mipsle/dps-client
cd packaging/gemtek; ./package.sh $(VERSION)
Expand Down
23 changes: 0 additions & 23 deletions cmd/dps-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io/ioutil"
"os"
"time"

"github.com/mydevicesiot/dps-client/pkg/provision"

Expand All @@ -16,13 +15,6 @@ import (

var version string // set by the compiler
var commandScriptPath = "/opt/mydevices/command-ctrl.sh" // can be overridden by the compiler
var metaDataScriptPath = "" // can be overridden by the compiler

func addMetaDataCommand(command string) {
metaDataCommand := fmt.Sprintf("meta_data.dynamic.commands.%s", command)
commandLine := fmt.Sprintf("%s %s", metaDataScriptPath, command)
viper.SetDefault(metaDataCommand, commandLine)
}

func initConfig() provision.Options {
var opts provision.Options
Expand Down Expand Up @@ -77,21 +69,6 @@ func initConfig() provision.Options {
viper.SetDefault("commands.commands.update.command", updateCommand)
viper.SetDefault("commands.commands.update.max_execution_duration", "20m")

if metaDataScriptPath != "" {
viper.SetDefault("meta_data.dynamic.execution_interval", 10*time.Minute)
viper.SetDefault("meta_data.dynamic.max_execution_duration", time.Minute)
addMetaDataCommand("chirpstack_version")
addMetaDataCommand("dps_client_version")
addMetaDataCommand("eui")
addMetaDataCommand("firmware_version")
addMetaDataCommand("hardware_version")
addMetaDataCommand("ip")
addMetaDataCommand("mac")
addMetaDataCommand("manufacturer")
addMetaDataCommand("model")
addMetaDataCommand("serial")
}

if opts.Endpoint == "" {
opts.Endpoint = viper.GetString("integration.mqtt.auth.azure_iot_hub.provisioning.Endpoint")
}
Expand Down
66 changes: 66 additions & 0 deletions packaging/gemtek/files/azure-iot.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2020 Browan
# Provides: azure-iot.service
# Description: Run the dps-client and the chirpstack-gateway-bridge

START=99
#HDRSTR="0000"
GWID=`uci get -c /mnt/data/config mfg.system.lora_ee_cnt_0 | cut -c 1-16`
BRIDGE="chirpstack-gateway-bridge"
DPSC="dps-client"
AZIOT_DIR="/mnt/data/app/azureiot"
#EXE_DPS="/usr/bin/$DPSC"
EXE_DPS="/mnt/data/myd/myd/$DPSC"
#EXE_CGB="/usr/bin/$BRIDGE"
EXE_CGB="/mnt/data/myd/myd/$BRIDGE"
ENDPOINT="global.azure-devices-provisioning.net"
SCOPE="0ne0006B4D6"
#REGISTRATION_ID=$HDRSTR$GWID
REGISTRATION_ID=$GWID
DEVICE_CERTIFICATE="$AZIOT_DIR/certs/$HDRSTR$GWID.cert.pem"
PRIVATE_KEY="$AZIOT_DIR/private/$HDRSTR$GWID.key.pem"
CGB_CONFIG_FILE="$AZIOT_DIR/chirpstack-gateway-bridge.toml"
DPS_CFG_FILE="/mnt/data/myd/myd/default.toml"
DPS_LOG=/tmp/dps.log

start() {

local mode=`uci -c /mnt/data/config/ get mfg.system.mode`
if [ "$mode" != "mfg" ]; then

if pgrep $BRIDGE > /dev/null; then
echo "[azure-iot.service] $BRIDGE already running. [`pgrep -f $BRIDGE`]"
exit 1
fi

echo "[azure-iot.service] Starting DPS..."
rm -rf $OUTPUT_FILE $DPS_LOG
#$EXE_DPS -e $ENDPOINT -s $SCOPE -r $REGISTRATION_ID -c $DEVICE_CERTIFICATE -k $PRIVATE_KEY -o $CGB_CONFIG_FILE -t >> $DPS_LOG
$EXE_DPS -i $DPS_CFG_FILE -r $REGISTRATION_ID -c $DEVICE_CERTIFICATE -k $PRIVATE_KEY -o $CGB_CONFIG_FILE -t >> $DPS_LOG
echo "[azure-iot.service] DPS is done!"
echo "[azure-iot.service] Starting CGB..."
$EXE_CGB -c $CGB_CONFIG_FILE > /dev/null 2>&1 &
sleep 3

if pgrep $BRIDGE > /dev/null; then
echo "[azure-iot.service] CGB is running! [`pgrep -f $BRIDGE`]" >> /tmp/test1.log
else
echo "[azure-iot.service] CGB is failed! Please see $DPS_LOG to get more detail messages" >> /tmp/test2.log
fi

exit 0
fi
}

stop(){
if ! pgrep $BRIDGE > /dev/null; then
echo "[azure-iot.service] $BRIDGE is not running."
exit 1
fi
echo "Stopping $BRIDGE..."
echo "[azure-iot.service] Stopping $BRIDGE... [`pgrep -f $BRIDGE`]"
kill -9 `pgrep $BRIDGE`
echo "[azure-iot.service] $BRIDGE is stopped"
exit 0
}

28 changes: 28 additions & 0 deletions packaging/gemtek/files/default.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

[commands]

[commands.commands]

[commands.commands.reboot]
command = "/mnt/data/myd/myd/command-ctrl.sh reboot"
max_execution_duration = "1s"

[commands.commands.remote-ctrl]
command = "/mnt/data/myd/myd/command-ctrl.sh remote-ctrl"
max_execution_duration = "15s"

[commands.commands.update]
command = "/mnt/data/myd/myd/command-ctrl.sh update"
max_execution_duration = "20m"

[integration]
marshaler = "json"

[integration.mqtt]

[integration.mqtt.auth]
type = "azure_iot_hub"

[integration.mqtt.auth.azure_iot_hub.provisioning]
endpoint = "global.azure-devices-provisioning.net"
scope = "0ne0006B4D6"
20 changes: 9 additions & 11 deletions packaging/gemtek/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ PACKAGE_FILE="${BUILD_DIR}/mipsle/dps-client"
OUTPUT_DIR="${BUILD_DIR}/package/gemtek"
PACKAGE_DIR="${OUTPUT_DIR}/build"
USR_BIN_DIR="${PACKAGE_DIR}/usr/bin"
TMP_DIR="${PACKAGE_DIR}/tmp"
APP_LORA_PKG_DIR="${PACKAGE_DIR}/app/lora_pkg"
MNT_DATA_APP_AZUREIOT_DIR="${PACKAGE_DIR}/mnt/data/app/azureiot"
MYDEVICES_DATA_DIR="${PACKAGE_DIR}/mnt/data/myd/myd/"

# Cleanup
rm -rf $PACKAGE_DIR
Expand All @@ -32,7 +31,7 @@ Description: Azure device provisioning client
EOF

cat > $PACKAGE_DIR/CONTROL/postinst << EOF
cp /tmp/chirpstack-gateway-bridge /usr/bin/
cp /mnt/data/myd/myd/azure-iot.service /etc/init.d/
/etc/init.d/azure-iot.service stop >> /tmp/gateway-bridge-dps-update.log
/etc/init.d/azure-iot.service start >> /tmp/gateway-bridge-dps-update.log
EOF
Expand All @@ -48,17 +47,16 @@ EOF

# Files
mkdir -p $USR_BIN_DIR
mkdir -p $TMP_DIR
mkdir -p $APP_LORA_PKG_DIR
mkdir -p $MNT_DATA_APP_AZUREIOT_DIR
mkdir -p $MYDEVICES_DATA_DIR

cp files/chirpstack-gateway-bridge $TMP_DIR
cp files/chirpstack-gateway-bridge $MYDEVICES_DATA_DIR
cp files/lora_wdg_pkt_fwd.sh $APP_LORA_PKG_DIR
cp files/command-ctrl.sh $MNT_DATA_APP_AZUREIOT_DIR
chmod 755 $MNT_DATA_APP_AZUREIOT_DIR/command-ctrl.sh
cp files/meta-data.sh $MNT_DATA_APP_AZUREIOT_DIR
chmod 755 $MNT_DATA_APP_AZUREIOT_DIR/meta-data.sh
cp $PACKAGE_FILE $USR_BIN_DIR
cp files/command-ctrl.sh $MYDEVICES_DATA_DIR
chmod 755 $MYDEVICES_DATA_DIR/command-ctrl.sh
cp files/azure-iot.service $MYDEVICES_DATA_DIR
chmod 755 $MYDEVICES_DATA_DIR/azure-iot.service
cp $PACKAGE_FILE $MYDEVICES_DATA_DIR

# Package
opkg-build -o root -g root $PACKAGE_DIR $OUTPUT_DIR
Expand Down

0 comments on commit d344d3a

Please sign in to comment.