Description

Milesight Routers supports 1 digital output. This article describes the principle of DO and how to control DO. The hardware design of DO on these models is the same. In this article UR32 is taken as example.

The PIN definition on UR32 is as below. For other models please refer to corresponding quick guides.

PINRS232RS485DIDODescription
1---------OUTDigital Output
2------IN---Digital Input
3GND---GND---Ground
4------
COMCommon Ground
5RXDB------Receive Data
6TXDA------Transmit Data



1. Principle of DO

DO is Optocoupler output. When DO outputs low level, the circuit turns on. When DO outputs high level, the circuit turns off. So you need to add power in external circuit to control device. DO port can accept 30V DC (max) input. Output current is 0.3A and output power is 0.3W. Because of the low output power, it’s not used to drive external device. In real case when DO port is connected with high voltage input, you need to add a resistance in series to make sure the circuit works correctly.


 

2. Ways to control DO

Note: do not use more than one trigger ways at the same time.


Requirement

  • Milesight Router: UR32/UR35, UR41, UR75/UF51 with firmware version 76.x.x.x
  • Battery(12VDC) and buzzer LED


Configuration

Make connection according to the below drawing:

COM -- Battery(-) -- Battery (+) -- LED --DO

When DO outputs low level, the circuit turns on, and LED is on.

When DO outputs high level, the circuit turns off, and LED is off.


Simple Test

Here’s simple test to check if DO is working correctly:

  1. Enable DI setting on Service > I/O > DI and set Action as DO; 
  2. Enable DO setting on Service > I/O > DO, then change DO mode and click Save and Apply button. DO mode means when DI triggers, DO will change to this mode. When it’s set “High Level”, DO status is low level DI triggers, LED is on. When it’s set “Low Level”, DO status is high level without DI triggers, LED is off.


 Trouble Shooting:

  1. During test LED is always off.

A. Check if LED can be on when connecting with the battery.

B. Check if Modbus Slave mode is already dis

C. Check if you click Save and Apply button to make settings take effect.

D. Check if you connect to the correct PINs of DO.

  1. During test LED is always on.

A. Check if there is short circuit in wiring.

B. Check if COM port and OUT port connected oppositely.

C. Check if Modbus Slave mode is already disabled.


 

Trigger by DI

  1. Go to Service > I/O > DI to configure DI Setting.2. Click Save. Then go to Service > I/O > DO to enable DO and configure mode.Click Save and Apply button.

In this example, when DI changes to low level (make PIN1-IN and PIN2-GND short connected), DO will be triggered as high level for 1 second.


 

Trigger by SMS

  1. Go to Network > Interface > Cellular to configure SMS Center number. SMS center number is different based on different Telecom operators.
  1. Go to System > Phone & SMS > Phone to add Phone Number List and Phone Group List. Click Save and Apply button.
  2. Enable SMS control feature and select the control phone group.
  3. Go to Service > I/O -> DO to configure Mode as Custom. Select the initial status and phone group.Click Save and Apply button.
  1. Send SMS content to control DO is as below.

set do1 low,20   // set DO to output low level,20 means duration of outputting low level is 20s.

set do1 high,0   // set DO to output high level,0 means continuously outputting high level.

do information   // query the current DO status.


After receiving the SMS, the router will send response as below.


 


Trigger by CLI Commands

You can control DO by CLI commands as below.

ROUTER> en

ROUTER# conf t

ROUTER(config)# industrial-io-output 1

ROUTER(config-output_io)# mode-out low

ROUTER(config-output_io)# no shutdown               //set DO to output low level.

ROUTER(config-output_io)# mode-out high

ROUTER(config-output_io)# no shutdown             //set DO to output high level.


 

Trigger by Modbus TCP

  1. Enable Modbus TCP on Service > Modbus Server > Modbus TCP. Configure port and DO address. The DO address can’t be 1.Click Save and Apply button.
  1. Run Modbus Poll software. Connect to the router by Modbus TCP/IP and configure IP and port. In this example, UR32 is connected to PC via LAN port. So IP is LAN IP 192.168.1.1.Select function as “01 Read Coil (0x)”.Then you can read current DO status on Modbus Poll.


  1. Double click the value of the register, you can control DO status by changing the value.

off/0 means low level, LED turns on.

on/1 meas high level, LED turns off.


 


Trigger by Modbus RTU

  1. Connect the router to PC via USB to RS232/RS485 cable. Take RS232 as an example.
  2. Enable Modbus Server mode on Server > Serial Port > Serial RS232 type.Click Save & Apply button.
  1. Enable the corresponding serial port on Service > Modbus Server > Modbus RTU. Configure Server ID and DO address. DO address can’t be 1.Click Save and Apply button.
  1. Run Modbus Poll software. Connect to the router by Serial Port mode.
  2. Then you can control DO by changing the value of the register.



Trigger by Modbus RTU over TCP

  1. Run Netassist software as TCP server. Make sure the TCP server is reachable from the router.

In this example, router is connected to the PC via LAN port. And PC IP is 192.168.1.100.


  1. Go to Service > Modbus Server > Modbus RTU over TCP and enable it.

Device ID: user-defined

DO address can’t be 1.

Configure the server IP and port which is set on Netassist software.

Click Save and Apply button. And the router will be connected after a while.

  1. Then you can send command from TCP server to control DO status.

Control command varies according to the Server ID and DO address.

In this example, Slave ID is 1 And DO address is 0.

Control frame:

Sever IDFunction CodeStart(DO Address)ValueCRC Parity
0x010x050x00 0x000xFF 0x00

(high level)

0x8C 0x3A
0x010x050x00 0x00x00 0x00
(low level)
0xCD 0xCA

If DO is controlled successfully, the router will send the same frame as response.



Trigger by MQTT

Note: this feature only works with UR3x with firmware version 3x.3.0.8 and later.

  1. Go to Service > MQTT page to add a MQTT connection to connect router to a MQTT broker.
    For more details please refer to article Milesight Router MQTT Messaging Feature.
     
  2. Customize the Status Request topic to send MQTT downlink commands and Status Response topic to receive the replies.
  3. Subscribe the both Status Request and Status Response topics on MQTT client software:
     
  4. Send DO control command to Status Request topic, the request format should be json format.DO command format:
    {
    "id": "1", //Random value
    "sn": "64E1213132456", //Device SN
    "status": "do",
    "need_response": "1" //0=no need response, 1=need response
    }

    Response format:

    {
    "id": "1", //The same as request
    "sn": "64E1213132456",
    "status": "do",
    "time": "2024-04-15T07:32:17Z", //UTC report time
    "result": 0, //0=control failed, 1=control success, 2=DO disabled
    "data": { //DO configuration
    .........
    }
    }
  5. After sending, check the replies under Status Response topic.

 


----END---