first commit
This commit is contained in:
53
support/README.md
Normal file
53
support/README.md
Normal file
@@ -0,0 +1,53 @@
|
||||
|
||||
# Domoticz support scripts
|
||||
|
||||
## Index available support tools
|
||||
|
||||
- [Get Domoticz version list](./README.md#get_build_versionssh)
|
||||
- [MQTT AutoDiscovery tools](./mqtt_ad/README.md)
|
||||
|
||||
## get_build_versions.sh
|
||||
|
||||
**This script ONLY works when you run it from a subdirectory within the GITHUB clone of DOMOTICZ/DOMOTICZ.**\
|
||||
Script will list 20 commitlog entries preceding provided version, to easily list changes made around that version.
|
||||
|
||||
### usage get_build_versions.sh
|
||||
|
||||
```text
|
||||
sh getcommitlog.sh [-v version] [-m max_logEntries]
|
||||
-v domoticz version. default last
|
||||
-m number of records to show. default 20
|
||||
```
|
||||
|
||||
### examples get_build_versions.sh
|
||||
|
||||
```bash
|
||||
#List last 20 versions & commit logrecords
|
||||
sh getcommitlog.sh
|
||||
|
||||
#List last 20 versions & commit logrecords for v41080
|
||||
sh getcommitlog.sh -v 41080
|
||||
*** Get 20 logrecords from commit:11974 version:14080 ***
|
||||
Build Commit Date Commit Description
|
||||
------ --------- ---------- ----------------------------------------------------------------------
|
||||
V14080 41e11f829 2022-01-17 Fix compile warning (and use internal reader)
|
||||
V14079 6350f3544 2022-01-17 MQTT-AD: Escaping special characters
|
||||
V14078 b120b0041 2022-01-17 Merge pull request #5113 from guillaumeclair/development
|
||||
V14077 67c349a22 2022-01-17 Fixed compile warnings under windows
|
||||
V14076 0f31858e1 2022-01-17 MQTT-AD: making sure correct discovery topic is matched (Fixes #5114)
|
||||
V14075 7259c5139 2022-01-17 Fix a bug in variables name in alertlevel function
|
||||
V14074 f64304efb 2022-01-16 Allow hardware to declare manual switches they are able to handle. (#4923)
|
||||
V14073 4fcda55f3 2022-01-16 Partly fix for Meter Counter report
|
||||
V14072 63e2f7b97 2022-01-16 MQTT/AD: Fixes for Fibaro FGRGBW dimmer (Issue #5069) (#5100)
|
||||
V14071 f47572654 2022-01-16 MQTT-AD: Making sure JSON object is not a object
|
||||
V14070 0bf7a176f 2022-01-15 MQTT-AD: putting unknown sensor types back into general type
|
||||
V14069 b2a1ebf50 2022-01-15 MQTT-AD: Added more exception information
|
||||
V14068 16801a0a4 2022-01-15 MQTT-AD: Added detection of CT nodes (needs more work from other pR)
|
||||
V14067 b36f2bc65 2022-01-15 Replace light/switch now only transfers new HardwareID/DeviceID/Unit to the old device
|
||||
V14066 13523bbe6 2022-01-15 Making sure a new sensor is created (could already exist a device with same type/id)
|
||||
V14065 b66a52e13 2022-01-15 Updated History
|
||||
V14064 650d91643 2022-01-15 Merge pull request #5111 from jgaalen/add-annathermostat-metrics
|
||||
V14063 a3b03f315 2022-01-14 Add AnnaThermostat metrics
|
||||
V14062 fce96f2a0 2022-01-14 Add AnnaThermostat metrics
|
||||
V14061 d43fd6b3b 2022-01-14 Add Daikin yearly energy usage for kwh meter
|
||||
```
|
||||
37
support/get_build_versions.sh
Normal file
37
support/get_build_versions.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#!/bin/bash
|
||||
: '
|
||||
# Scriptname getcommitlog.sh Ver: 20220123-02
|
||||
# Created by JvdZ
|
||||
# base info from https://www.domoticz.com/forum/viewtopic.php?f=47&t=30405#p230094
|
||||
|
||||
Script will list 20 commitlog entries preceding provided version, to easily list changes made around that version
|
||||
|
||||
usage:
|
||||
sh getcommitlog.sh [-v version] [-m max_logEntries]
|
||||
-v domoticz version. default last
|
||||
-m number of records to show. default 20
|
||||
'
|
||||
|
||||
MAXREC=20;
|
||||
IVER=""
|
||||
# process parameters
|
||||
while getopts m:v: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
m) MAXREC=${OPTARG};;
|
||||
v) IVER=${OPTARG};;
|
||||
esac
|
||||
done
|
||||
# Get latest commit count
|
||||
TCNT=`git rev-list HEAD --count`
|
||||
# Version is Commitcount + 2107 use last when not provided as input
|
||||
if [[ -z $IVER ]]; then
|
||||
let IVER=TCNT+2107;
|
||||
fi
|
||||
# Calculate start record
|
||||
let SREC=TCNT+2107-IVER
|
||||
let SCOM=TCNT-SREC
|
||||
echo " *** Get $MAXREC logrecords from commit:$SCOM version:$IVER ***"
|
||||
echo "Build Commit Date Commit Description"
|
||||
echo "------ --------- ---------- ----------------------------------------------------------------------"
|
||||
git log --date=human --pretty=format:"%h %as %s" --skip=$SREC --max-count=$MAXREC | awk '{print "V"'$IVER'-NR+1 " " $s}'
|
||||
79
support/mqtt_ad/README.md
Normal file
79
support/mqtt_ad/README.md
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
# MQTT AutoDiscovery tools
|
||||
|
||||
## How to supply an MQTT AD messages dump to the developers
|
||||
|
||||
When you are asked to supply a copy of all MQTT messages for a device used by MQTT Autodiscovery, you can follow the following steps:
|
||||
|
||||
1. go to subdirecory domoticz/scripts/support/mqtt_ad
|
||||
2. Run the script as shown in the examples below with the appropriate parameters. This will capture all MQTT packages in scope of the defined parametres.
|
||||
3. Provide us with the **mqtt_ad_record_*XXX*.log** file containing all records.
|
||||
4. Press Ctrl+c when you want to stop the capture process before the timer ends.
|
||||
|
||||
## mqtt_ad_record.sh
|
||||
|
||||
Script that helps capturing MQTT messages for Homeassistant AD into a file, so they can be shared easily with others for debugging.
|
||||
|
||||
### usage mqtt_ad_record.sh
|
||||
|
||||
```text
|
||||
bash mqtt_ad_record.sh [-h hostname/ip] [-p port] [-s searchstring] [-t capturetime]
|
||||
-h Hostname or Ipaddres of MQTT deamon. default is 127.0.0.1
|
||||
-p port for the MQTT deamon. default is 1883
|
||||
-u Userid for MQTT deamon
|
||||
-P Password for MQTT deamon
|
||||
-s only records MQTT messages that contain this string in the TOPIC or PAYLOAD. default is all messages
|
||||
-t caputure time in seconds. default is 600
|
||||
```
|
||||
|
||||
### examples mqtt_ad_record.sh
|
||||
|
||||
```bash
|
||||
# Records all MQTT Messages containing "/config", "_state" or "/state" for 10 minutes
|
||||
bash mqtt_ad_record.sh
|
||||
|
||||
# specify userid and password to access the MQTT deamon.
|
||||
bash mqtt_ad_record.sh -u UserId -P Password
|
||||
|
||||
#Records all MQTT Messages containing "/config", "_state" or "/state" for 30 Seconds
|
||||
bash mqtt_ad_record.sh -t 30
|
||||
|
||||
#Records all MQTT Messages containing "TASMOTA_A1" for 10 minutes
|
||||
bash mqtt_ad_record.sh -s TASMOTA_A1
|
||||
|
||||
#Records all MQTT Messages containing "TASMOTA_A1" for 30 seconds
|
||||
bash mqtt_ad_record.sh -s TASMOTA_A1 -t 30
|
||||
```
|
||||
|
||||
The above command will create an **mqtt_ad_record_*XXX*.log** file in the current directory.
|
||||
|
||||
- where ***XXX*** will be ***all*** for the first 2 examples and will be ***TASMOTA_A1*** for the last 2 examples.
|
||||
|
||||
## mqtt_ad_send.sh
|
||||
|
||||
Script that sends the captured mqtt records again to a server recorded in HA_Discovery_mqtt.log in dezelfde directory.
|
||||
|
||||
### usage mqtt_ad_send.sh
|
||||
|
||||
```text
|
||||
bash mqtt_ad_send.sh [-h hostname/ip] [-p port] [-s searchstring] [-i inputfile]
|
||||
-h Hostname or Ipaddres of MQTT deamon. default is 127.0.0.1
|
||||
-p port for the MQTT deamon. default is 1883
|
||||
-s only send MQTT messages that contain this string in the TOPIC or PAYLOAD. default is all messages
|
||||
-i inputfile. default is mqtt_ad_record_all.log
|
||||
-r override retain (y/n). defaults to the retain flag in the input records
|
||||
-d When Dry-run when switch is provided, no MQTT messages will be send, just the logging.
|
||||
```
|
||||
|
||||
### examples mqtt_ad_send.sh
|
||||
|
||||
```bash
|
||||
#ALL records
|
||||
bash mqtt_ad_send.sh
|
||||
|
||||
#ALL records from a specific file
|
||||
bash mqtt_ad_send.sh -i mqtt_ad_record_testDevice.log
|
||||
|
||||
#Send selected records from log file:
|
||||
bash mqtt_ad_send.sh PARTIAL_DEVICE_NAME
|
||||
```
|
||||
102
support/mqtt_ad/mqtt_ad_record.sh
Normal file
102
support/mqtt_ad/mqtt_ad_record.sh
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
sver="20220124-01"
|
||||
: '
|
||||
# Scriptname mqtt_ad_record.sh
|
||||
# Created by JvdZ
|
||||
|
||||
Script that helps capturing MQTT messages for Homeassistant AD into a file so they can be shared easily with others for debugging.
|
||||
|
||||
usage:
|
||||
bash mqtt_ad_record.sh [-h hostname/ip] [-p port] [-s searchstring] [-t*max capture time seconds*]
|
||||
-h Hostname or Ipaddres of MQTT deamon. default is 127.0.0.1
|
||||
-p port for the MQTT deamon. default is 1883
|
||||
-u Userid for MQTT deamon
|
||||
-P Password for MQTT deamon
|
||||
-s only records MQTT messages that contain this string in the TOPIC or PAYLOAD. default is all messages
|
||||
-t caputure time in seconds. default is 600
|
||||
|
||||
examples:
|
||||
# Records all MQTT Messages containing "/config", "_state" or "/state" for 10 minutes.
|
||||
bash mqtt_ad_record.sh
|
||||
|
||||
# specify userid and password to access the MQTT deamon.
|
||||
bash mqtt_ad_record.sh -u UserId -P Password
|
||||
|
||||
#Records all MQTT Messages containing "/config", "_state" or "/state" for 30 Seconds.
|
||||
bash mqtt_ad_record.sh -t 30
|
||||
|
||||
#Records all MQTT Messages containing "TASMOTA_A1" for 10 minutes.
|
||||
bash mqtt_ad_record.sh -s TASMOTA_A1
|
||||
|
||||
#Records all MQTT Messages containing "TASMOTA_A1" for 30 seconds.
|
||||
bash mqtt_ad_record.sh -s TASMOTA_A1 -t 30
|
||||
|
||||
Output file name:
|
||||
The above commands will create file mqtt_ad_record_XXX.log in the current directory,
|
||||
where XXX will be all for the first 2 examples and will be TASMOTA_A1 for the last 2 examples.
|
||||
'
|
||||
|
||||
MQTT_IP="127.0.0.1" # Define MQTT Server
|
||||
MQTT_PORT="1883" # Define port
|
||||
rtime=600 # Define default Capture time for MQTT messages in seconds.
|
||||
# You can always interrupt the capture process at anytime withCtrl+Break pr Ctrl+C
|
||||
MQTT_Param="" # used for extram mosquitto_sub parameters
|
||||
|
||||
# Check if mosquitto_sub is installed
|
||||
if ! command -v mosquitto_sub &> /dev/null; then
|
||||
echo "================================================================================================================="
|
||||
echo "This script can be used to capture MQTT messages for a particular device."
|
||||
echo "Current MQT Server $MQTT_IP port $MQTT_PORT, edit script to change these."
|
||||
echo "!!!! program mosquitto_sub not found, please install that first."
|
||||
echo "RPI install:sudo apt-get install mosquitto-clients"
|
||||
echo "================================================================================================================="
|
||||
exit
|
||||
fi
|
||||
# process parameters
|
||||
while getopts h:p:u:P:s:t: flag
|
||||
do
|
||||
case "${flag}" in
|
||||
h) MQTT_IP=${OPTARG};;
|
||||
p) MQTT_PORT=${OPTARG};;
|
||||
u) MQTT_Param=${MQTT_Param}' -u '${OPTARG}'';;
|
||||
P) MQTT_Param=${MQTT_Param}' -P '${OPTARG}'';;
|
||||
s) sdev=${OPTARG};;
|
||||
t) rtime=${OPTARG};;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set case insensitive flag for the PARTIAL_DEVICE_NAME tests
|
||||
shopt -s nocasematch
|
||||
|
||||
# trap ctrl-c and call ctrl_c()
|
||||
trap message INT
|
||||
|
||||
function message() {
|
||||
echo "** CTRL-C pressed."
|
||||
# command for clean up e.g. rm and so on goes below
|
||||
}
|
||||
|
||||
echo "== $sver =============================================================================================================="
|
||||
echo "MQTT_IP : '$MQTT_IP'";
|
||||
echo "MQTT_PORT : '$MQTT_PORT'";
|
||||
echo "MQTT_Param: '$MQTT_Param'";
|
||||
echo "Recordtime: '$rtime'";
|
||||
echo "Search For: '$sdev'";
|
||||
|
||||
logfile="mqtt_ad_record_all.log"
|
||||
# Start Capture
|
||||
if [[ -z $sdev ]]; then
|
||||
echo "Start Capture for $rtime seconds of all MQTT messages to Console and file: $logfile"
|
||||
mosquitto_sub $MQTT_Param -h $MQTT_IP -p $MQTT_PORT -t "#" -v -W $rtime -F "%I\t%r\t%t\t%p"| stdbuf -i0 -o0 grep -i -e "\/config\|[_\/]state" | stdbuf -i0 -o0 tee "$logfile"
|
||||
else
|
||||
# remove characters in filename that aren't allowed
|
||||
logfile="mqtt_ad_record_"${sdev//[^A-Za-z0-9-_]/}".log"
|
||||
echo "Start Capture for $rtime seconds of MQTT messages containing $sdev to Console and file: $logfile"
|
||||
mosquitto_sub $MQTT_Param -h $MQTT_IP -p $MQTT_PORT -t "#" -v -W $rtime -F "%I\t%r\t%t\t%p"| stdbuf -i0 -o0 grep -i "$sdev" | stdbuf -i0 -o0 tee "$logfile"
|
||||
fi
|
||||
# Capture Ended
|
||||
if [ "$?" -eq "0" ] ; then
|
||||
echo "Capture ended, check file: $logfile"
|
||||
else
|
||||
echo "Capture interrupted, check file: $logfile"
|
||||
fi
|
||||
102
support/mqtt_ad/mqtt_ad_send.sh
Normal file
102
support/mqtt_ad/mqtt_ad_send.sh
Normal file
@@ -0,0 +1,102 @@
|
||||
#!/bin/bash
|
||||
sver="20220124-01"
|
||||
: '
|
||||
# Scriptname mqtt_ad_send.sh
|
||||
# Created by JvdZ
|
||||
|
||||
Script that sends the captured mqtt records again to a server recorded in HA_Discovery_mqtt.log in dezelfde directory.
|
||||
|
||||
usage:
|
||||
bash mqtt_ad_send.sh [-h hostname/ip] [-p port] [-s searchstring] [-i inputfile]
|
||||
-h Hostname or Ipaddres of MQTT deamon. default is 127.0.0.1
|
||||
-p port for the MQTT deamon. default is 1883
|
||||
-u Userid for MQTT deamon
|
||||
-P Password for MQTT deamon
|
||||
-s only send MQTT messages that contain this string in the TOPIC or PAYLOAD. default is all messages
|
||||
-i inputfile. default is mqtt_ad_record_all.log
|
||||
-r override retain (y/n). defaults to the retain flag in the record
|
||||
-d When Dry-run when switch is provided, no MQTT messages will be send, just the logging.
|
||||
|
||||
example:
|
||||
ALL records : bash mqtt_ad_send.sh
|
||||
Selected records: bash mqtt_ad_send.sh PARTIAL_DEVICE_NAME
|
||||
'
|
||||
|
||||
MQTT_IP="127.0.0.1"
|
||||
MQTT_PORT="1883"
|
||||
MQTT_Param=""
|
||||
input="mqtt_ad_record_all.log"
|
||||
retain=""
|
||||
dryrun=""
|
||||
|
||||
# process parameters
|
||||
while getopts h:p:u:P:s:i:r:d flag
|
||||
do
|
||||
case "${flag}" in
|
||||
h) MQTT_IP=${OPTARG};;
|
||||
p) MQTT_PORT=${OPTARG};;
|
||||
u) MQTT_Param=${MQTT_Param}' -u '${OPTARG};;
|
||||
P) MQTT_Param=${MQTT_Param}' -P '${OPTARG};;
|
||||
s) sdev=${OPTARG};;
|
||||
i) input=${OPTARG};;
|
||||
r) retain=${OPTARG};;
|
||||
d) dryrun='y';;
|
||||
esac
|
||||
done
|
||||
|
||||
# Set case insensitive flag for the PARTIAL_DEVICE_NAME tests
|
||||
shopt -s nocasematch
|
||||
|
||||
echo "== $sver =============================================================================================================="
|
||||
echo "MQTT_IP : '$MQTT_IP'";
|
||||
echo "MQTT_PORT : '$MQTT_PORT'";
|
||||
echo "MQTT_Param: '$MQTT_Param'";
|
||||
echo "inputfile : '$input'";
|
||||
if [[ ! -z "$retain" ]] ; then
|
||||
echo "Retain override with '$retain'";
|
||||
fi
|
||||
if [[ ! -z "$dryrun" ]] ; then
|
||||
echo "### Dry-Run so no MQTT messages are send, just showing the log of the selected messages.###";
|
||||
fi
|
||||
|
||||
srec=0;
|
||||
|
||||
#Get rid of CR and only leave LF and read all records
|
||||
# -r option read is to leave backslaches as in the file
|
||||
cat "$input" | tr -d "\r" | while IFS=$'\t' read -r itime iretain itopic ipayload;
|
||||
do
|
||||
#echo -e "###\nT=$itopic\nP=$ipayload"
|
||||
#skip Comment lines starting with #
|
||||
[[ itime =~ ^#.* ]] && { continue; }
|
||||
|
||||
#skip empty lines or only one param is provided
|
||||
[[ -z "$ipayload" ]] && { continue; }
|
||||
|
||||
#skip lines that do not contain the selected dev
|
||||
[[ ! $itopic =~ $sdev ]] && {
|
||||
[[ ! $ipayload =~ $sdev ]] && { continue; }
|
||||
}
|
||||
|
||||
## process the selected record
|
||||
srec=$((srec+1))
|
||||
# Set MQTT Options
|
||||
MQTT_Opts=""
|
||||
# Add Retain option when 1 is specified in input or in the override param -r
|
||||
if [[ -z "$retain" ]] ; then
|
||||
[[ "$iretain" == "1" ]] && { MQTT_Opts=" -r";}
|
||||
else
|
||||
[[ "$retain" == "y" ]] && { MQTT_Opts=" -r";}
|
||||
fi
|
||||
if [[ -z "$dryrun" ]] ; then
|
||||
echo -e "== $srec > $MQTT_Opts\nT=$itopic\nP=$ipayload"
|
||||
mosquitto_pub $MQTT_Param $MQTT_Opts -h $MQTT_IP -p $MQTT_PORT -t "$itopic" -m "$ipayload"
|
||||
else
|
||||
echo -e "-- $srec: $MQTT_Opts\nT=$itopic\nP=$ipayload"
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ! -z "$dryrun" ]] ; then
|
||||
echo "###============================================###";
|
||||
echo "### Dry-Run ended,so no MQTT messages are send.###";
|
||||
echo "###============================================###";
|
||||
fi
|
||||
Reference in New Issue
Block a user