„README.md“ ändern
This commit is contained in:
parent
15f8b7f1bd
commit
a3110dc2f2
185
README.md
185
README.md
@ -61,47 +61,47 @@ apt-get install mariadb-server
|
||||
CREATE TABLE IF NOT EXISTS Smartlock
|
||||
(
|
||||
`accountId` VARCHAR(9) NOT NULL,
|
||||
`adminPinState` TINYINT NOT NULL,
|
||||
`advertisingMode` TINYINT NOT NULL,
|
||||
`adminPinState` SMALLINT NOT NULL,
|
||||
`advertisingMode` SMALLINT NOT NULL,
|
||||
`authId` VARCHAR(24),
|
||||
`autoLockTimeout` SMALLINT NOT NULL,
|
||||
`autoUnlatch` BOOLEAN NOT NULL,
|
||||
`automaticBatteryTypeDetection` BOOLEAN NOT NULL,
|
||||
`batteryCritical` BOOLEAN NOT NULL,
|
||||
`batteryType` TINYINT NOT NULL,
|
||||
`batteryType` SMALLINT NOT NULL,
|
||||
`buttonEnabled` BOOLEAN NOT NULL,
|
||||
`creationDate` DATETIME NOT NULL,
|
||||
`daylightSavingMode` TINYINT NOT NULL,
|
||||
`daylightSavingMode` SMALLINT NOT NULL,
|
||||
`detachedCylinder` BOOLEAN NOT NULL,
|
||||
`doubleButtonPressAction` TINYINT NOT NULL,
|
||||
`doubleButtonPressAction` SMALLINT NOT NULL,
|
||||
`favorite` BOOLEAN NOT NULL,
|
||||
`firmwareVersion` VARCHAR(255),
|
||||
`fobAction1` TINYINT NOT NULL,
|
||||
`fobAction2` TINYINT NOT NULL,
|
||||
`fobAction3` TINYINT NOT NULL,
|
||||
`fobAction1` SMALLINT NOT NULL,
|
||||
`fobAction2` SMALLINT NOT NULL,
|
||||
`fobAction3` SMALLINT NOT NULL,
|
||||
`fobPaired` BOOLEAN NOT NULL,
|
||||
`keypadPaired` BOOLEAN NOT NULL,
|
||||
`lastAction` TINYINT NOT NULL,
|
||||
`lastAction` SMALLINT NOT NULL,
|
||||
`latitude` FLOAT NOT NULL,
|
||||
`ledBrightness` TINYINT NOT NULL,
|
||||
`ledBrightness` SMALLINT NOT NULL,
|
||||
`ledEnabled` BOOLEAN NOT NULL,
|
||||
`lngTimeout` SMALLINT NOT NULL,
|
||||
`lockedPositionOffsetDegrees` SMALLINT NOT NULL,
|
||||
`longitude` FLOAT NOT NULL,
|
||||
`mainName` VARCHAR(255),
|
||||
`mode` TINYINT NOT NULL,
|
||||
`mode` SMALLINT NOT NULL,
|
||||
`name` VARCHAR(255),
|
||||
`pairingEnabled` BOOLEAN NOT NULL,
|
||||
`serverState` TINYINT NOT NULL,
|
||||
`singleButtonPressAction` TINYINT NOT NULL,
|
||||
`serverState` SMALLINT NOT NULL,
|
||||
`singleButtonPressAction` SMALLINT NOT NULL,
|
||||
`singleLock` BOOLEAN NOT NULL,
|
||||
`singleLockedPositionOffsetDegrees` SMALLINT NOT NULL,
|
||||
`smartlockId` VARCHAR(9) NOT NULL PRIMARY KEY, /*primary key = unique!*/
|
||||
`state` TINYINT NOT NULL,
|
||||
`state` SMALLINT NOT NULL,
|
||||
`timezoneOffset` SMALLINT NOT NULL,
|
||||
`totalDegrees` SMALLINT NOT NULL,
|
||||
`trigger` TINYINT NOT NULL,
|
||||
`type` TINYINT NOT NULL,
|
||||
`trigger` SMALLINT NOT NULL,
|
||||
`type` SMALLINT NOT NULL,
|
||||
`unlatchDuration` SMALLINT NOT NULL,
|
||||
`unlockedPositionOffsetDegrees` SMALLINT NOT NULL,
|
||||
`unlockedToLockedTransitionOffsetDegrees` SMALLINT NOT NULL,
|
||||
@ -111,15 +111,15 @@ CREATE TABLE IF NOT EXISTS Smartlock
|
||||
|
||||
CREATE TABLE IF NOT EXISTS SmartlockLog
|
||||
(
|
||||
`action` TINYINT NOT NULL,
|
||||
`action` SMALLINT NOT NULL,
|
||||
`authId` VARCHAR(24),
|
||||
`autoUnlock` BOOLEAN NOT NULL,
|
||||
`date` DATETIME NOT NULL,
|
||||
`id` VARCHAR(24) NOT NULL PRIMARY KEY, /*primary key = unique!*/
|
||||
`name` VARCHAR(255),
|
||||
`smartlockId` VARCHAR(9) NOT NULL,
|
||||
`state` TINYINT NOT NULL,
|
||||
`trigger` TINYINT NOT NULL
|
||||
`state` SMALLINT NOT NULL,
|
||||
`trigger` SMALLINT NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS SmartlockAuth
|
||||
`name` VARCHAR(255),
|
||||
`remoteAllowed` BOOLEAN NOT NULL,
|
||||
`smartlockId` VARCHAR(9) NOT NULL,
|
||||
`type` TINYINT NOT NULL,
|
||||
`type` SMALLINT NOT NULL,
|
||||
`updateDate` DATETIME NOT NULL
|
||||
);
|
||||
|
||||
@ -142,7 +142,7 @@ CREATE TABLE IF NOT EXISTS SmartlockAuth
|
||||
/*look script: you need to insert the nukiId in jq*/
|
||||
CREATE TABLE IF NOT EXISTS BridgeCallbackList
|
||||
(
|
||||
`id` TINYINT NOT NULL,
|
||||
`id` SMALLINT NOT NULL,
|
||||
`nukiId` VARCHAR(9) NOT NULL,
|
||||
`url` TEXT NOT NULL
|
||||
);
|
||||
@ -151,15 +151,15 @@ CREATE TABLE IF NOT EXISTS BridgeCallbackList
|
||||
CREATE TABLE IF NOT EXISTS BridgeInfo
|
||||
(
|
||||
`appVersion` VARCHAR(24),
|
||||
`bridgeType` TINYINT NOT NULL,
|
||||
`bridgeType` SMALLINT NOT NULL,
|
||||
`currentTime` DATETIME NOT NULL,
|
||||
`firmwareVersion` VARCHAR(24),
|
||||
`hardwareId` VARCHAR(24),
|
||||
`name` VARCHAR(255) NOT NULL,
|
||||
`nukiId` VARCHAR(9) NOT NULL PRIMARY KEY, /*primary key = unique!*/
|
||||
`paired` TINYINT NOT NULL,
|
||||
`rssi` TINYINT NOT NULL,
|
||||
`serverConnected` TINYINT NOT NULL,
|
||||
`paired` SMALLINT NOT NULL,
|
||||
`rssi` SMALLINT NOT NULL,
|
||||
`serverConnected` SMALLINT NOT NULL,
|
||||
`serverId` VARCHAR(24) NOT NULL,
|
||||
`uptime` BIGINT NOT NULL,
|
||||
`wifiFirmwareVersion` VARCHAR(24)
|
||||
@ -169,9 +169,9 @@ CREATE TABLE IF NOT EXISTS BridgeInfo
|
||||
CREATE TABLE IF NOT EXISTS BridgeList
|
||||
(
|
||||
`batteryCritical` BOOLEAN NOT NULL,
|
||||
`name` TINYINT NOT NULL,
|
||||
`name` SMALLINT NOT NULL,
|
||||
`nukiId` VARCHAR(9) NOT NULL PRIMARY KEY, /*primary key = unique!*/
|
||||
`state` TINYINT NOT NULL,
|
||||
`state` SMALLINT NOT NULL,
|
||||
`stateName` VARCHAR(24) NOT NULL,
|
||||
`timestamp` DATETIME NOT NULL
|
||||
);
|
||||
@ -182,7 +182,7 @@ CREATE TABLE IF NOT EXISTS BridgeLockState
|
||||
(
|
||||
`batteryCritical` BOOLEAN NOT NULL,
|
||||
`nukiId` VARCHAR(9) NOT NULL PRIMARY KEY, /*primary key = unique!*/
|
||||
`state` TINYINT NOT NULL,
|
||||
`state` SMALLINT NOT NULL,
|
||||
`stateName` VARCHAR(24) NOT NULL,
|
||||
`success` BOOLEAN NOT NULL
|
||||
);
|
||||
@ -193,7 +193,7 @@ CREATE TABLE IF NOT EXISTS BridgeLog
|
||||
(
|
||||
`bridgeId` VARCHAR(9) NOT NULL,
|
||||
`cmdId` VARCHAR(9),
|
||||
`connection` TINYINT,
|
||||
`connection` SMALLINT,
|
||||
`macAddr` VARCHAR(12),
|
||||
`nukiId` VARCHAR(9),
|
||||
`timestamp` DATETIME NOT NULL,
|
||||
@ -236,14 +236,14 @@ while [ true ]; do
|
||||
|
||||
eval "curl -X GET $CURL_HEADER $BASE_URL/smartlock/log -o "$FILE_BASE"_SmartlockLog.json"
|
||||
jq -r "$JQ_CSV" "$FILE_BASE"_SmartlockLog.json > "$FILE_BASE"_SmartlockLog.csv
|
||||
sed -i 's/,true,/,1,/g' "$FILE_BASE"_SmartlockLog.csv
|
||||
sed -i 's/,false,/,0,/g' "$FILE_BASE"_SmartlockLog.csv
|
||||
sed -i 's/true/1/g' "$FILE_BASE"_SmartlockLog.csv
|
||||
sed -i 's/false/0/g' "$FILE_BASE"_SmartlockLog.csv
|
||||
mysql -u$DB_USER -p$DB_PASS $DB_NAME -e"TRUNCATE TABLE SmartlockLog; LOAD DATA LOCAL INFILE '"$FILE_BASE"_SmartlockLog.csv' INTO TABLE SmartlockLog FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
|
||||
|
||||
eval "curl -X GET $CURL_HEADER $BASE_URL/smartlock/auth -o "$FILE_BASE"_SmartlockAuth.json"
|
||||
jq -r "$JQ_CSV" "$FILE_BASE"_SmartlockAuth.json > "$FILE_BASE"_SmartlockAuth.csv
|
||||
sed -i 's/,true,/,1,/g' "$FILE_BASE"_SmartlockAuth.csv
|
||||
sed -i 's/,false,/,0,/g' "$FILE_BASE"_SmartlockAuth.csv
|
||||
sed -i 's/true/1/g' "$FILE_BASE"_SmartlockAuth.csv
|
||||
sed -i 's/false/0/g' "$FILE_BASE"_SmartlockAuth.csv
|
||||
mysql -u$DB_USER -p$DB_PASS $DB_NAME -e"TRUNCATE TABLE SmartlockAuth; LOAD DATA LOCAL INFILE '"$FILE_BASE"_SmartlockAuth.csv' INTO TABLE SmartlockAuth FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
|
||||
|
||||
eval "curl -X GET $CURL_HEADER $BASE_URL/smartlock -o "$FILE_BASE"_Smartlock.json"
|
||||
@ -303,26 +303,38 @@ done
|
||||
|
||||
```
|
||||
chmod 770 nuki_bridge_job-collector.sh
|
||||
vim /etc/rc.local
|
||||
|
||||
vim /opt/nuki/bridge/nuki-bridge-collector.service
|
||||
|
||||
```
|
||||
|
||||
> /etc/rc.local
|
||||
> /opt/nuki/bridge/nuki-bridge-collector.service
|
||||
```
|
||||
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
|
||||
|
||||
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
|
||||
|
||||
nohup /opt/nuki/bridge/nuki_bridge_job-collector.sh > /opt/nuki/bridge/nuki_bridge_job-collector.log 2>&1 &
|
||||
|
||||
exit 0
|
||||
|
||||
[Unit]
|
||||
After=network.target
|
||||
Description=Nuki Bridge Collector Service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/opt/nuki/bridge/nuki_bridge_job-collector.sh
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
RestartSec=10s
|
||||
RemainAfterExit=yes
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
```
|
||||
|
||||
Init the modified rc.local and check status
|
||||
```
|
||||
sudu su
|
||||
. /etc/rc.local
|
||||
ps -afe | grep [n]uki
|
||||
ln -sf /opt/nuki/bridge/nuki-bridge-collector.service /etc/systemd/system/nuki-bridge-collector.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable nuki-bridge-collector.service
|
||||
|
||||
service nuki-bridge-collector restart && service nuki-bridge-collector status
|
||||
```
|
||||
|
||||
#### 5.2.2 SSH sync user
|
||||
@ -387,15 +399,15 @@ while [ true ]; do
|
||||
|
||||
|
||||
jq -r "[{bridgeType}+(.|{ids}|{hardwareId}+.[])+(.|{versions}|{appVersion}+{firmwareVersion}+{wifiFirmwareVersion}+.[])+{uptime}+{currentTime}+{serverConnected}+(.|{scanResults}|.[][])]|$JQ_CSV" "$FILE_BASE"_info.json > "$FILE_BASE"_info.csv
|
||||
sed -i 's/,true,/,1,/g' "$FILE_BASE"_info.csv
|
||||
sed -i 's/,false,/,0,/g' "$FILE_BASE"_info.csv
|
||||
sed -i 's/true/1/g' "$FILE_BASE"_info.csv
|
||||
sed -i 's/false/0/g' "$FILE_BASE"_info.csv
|
||||
mysql -u$DB_USER -p$DB_PASS $DB_NAME -e"TRUNCATE Table BridgeInfo; LOAD DATA LOCAL INFILE '"$FILE_BASE"_info.csv' INTO TABLE BridgeInfo FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
|
||||
|
||||
|
||||
|
||||
jq -r "[.[]|{nukiId}+{name}+({lastKnownState}|.[])]|$JQ_CSV" "$FILE_BASE"_list.json > "$FILE_BASE"_list.csv
|
||||
sed -i 's/,true,/,1,/g' "$FILE_BASE"_list.csv
|
||||
sed -i 's/,false,/,0,/g' "$FILE_BASE"_list.csv
|
||||
sed -i 's/true/1/g' "$FILE_BASE"_list.csv
|
||||
sed -i 's/false/0/g' "$FILE_BASE"_list.csv
|
||||
mysql -u$DB_USER -p$DB_PASS $DB_NAME -e"TRUNCATE TABLE BridgeList; LOAD DATA LOCAL INFILE '"$FILE_BASE"_list.csv' INTO TABLE BridgeList FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 1 LINES;"
|
||||
|
||||
|
||||
@ -425,30 +437,73 @@ chmod 770 nuki_bridge_job-parser.sh
|
||||
#test the script
|
||||
./nuki_bridge_job-parser.sh
|
||||
```
|
||||
### 5.3 Putting the scripts to autostart (rc.local)
|
||||
### 5.3 Install scripts as service
|
||||
```
|
||||
vim /etc/rc.local
|
||||
vim /opt/nuki/web/nuki-web.service
|
||||
```
|
||||
|
||||
> /etc/rc.local
|
||||
> /opt/nuki/web/nuki-web.service
|
||||
```
|
||||
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
|
||||
|
||||
if [ -f /aafirstboot ]; then /aafirstboot start ; fi
|
||||
|
||||
nohup /opt/nuki/web/nuki_web_job.sh > /opt/nuki/web/nuki_web_job.log 2>&1 &
|
||||
nohup /opt/nuki/bridge/nuki_bridge_job-parser.sh > /opt/nuki/bridge/nuki_bridge_job-parser.log 2>&1 &
|
||||
|
||||
exit 0
|
||||
[Unit]
|
||||
After=network.target
|
||||
Description=Nuki Web Service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/opt/nuki/web/nuki_web_job.sh
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
RestartSec=10s
|
||||
RemainAfterExit=yes
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
```
|
||||
|
||||
### 5.4 Test it!
|
||||
```
|
||||
#reload
|
||||
. /etc/rc.local & bash -c "ps -afe | grep [n]uki"
|
||||
ln -sf /opt/nuki/web/nuki-web.service /etc/systemd/system/nuki-web.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable nuki-web.service
|
||||
|
||||
service nuki-web restart && service nuki-web status
|
||||
```
|
||||
|
||||
### 5.5 Customization parameters
|
||||
```
|
||||
vim /opt/nuki/bridge/nuki-bridge-parser.service
|
||||
```
|
||||
|
||||
> /opt/nuki/bridge/nuki-bridge-parser.service
|
||||
```
|
||||
|
||||
[Unit]
|
||||
After=network.target
|
||||
Description=Nuki Bridge Parser Service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/opt/nuki/bridge/nuki_bridge_job-parser.sh
|
||||
KillMode=process
|
||||
Restart=on-failure
|
||||
RestartSec=10s
|
||||
RemainAfterExit=yes
|
||||
User=root
|
||||
Group=root
|
||||
|
||||
[Install]
|
||||
WantedBy= multi-user.target
|
||||
```
|
||||
|
||||
```
|
||||
ln -sf /opt/nuki/bridge/nuki-bridge-parser.service /etc/systemd/system/nuki-bridge-parser.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable nuki-bridge-parser.service
|
||||
|
||||
service nuki-bridge-parser restart && service nuki-bridge-parser status
|
||||
```
|
||||
|
||||
### 5.4 Customization parameters
|
||||
|
||||
* by adjusting the bash scripts you can modify the update frequency for CURLing and parsing json files (currently 30s is standard value)
|
||||
* Bridge Id has to be added so the conjunction between Smartlock and Bridge can be established. This could be automated but at the moment it has to be done manually (replace in JQ parsing lines)
|
||||
|
Loading…
Reference in New Issue
Block a user