Skip to content

Commit

Permalink
Merge pull request #1 from smartrent/srhub_90
Browse files Browse the repository at this point in the history
Removes usage of ZipGateway.
  • Loading branch information
mattludwigs authored Jun 20, 2019
2 parents 86d51de + 3c2187b commit e185d22
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lib/grizzly/application.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
defmodule Grizzly.Application do
use Application
require Logger

def start(_type, _args) do
_ = Logger.info("Starting Grizzly")

children =
[
Grizzly.Notifications,
Expand Down
19 changes: 14 additions & 5 deletions lib/grizzly/conn/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ defmodule Grizzly.Conn.Server do
alias Grizzly.{Notifications, Command, Conn}
alias Grizzly.Conn.Config

@retry_connect_delay 1_000

@type t :: pid

defmodule State do
Expand Down Expand Up @@ -137,6 +139,15 @@ defmodule Grizzly.Conn.Server do

:noop ->
{:noreply, state}

{:error, :timeout} ->
_ =
Logger.warn(
"[GRIZZLY] Setup autoconnect timed out. Retrying in #{@retry_connect_delay}"
)

Process.send_after(self(), :setup, @retry_connect_delay)
{:noreply, state}
end
end

Expand Down Expand Up @@ -261,15 +272,13 @@ defmodule Grizzly.Conn.Server do
%{status: :queued, queued_ref: ref, from: {pid, _}, owner: owner},
response
) do
message = {ZipGateway, :queued_response, ref, response}
message = {Grizzly, :queued_response, ref, response}
receiver = owner || pid

_ =
Logger.info(
"[ZIPGATEWAY] Sending queued response #{inspect(message)} to #{inspect(receiver)}"
)
Logger.info("[GRIZZLY] Sending queued response #{inspect(message)} to #{inspect(receiver)}")

send(receiver, {ZipGateway, :queued_response, ref, response})
send(receiver, {Grizzly, :queued_response, ref, response})
end

defp send_response(%{status: :active, from: {pid, _}, mode: :async}, response) do
Expand Down
1 change: 1 addition & 0 deletions lib/grizzly/notifications.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ defmodule Grizzly.Notifications do
end

def start_link() do
_ = Logger.info("[GRIZZLY] Starting registry #{@registry_name}")
Registry.start_link(keys: :duplicate, name: @registry_name)
end

Expand Down
6 changes: 0 additions & 6 deletions lib/grizzly/packet/encoder.ex

This file was deleted.

4 changes: 2 additions & 2 deletions lib/grizzly/unsolicited_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ defmodule Grizzly.UnsolicitedServer do
) do
case :ssl.listen(41230, opts(ip_address, ip_version)) do
{:ok, listensocket} ->
_ = Logger.info("[ZIPGATEWAY]: unsolicited server waiting for connections")
_ = Logger.info("[GRIZZLY]: unsolicited server waiting for connections")
start_accepting_sockets(listensocket)
{:noreply, %{state | socket: nil}}

error ->
_ =
Logger.warn(
"[ZIPGATEWAY]: Unable to bind unsolicited messages server. Error: #{inspect(error)}"
"[GRIZZLY]: Unable to bind unsolicited messages server. Error: #{inspect(error)}"
)

Process.send_after(self(), :listen, 2_000)
Expand Down
4 changes: 2 additions & 2 deletions lib/grizzly/unsolicited_server/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ defmodule Grizzly.UnsolicitedServer.Socket do
|> :binary.list_to_bin()
|> Packet.decode()

_ = Logger.debug("[ZIPGATEWAY]: unsolicited message received: #{inspect(parsed_data)}")
_ = Logger.debug("[GRIZZLY]: unsolicited message received: #{inspect(parsed_data)}")
Notifications.broadcast(:unsolicited_message, prepare_message(parsed_data, node_id))
{:noreply, state}
end

def handle_info({:ssl_closed, {:sslsocket, {_, {_, {{_ip, _}, _}}, _}, _}}, state) do
_ = Logger.info("[ZIPGATEWAY]: unsolicated messages closed")
_ = Logger.info("[GRIZZLY]: unsolicated messages closed")
{:stop, :normal, state}
end

Expand Down
36 changes: 36 additions & 0 deletions priv/zipgateway.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Refer to zipgateway manual page in the documentation for
# more information.

ZipSerialAPIPortName = /dev/ttyS4
ZipUnsolicitedDestinationIp6 = fd00:aaaa::2
ZipUnsolicitedDestinationPort = 41230
#ZipUnsolicitedDestination2Ip6 = fd00:aaaa::1234
#ZipUnsolicitedDestination2Port = 41231
#SerialLog = /tmp/ziprouter.serlog
ZipCaCert=/etc/Portal.ca_x509.pem
ZipCert=/etc/ZIPR.x509_1024.pem
ZipPrivKey=/etc/ZIPR.key_1024.pem
Eepromfile=/root/zipeeprom.dat
TunScript=./zipgateway.tun
PVSStorageFile=/root/provisioning_list_store.dat
ProvisioningConfigFile=/etc/zipgateway_provisioning_list.cfg
ZipPanIp6 = fd00:bbbb::1
ZipLanIp6 = fd00:aaaa::1

# The zipgateway shouldn't be sending anything outside of the LAN/PAN
ZipLanGw6 = ::1

#ZipPortal=192.168.1.1
#ZipPortalPort=44123
#ZipTunPrefix = 2000::
#ZipTunIp6PrefixLength = 128
#ZipManufacturerID=0
#ZipHardwareVersion=1
#ZipProductID=1
#ZipProductType=1
#ZipMBPort=41230
#ZipMBDestinationIp6=
#ZipMBMode=1
ZipPSK=123456789012345678901234567890AA
#ExtraClasses= 0x43 0x75
#UdpServerLogFile=/tmp/zipmessages.log
37 changes: 37 additions & 0 deletions priv/zipgateway.tun
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

# This script brings the tuntap interface up and routes the
# Z-Wave PAN via the Z-Wave gateway's IP address.

ROUTING_PID="/tmp/zipgateway.routing.pid"

case "$1" in
up)
ip link set dev $TUNDEV up
ip addr add fd00:aaaa::2 dev $TUNDEV

if [ -f $ROUTING_PID ]; then
kill -9 $(cat $ROUTING_PID)
rm -f $ROUTING_PID
fi

sh -c "while true; do
pidof zipgateway || break;
ip -6 route del $HANPREFIX > /dev/null 2>&1
ip -6 route add $HANPREFIX via $LANIP dev $TUNDEV > /dev/null 2>&1
if [ \$? -eq 2 ]; then
sleep 5;
continue;
else
break;
fi;
done;" &

echo $! > $ROUTING_PID

exit 0
;;
down)
ip -6 route del $HANPREFIX via $LANIP
;;
esac

0 comments on commit e185d22

Please sign in to comment.