4G router as a universal server for IoT

Routers of the ICR-3200 series are designed to replace the classic bundle: a single-board computer + modem + router. Now you can run all the necessary logic directly on the router. Thanks to a powerful ARM processor, 512 MB of RAM and ~ 2 GB of internal flash memory, you can even start the nodejs server on the router!

Serial RS-232/485 interfaces are also built into the router and are available immediately in the operating system with full root access. An open environment for building native programs and a C / C ++ library for working with low-level hardware APIs is also available.
The deep sleep function will save energy when working on battery power: the router can be activated only when communication is really needed.

In the article, we will analyze the interesting functions of the device and try in practice to work with the I / O interface from shell scripts.


The routers of the ICR-3200 series are made on a single hardware platform and are represented by five models that differ in the frequency ranges of LTE, the presence of Wi-Fi and geolocation (GNSS). Devices are positioned as a replacement for a bundle of a single-board computer and a router. A powerful processor and a large amount of RAM allows you to run resource-intensive user applications directly on the router.

Separately, there is an ICR-3211B model that works according to the LTE Cat standard. M1 ( NB-IoT ). LTE Cat protocol. M1 was specifically designed for M2M solutions, has a low data transfer rate (375 kb / s), as well as a longer range and increased stability in difficult indoor communication conditions. The router has a built-in ionistor (supercapacitor) , allowing the device to work for a short time after a complete power outage.

Deep sleep mode

Deep sleep mode allows you to enter the router into a state where all processes are frozen and the hardware is turned off to save energy, while all the functions of the device are turned off and from the side it will look completely off. The energy consumption in this mode is not more than 10 mW .

In sleep mode, the router almost does not consume energy and wakes up in 3 seconds

When you need to wake up the router for data transfer, it will wake up in ~ 3 seconds . Of course, additional time will be required to register the modem on the cellular network, but this is significantly faster than downloading the router from scratch. This option is useful for self-powered systems, most of which are idle and occasionally activated, to perform active actions, such as an alarm or a backup unit.

Awakening and falling asleep

Management of falling asleep and waking up occurs through the Sleep Mode module.

There are 2 ways to control sleep mode:

Deep sleep configuration interface

Last breath function

A power failure at a remote site can be especially unpleasant, because it is not clear why communication with the site is unavailable. The “Last breath” function allows the router to work for some time after a complete power outage and send a message that an accident has occurred and the backup power has not turned on. Thanks to the built-in ionistor, the resource of which is much more than rechargeable batteries, it does not require maintenance and replacement. This is useful for power backup systems where failures are possible and it is important to keep track of when the voltage is completely lost.

The router will send a signal about a power failure even after a complete power outage

In order to properly respond to the event of power loss, you need to somehow find out about it.
The current supply voltage can be obtained either using the status sys shell command:

 $ status sys Firmware Version : 6.1.10 (2019-07-02) Serial Number : ACZ1100000623519 Profile : Standard RTC Battery : Ok Supply Voltage : 12.3 V # ←   Temperature : 37 C # ←    Time : 2019-08-16 16:21:18 Uptime : 0 days, 11 hours, 43 minutes 

Or using the hardware Unix I / O control (ioctl) and a program in C / C ++ or another language.
The table shows the addresses of the required hardware registers. The current supply voltage is returned as an integer, in millivolts. Using a low-level API is preferable to shell scripts in this case for a faster reaction. Detailed information on working with the hardware is available in the developer's guide.

An ioctl request that returns the current supply voltage.

Serial interfaces

Two serial interfaces are built into the router: RS-232 and RS-485. They allow you to connect peripheral devices directly to the router, without the use of additional strapping. At the same time, a full-fledged Node-RED or Nodejs server can be launched on the router, which allows one device to be deployed to deploy a simple automation system, without additional computers and controllers.

By default, both interfaces are available to work as standard serial devices in Linux:

 ls -la /dev/ttyS* crw------- 1 root root 251, 0 Jan 1 1970 /dev/ttyS0 # ←  rs-232 crw------- 1 root root 251, 1 Jan 1 1970 /dev/ttyS1 # ←  rs-485 crw------- 1 root root 251, 5 Jan 1 1970 /dev/ttyS5 # ←   

All standard libraries will support these devices without additional settings, including the Modbus-RTU2TCP module and others.

Custom modules

The functionality of the device can be expanded using custom modules: this is a simplified version of packages, only without a package manager. The entire list of available modules is available at https://advantech-bb.cz/products/software/user-modules .

The modules are installed manually by downloading the package file via the web interface:

Currently 73 modules are available. Here are some interesting ones:

Since the firmware of the routers is open, developers can write their own modules, including those with a web interface. Reference materials are available in the module writing guide and in the developer section of the company’s website. For the convenience of building packages, a ready -made cross-compilation environment is available.

Hardware resources through shell scripts

For simple automation tasks it is convenient to use shell scripts from which you can control the light indication and receive / set the status of digital pins.

Light indication is convenient to show the current status of command execution. For example, the data transfer indication - frequent blinking, connection attempt - rare blinking, simple - lights up continuously. Consider the led command. At the input, it takes only one argument - the type of LED blinking.

 # led led on|off|fast|slow 

Here's what it looks like in real life:

Demonstration of user indicator operating modes through shell commands

To work with digital pins, use the io command.

 $ io Usage: io [get <pin>] | [set <pin> <value>] io set out0 1 #    OUT0   1 (LOW) io get bin0 #     BIN0 

It is important to remember that the logic in this case is inverted. Accordingly, 1 = LOW, 0 = HIGH. Using the io command, we can easily work with digital pins from bash scripts and build simple logic for automation and control.

As a demonstration of the simplicity of working with digital inputs and indicators, we will write a useless script that displays the status of a digital input using an LED.

 #!/bin/bash while true do [ $(io get bin0) -eq 0 ] && led fast || led on done 

The principle of the script is simple: if BIN0 is in state 0, then the diode burns often, otherwise it burns continuously. Here's how it looks live:

Demonstration of the bash script that displays the status of a digital input using an indicator.

Despite the primitiveness of this script, it clearly shows how in one line, without additional software, libraries and settings, you can receive input data from digital inputs and respond to them.


Welcome to the Advantech Partner Forum

The Advantech Forum will be a unique platform for discussing local and global trends in the Internet of Things. Here you can exchange experiences using new technological solutions and products, find new customers and partners. You will have a chance to see the products that we described in articles and not only. We will feature industry leaders and representatives of key partners - NVidia, Intel and other companies that are actively involved in the development of the industrial Internet of Things for the coming years. We will be glad to see all the experts in the field of industrial automation and the Internet of things at the event. Participation in the event is free! Limited number of seats. Hurry up to register .

Source: https://habr.com/ru/post/464003/

All Articles