Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
add networks in ssid channel
  • Loading branch information
Eyal Cohen authored and Eyal Cohen committed Feb 4, 2021
1 parent 30c6a5e commit 9031c02
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ The application publish:

- App version
- Number of discovered networks in the state field
- Number of networks in the specified ssid channel
- Total number of networks per channel in the channels field.
- SSID channel with the channel of the specified SSID (0 if not specified).
- Highest level received per channel (in dBm)

```
{"state":6,"version":"1.0.3","ssid_channel":6,"channels":[0,0,0,0,0,0,4,0,0,0,0,2,0],"levels":[-100,-100,-100,-100,-100,-100,-21,-100,-100,-100,-100,-64,-100]}
{"state":6,"version":"1.0.3","ssid_channel":6,"ssid_networks":4,"channels":[0,0,0,0,0,0,4,0,0,0,0,2,0],"levels":[-100,-100,-100,-100,-100,-100,-21,-100,-100,-100,-100,-64,-100]}
```

The following sensor can be used to track the number of networks in wifi channel 7:
Expand Down
8 changes: 6 additions & 2 deletions app.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# App version
version="1.0.3"
version="1.0.4"

# Delay in seconds (default - 10 minutes)
delay="${DELAY:-600}"
Expand Down Expand Up @@ -38,6 +38,10 @@ do
channels=("${values[@]:1:13}")
levels=("${values[@]:14:26}")

# Get the number of networks in the ssid channel
channel=$((ssid_channel-1))
ssid_networks=${channels[$channel]}

# Total number of networks
total=0
for i in ${channels[@]}; do
Expand All @@ -51,7 +55,7 @@ do
levels=$(echo \[${levels:1}\])

# Publish
message=$(echo \{\"state\":$total,\"version\":\"$version\",\"ssid_channel\":$ssid_channel,\"channels\":$channels,\"levels\":$levels\})
message=$(echo \{\"state\":$total,\"version\":\"$version\",\"ssid_channel\":$ssid_channel,\"ssid_networks\":$ssid_networks,\"channels\":$channels,\"levels\":$levels\})
mosquitto_pub -h $mqtt_url -t $mqtt_topic -m $message

# Wait before next scan
Expand Down
10 changes: 6 additions & 4 deletions scan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ level=${LEVEL:--999}
# Min level for levels array
min_level=${MIN_LEVEL:--100}

# Ssid chanle (if SSID specified)
# Ssid channel (if SSID specified)
ssid_channel=0

# Networks per channel
networks=(0 0 0 0 0 0 0 0 0 0 0 0 0)
networks=(0 0 0 0 0 0 0 0 0 0 0 0 0 0)

# Channel max level
levels=($min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level)
levels=($min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level $min_level)

# Scan and parse
while IFS= read -r line; do
Expand All @@ -42,6 +42,7 @@ while IFS= read -r line; do
if [[ "$essid" == "\"$ssid\"" ]]; then
ssid_channel=$chn
fi
#
if [ $lvl -gt ${levels[$chn]} ]; then
levels[$chn]="$lvl"
fi
Expand All @@ -50,5 +51,6 @@ while IFS= read -r line; do

done


# Return channels scan result
echo $ssid_channel "${networks[@]}" "${levels[@]}"
echo $ssid_channel "${networks[@]:1}" "${levels[@]:1}"

0 comments on commit 9031c02

Please sign in to comment.