3.-A NATS installation

The NATS server is a simple, secure and high-performance open source messaging system that is used for the different remoteSwitch modules to communicate with each other. As many remoteSwitch modules as devices to be controlled are desired. In addition, you always have to run a remoteSwitch configured as a web server, then at least we will have 2 remoteSwitch running. The NATS server is used for communication between all these modules. You can download the NATS server from its official website that you will find at:

https://nats.io

Download NATS module

We can download version 2.0.4 from my website:

https://ea4tx.com/wp-content/uploads/files/rspi/nats-server

We have many ways to put the NATS binary in the RsPi, some will surely choose to download it to the PC and from it, upload it through an FTP to the RsPi. Here we are going to do it using the wget command as shown below:

wget https://ea4tx.com/wp-content/uploads/files/rspi/nats-server

With this we already have the binary in the RsPi although surely in the root folder or /home/pi. Now we are going to copy it to the folder /usr/local/sbin which is where it would usually be left, for this we can use the program mc (midnight commander that we had already installed in step 2) or by using the command:

sudo cp nats-server /usr/local/sbin/

You can do these two steps in one, using the command:

wget https://ea4tx.com/wp-content/uploads/files/rspi/nats-server -P /usr/local/sbin

You will have to indicate that the type of file can be executed, with which you will surely have to change its properties, something to do by using the command:

sudo chmod 755 /usr/local/sbin/nats-server

With this we have the program ready. It is not necessary to configure anything.

We execute it and verify that it starts well.

Start System

So that when you turn on the Raspberry Pi the program will automatically run, we will use SystemD. To do this, we will leave a file in the /etc/systemd/system folder such as nats.system This file indicates the path where the program is located, its startup options, the user account with which it runs, etc. You can download This file from my site using the command:

sudo wget https://ea4tx.com/wp-content/uploads/files/rspi/nats.service

We will copy this file to the /etc/systemd/system folder, then the command will be:

sudo cp nats.service /etc/systemd/system/

In principle, this file that you have downloaded and copied to the /etc/systemd/system folder can be left as is without having to change anything in it. Now we only have to add this nats service in the systemd manager, then we execute the command:

sudo systemctl enable nats.service

With this already restarting the RsPi, this service will be executed automatically. You can also start or stop manually, for this the start command would be:

sudo service nats start

or to stop:

sudo service nats stop

With all this, we should already have the nats server up and running, ready so that when we start the remoteSwitch modules can connect. We will see this later.

3.-B ser2net instation

The ser2net module works as a router or gateway between serial ports and TCP/IP. It allows defining in a configuration file (/etc/ser2net.conf) and line by line, each of the serial ports that we want to be accessible by a TCP/IP port. In this way, an application can connect to that TCP/IP port and access the serial device via the ser2net.

  • Note: Through a single ser2net service you can access as many serial devices as defined.

The serial devices are going to be each of the RemoteBox or StackMain that we connect to the RsPi and with this we allow them to be accessible by TCP/IP. Thanks to this service, the windows RBM client can connect to the device via TCP/IP and the remoteSwitch also accesses.

Since the standard version of the ser2net does not allow two clients to access the same port simultaneously, I have compiled the standard version and left a version on my server that does. Therefore, the simplest is to install the standard ser2net package and update only the binary.

Ser2net standard installation

To install the standard ser2net package, run:

sudo apt-get install ser2net

The installer will have left the program in the \usr\sbin\ser2net folder, the ser2net.conf configuration file in \etc and the service boot system ready. Now we are going to replace this executable with the one that allows multiple simultaneous connections.

Ser2net update

To download the update we first ensure that the ser2net server is stopped by the command

sudo service ser2net stop

We remove the standard executable:

sudo rm /usr/sbin/ser2net

And we downloaded the new executable leaving it in the folder \usr\sbin which is where the installed version was.

sudo wget https://ea4tx.com/wp-content/uploads/files/rspi/ser2net -P /usr/sbin

Finally we change the attribute so that it can be executed, using the command:

sudo chmod 755 /usr/sbin/ser2net

Ser2net configuration

The configurator of the ser2net service is called ser2net.conf and we have it in \etc. Edit the file:

sudo nano /etc/ser2net.conf

In our case we remove the 4 lines of the example that are created by default and incorporate the line for our service, adding the new option that allows defining the number of simultaneous maximum connections (in this example 10)

7011:raw:600:/dev/ttyACM0:38400 8DATABITS NONE 1STOPBIT max-connections=10

Note: If we need to define more devices, we will indicate as many lines as we want to define. In that example the configuration indicates:

  • It listens on the TCP / IP port: 7011
  • in raw mode or without processing
  • With 600 seconds timeout
  • And it is associated with the ttyACM0 serial device. This would be the name associated with the serial port created when connecting the RemoteBox
  • 33800 bps 8 bit bit rate, no parity stop
  • supporting up to 10 simultaneous connections

If we have a RemoteBox already connected to the RsPi and we have already edited the ser2net file and started the service

sudo service ser2net start

We can prove that the ser2net service is working before continuing with the final part and that it would be to install the remoteSwitch and its web server which will be what you see in the last section.

Run the RBM program on your computer and configure that the service is via TCP/IP indicating the IP and Port of the defined service.