
This document provides a sample configuration on how to configure the digital inputs on the router to mirror the digital relay outputs on a remote router.
Initial Setup
Save a copy of the script-dio-mirror for both the local and remote
Local Router

PORT the UDP port of the remote router
REMOTE the remote router IP address
FREQ the frequency in seconds to send updates to the remote router
/*
* Copyright (C) 2019 AVVERO
*/
PORT = 6666;
REMOTE = "172.30.6.110";
FREQ = 1;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) {
nb_syslog("Unable to open socket\n");
exit(1);
}
ret = bind(sock, PORT, "");
if(ret == -1) {
nb_syslog("Unable to bind to port: %d\n", PORT);
close(sock);
exit(1);
}
nb_syslog("Sending messages on port %d\n", PORT);
for(;;)
{
sleep(FREQ);
MSG = sprintf("in1=%d in2=%d out1=%d out2=%d",
nb_dio_get("in1"),
nb_dio_get("in2"),
nb_dio_get("out1"),
nb_dio_get("out2"));
if (sendto(sock, MSG, REMOTE, PORT) != strlen(MSG))
nb_syslog("ERROR: UDP GPIO message failed");
}
Remote Router

PORT the UDP port of the remote router
/*
* Copyright (C) 2019 AVVERO
*/
PORT = 6666;
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) {
nb_syslog("Unable to open socket\n");
exit(1);
}
ret = bind(sock, PORT, "");
if(ret == -1) {
nb_syslog("Unable to bind to port: %d\n", PORT);
close(sock);
exit(1);
}
nb_syslog("Listening for messages on port %d\n", PORT);
while (1) {
msg = recvfrom(sock);
if (msg != "") {
ret = (int) strstr(msg, "in1");
state = (int) substr(msg, (ret+4), 1);
cin1 = nb_dio_get("out1");
if (state != cin1) {
nb_dio_set("out1", state);
nb_syslog("Digital Relay = %s",state);
}
ret = (int) strstr(msg, "in2");
state = (int) substr(msg, (ret+4), 1);
cin2 = nb_dio_get("out2");
if (state != cin2) {
nb_dio_set("out2", state);
nb_syslog("Digital Relay = %s",state);
}
}
}
close(sock);
exit(0);