> For the complete documentation index, see [llms.txt](https://docs.cybus.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cybus.io/1-8-0/documentation/services/service-commissioning-files/sample-service-commissioning-files/machine-utilization-example-multi-file-service-composition-modbus-tcp-+-influxdb-+-grafana-+-mss/machine-utilization-example-machine-connectivity.md).

# “Machine Utilization Example” - Machine Connectivity

This this file, Modbus TCP based machine connectivity has been handled. Additionally, data has been pre-processed using Connectware Rules.

Download:

{% file src="/files/4ukOQnpd2rogbIPHWsIB" %}

{% hint style="info" %}
The example below uses an additional Docker image provided by Cybus that requires a suitable license. You can check the current capabilities and permissions of your Connectware license in the Cybus Portal ([https://portal.cybus.io](https://portal.cybus.io/)). If your license is not eligible to use the example Docker image, please contact Cybus Sales ([sales@cybus.io](mailto:sales%40cybus.io)).
{% endhint %}

{% code lineNumbers="true" %}

```yaml
description: >
    Machine connectivity and data mapping

metadata:
    name: ModBus Machine Connectivity
    icon: https://www.cybus.io/wp-content/uploads/2019/03/Cybus-logo-Claim-lang.svg
    provider: cybus
    homepage: https://www.cybus.io
    version: 0.0.1

parameters:
    modbus_connection_ip:
        type: string
        default: 172.17.0.1

    modbus_connection_port:
        type: integer
        default: 10502

resources:
    # Modbus simulator service for this example
    machineSimulator:
        type: Cybus::Container
        properties:
            image: registry.cybus.io/cybus-testing/modbus-machine-simulator:0.0.1
            ports:
                - !sub '${modbus_connection_port}:10502/tcp'

    modbusConnection:
        type: Cybus::Connection
        properties:
            protocol: Modbus
            targetState: connected
            connection:
                host: !ref modbus_connection_ip
                port: !ref modbus_connection_port

    powerLevel:
        type: Cybus::Endpoint
        properties:
            protocol: Modbus
            connection: !ref modbusConnection
            subscribe:
                fc: 3
                length: 2
                interval: 1000
                address: 0
                dataType: floatBE

    mapping:
        type: Cybus::Mapping
        properties:
            mappings:
                - subscribe:
                      endpoint: !ref powerLevel
                  publish:
                      topic: !sub '${Cybus::MqttRoot}/power-level'
                - subscribe:
                      endpoint: !ref powerLevel
                  rules:
                      - transform:
                            expression: |
                                (
                                    $stateMap := [
                                        {
                                            "lower": 0,
                                            "upper": 0,
                                            "state": "OFF"
                                        },
                                        {
                                            "lower": 1,
                                            "upper": 10,
                                            "state": "IDLE"
                                        },
                                        {
                                            "lower": 11,
                                            "upper": 40,
                                            "state": "JOG"
                                        },
                                        {
                                            "lower": 41,
                                            "upper": 100,
                                            "state": "RUNNING"
                                        }
                                    ];
                                    $findState := function($stateRaw) {
                                        (
                                        $result := $filter($stateMap, function($v) {
                                            ($stateRaw >= $v.lower and $stateRaw <= $v.upper)
                                        });
                                        $result ? $result[0].state : "ERROR"
                                        )
                                    };
                                    {
                                        "powerlevel": value,
                                        "state": $findState(value),
                                        "timestamp": timestamp
                                    }
                                )
                  publish:
                      topic: !sub '${Cybus::MqttRoot}/machine-state'
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cybus.io/1-8-0/documentation/services/service-commissioning-files/sample-service-commissioning-files/machine-utilization-example-multi-file-service-composition-modbus-tcp-+-influxdb-+-grafana-+-mss/machine-utilization-example-machine-connectivity.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
