github.com/jingruilea/kubeedge@v1.2.0-beta.0.0.20200410162146-4bb8902b3879/docs/mappers/modbus_mapper.md (about)

     1  # Modbus Mapper
     2  
     3  
     4  ## Introduction
     5  
     6  Mapper is an application that is used to connect and control devices. This is an implementation of mapper for 
     7  Modbus protocol. The aim is to create an application through which users can easily operate devices using ModbusTCP/ModbusRTU protocol for communication to the KubeEdge platform. The user is required to provide the mapper with the information required to control their device through the dpl configuration file. These can be changed at runtime by updating configmap.
     8  
     9  ## Running the mapper
    10  
    11    1. Please ensure that Modbus device is connected to your edge node
    12    2. Set 'modbus=true' label for the node (This label is a prerequisite for the scheduler to schedule modbus_mapper pod on the node)
    13  
    14        ```shell
    15        kubectl label nodes <name-of-node> modbus=true
    16        ```
    17  
    18    3. Build and deploy the mapper by following the steps given below.
    19  
    20  ### Building the modbus mapper
    21  
    22   ```shell
    23  cd $GOPATH/src/github.com/kubeedge/kubeedge/device/modbus_mapper
    24  make # or `make modbus_mapper`
    25  docker tag modbus_mapper:v1.0 <your_dockerhub_username>/modbus_mapper:v1.0
    26  docker push <your_dockerhub_username>/modbus_mapper:v1.0
    27  
    28  Note: Before trying to push the docker image to the remote repository please ensure that you have signed into docker from your node, if not please type the followig command to sign in
    29   docker login
    30   # Please enter your username and password when prompted
    31  ```
    32  
    33  ### Deploying modbus mapper application
    34  
    35  ```shell
    36  cd $GOPATH/src/github.com/kubeedge/kubeedge/device/modbus_mapper
    37  
    38  # Please enter the following details in the deployment.yaml :-
    39  #    1. Replace <edge_node_name> with the name of your edge node at spec.template.spec.voluems.configMap.name
    40  #    2. Replace <your_dockerhub_username> with your dockerhub username at spec.template.spec.containers.image
    41  
    42  kubectl create -f deployment.yaml
    43  ```
    44  
    45  ## Modules
    46  
    47  The modbus mapper consists of the following four major modules :-
    48  
    49   1. Controller
    50   2. Modbus Manager
    51   3. Devicetwin Manager
    52   4. File Watcher
    53  
    54   ### Controller
    55  
    56   The main entry is index.js. The controller module is responsible for subscribing edge MQTT devicetwin topic and perform check/modify operation on connected modbus devices. The controller is also responsible for loading the configuration and starting the other modules. The controller first connects the MQTT client to the broker to receive message of expected devicetwin value (using the mqtt configurations in conf.json), it then connects to the devices and check all the properties of devices every 2 seconds (based on dpl configuration provided in the configuration file) and the file watcher runs parallelly to check whether the dpl configuration file is changed.
    57  
    58   ### Modbus Manager
    59   
    60   Modbus Manager is a component which can perform an read or write action on modbus device. The following are the main responsibilities of this component: 
    61   a) When controller receives message of expected devicetwin value, Modbus Manager will connect to the device and change the registers to make actual state equal to expected. 
    62  
    63   b) When controller checks all the properties of devices, Modbus Manager will connect to the device and read the actual value in registers accroding to the dpl configuration.
    64  
    65   ### Devicetwin Manager
    66  
    67   Devicetwin Manager is a component which can transfer the edge devicetwin message. The following are the main responsibilities of this component: 
    68   a) To receive the edge devicetwin message from edge mqtt broker and parse message.
    69  
    70   b) To report the actual value of device properties in devicetwin format to the cloud.
    71                    
    72   ### File Watcher
    73   
    74   File Watcher is a component which can load dpl and mqtt configuration from configuration files.The following are the main responsibilities of this component: 
    75   a) To monitor the dpl configuration file. If this file changed, file watcher will reload the dpl configuration to the mapper.
    76  
    77   b) To load dpl and mqtt configuration when mapper starts first time.
    78