SDK : Mirror the local digital inputs to the remote digital relay outputsandrewc2019-06-29T15:28:18+11:00
  1. Home
  2. Knowledge Base
  3. Development
  4. SDK : Mirror the local digital inputs to the remote digital relay outputs

Platform

Platform: NetModule
Document Version: 1.1.0Read More »

Software Version

NMRS : 4.0.0 or higher
Modem : n/a

Requirements

Active IP connection between client and server
script-dio-mirror-local.are
script-dio-mirror-remote.are

Introduction

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

 script-dio-mirror-local.are

/* 
 * 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");	
}

Parameters

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

Remote

 script-dio-mirror-remote.are

  /* 
   * 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);

Parameters

PORT the UDP port to listen for connections

Configuration

Uploading the scripts to the router

Upload your copy of the scripts to the routers

Router with digital input trigger – local
script-dio-mirror-local.are

Router with digital relay output trigger – remote
script-dio-mirror-local.are

See the generic example below on how to upload and configure the SDK script for the router.


SDK Status

Ensure that the script is running and using the correct UDP port.

Was this article helpful?