Skip to content

Commit

Permalink
adjust script to not use PATH for underlying tools (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ironsheep committed Sep 11, 2020
1 parent 9415e4d commit 324ae1e
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions ISP-lightning-mqtt-daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

signal(SIGPIPE,SIG_DFL)

script_version = "2.2.5"
script_version = "2.2.6"
script_name = 'ISP-lightning-mqtt-daemon.py'
script_info = '{} v{}'.format(script_name, script_version)
project_name = 'lightning-detector-MQTT2HA-Daemon'
Expand Down Expand Up @@ -388,6 +388,22 @@ def isAliveTimerRunning():
# -----------------------------------------------------------------------------
# Perform our MQTT Discovery Announcement...
# -----------------------------------------------------------------------------
host_mac = ''
host_ipaddr = ''
host_interface = ''

def getHostSpecifics():
global host_mac
global host_ipaddr
global host_interface
gw = os.popen("/sbin/ip -4 route show default").read().split()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((gw[2], 0))
host_ipaddr = s.getsockname()[0]
host_interface = gw[4]
ether = os.popen("/sbin/ifconfig " + host_interface + "| /bin/grep ether").read().split()
host_mac = ether[1]


# our lighting device
LD_TIMESTAMP = "last"
Expand All @@ -399,17 +415,10 @@ def isAliveTimerRunning():
LD_SETTINGS = "settings"

# what device are we on?
gw = os.popen("ip -4 route show default").read().split()
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((gw[2], 0))
ipaddr = s.getsockname()[0]
interface = gw[4]
ether = os.popen("ifconfig " + interface + "| grep ether").read().split()
mac = ether[1]
fqdn = socket.getfqdn()

uniqID = "AS3935-{}".format(mac.lower().replace(":", ""))

getHostSpecifics()
uniqID = "AS3935-{}".format(host_mac.lower().replace(":", ""))
print_line('- ip=[{}], mac[{}], interface=[{}], uniq-id=[{}]'.format(host_ipaddr, host_mac, host_interface, uniqID), debug=True)
# Publish our MQTT auto discovery
# table of key items to publish:
detectorValues = OrderedDict([
Expand Down Expand Up @@ -467,7 +476,7 @@ def isAliveTimerRunning():
if 'device_ident' in params:
payload['dev'] = {
'identifiers' : ["{}".format(uniqID)],
'connections' : [["mac", mac.lower()], [interface, ipaddr]],
'connections' : [["mac", host_mac.lower()], [host_interface, host_ipaddr]],
'manufacturer' : '(Austria Micro Systems) ams AG',
'name' : params['device_ident'],
'model' : 'Lightning Detector (AS3935)',
Expand Down

0 comments on commit 324ae1e

Please sign in to comment.