Last active
October 15, 2016 17:56
-
-
Save valentt/4ccc4d124f9886c18d7cb6a2299f33ca to your computer and use it in GitHub Desktop.
show babel netighboorts and send High or Low signal via serial connection to Arduino with lasers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
######################################################### | |
# Display the status of the Babel mesh. | |
# Latest version: | |
# http://redmine.bidon.ca/projects/reseaulibre-scripts/repository/raw/babelstatus.sh | |
# | |
# Usage: | |
# babelstatus.sh : shows babel routes | |
# babelstatus.sh --full : show other relevant info | |
# | |
# If you add your link-local addresses to your /etc/hosts | |
# you will get a more readable output. | |
######################################################### | |
# Detect the port used by Babel | |
# BABELDPORT=`uci get babeld.@general[0].local_server` | |
DS1=L | |
DS2=L | |
DS3=L | |
RI1=L | |
RI2=L | |
LTE=L | |
if [ "$BABELDPORT" = "" ]; then | |
BABELDPORT=33123 | |
fi | |
# Complicated awk script (because Perl is hard to install on OpenWRT) | |
AWK=' | |
function get_hostname_from_ip(ip) { | |
result = ip " [unknown]"; | |
command = "grep " ip " /etc/hosts"; | |
command | getline result; | |
close(command); | |
return result; | |
} | |
function get_neighbour(str) { | |
start = match(str, "via ([^ ]*)"); | |
ip = substr(str, start + 4, RLENGTH - 4); | |
host = get_hostname_from_ip(ip); | |
return host; | |
} | |
function strskip(str, skip) { | |
start = match(str, "(" skip ")"); | |
return substr(str, start + RLENGTH); | |
} | |
BEGIN { | |
neighstarted=0; | |
exportstarted=0; | |
} | |
{ | |
if (/^BABEL 0/) { | |
} | |
else if (/^add self alamakota id/) { | |
print "My MAC ID: ", $5; | |
} | |
else if (/^add neighbour/) { | |
if (! neighstarted) { | |
print "*** Neighbours ***"; | |
neighstarted=1; | |
} | |
ip = $5; | |
host = get_hostname_from_ip(ip); | |
print host strskip($0, "add neighbour [0-9a-zA-Z]+ address [^ ]+"); | |
} | |
} | |
' | |
[ -f /tmp/susjedi ] && rm /tmp/susjedi | |
nc :: $BABELDPORT | awk '{ if (/^add/) { print } }' | awk -v FULL=$1 "$AWK" | grep mesh0 > /tmp/susjedi & | |
sleep 2 | |
# cat /tmp/susjedi | cut -f 1 -d ' ' | |
grep "fe80::14cc:20ff:fe77:bc08" /tmp/susjedi && DS1=H | |
grep "fe80::a62b:b0ff:fec7:b29e" /tmp/susjedi && DS2=H | |
grep "fe80::62e3:27ff:feb5:8c6a" /tmp/susjedi && DS3=H | |
grep "fe80::a62b:b0ff:feb0:4c12" /tmp/susjedi && RI1=H | |
grep "fe80::16cc:20ff:fe77:bbf2" /tmp/susjedi && RI2=H | |
grep "fe80::62e3:27ff:feb5:8e08" /tmp/susjedi && LTE=H | |
cat /dev/ttyUSB0 & | |
echo $DS1$DS2$DS3$RI1$RI2$LTE > /dev/ttyUSB0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment