Created
January 13, 2019 19:05
-
-
Save stargieg/706d49931da0ffa2f30d1153ccb42254 to your computer and use it in GitHub Desktop.
Send ip6 neigh addr via mqtt
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
local function send_ip6neigh(mqtt,dev) | |
local neigh_table = nil | |
local neightbl = require "neightbl" | |
local neigh = nil | |
local qos = 1 | |
local retain = false | |
neigh_table=neightbl.get(dev) | |
for ip,mac in pairs(neigh_table) do | |
if mac then | |
print("ip6: "..ip.." mac: "..mac) | |
local mid = mqtt:publish("druschba/"..dev.."/", ip..","..mac, qos, retain) | |
end | |
end | |
end | |
local mosq = require("mosquitto") | |
mosq.init() | |
local state = { should_run = true } | |
local mqtt | |
local mqtt = mosq.new() | |
local function handle_ON_CONNECT(success, rc, str) | |
print("on connect ->", success, rc, str) | |
if not success then | |
printf("Failed to connect: %d : %s\n", rc, str) | |
return | |
end | |
state.mqtt_connected = true | |
end | |
broker = arg[1] -- defaults to "localhost" if arg not set | |
mqtt.ON_CONNECT = handle_ON_CONNECT | |
mqtt:connect(broker) | |
mqtt:loop_start() | |
while state.should_run do | |
if state.mqtt_connected then | |
print("send") | |
send_ip6neigh(mqtt,"eth1") | |
send_ip6neigh(mqtt,"eth0.1") | |
send_ip6neigh(mqtt,"eth0.2") | |
end | |
os.execute("sleep 1") | |
print("tick tock...\n") | |
end | |
mqtt:disconnect() | |
mqtt:loop_stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment