> For the complete documentation index, see [llms.txt](https://enless.gitbook.io/centre-aide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://enless.gitbook.io/centre-aide/ressources/gateway-lorawan/decodeurs-capteurs-tiers/watteco-fil-pilote.md).

# Watteco Fil Pilote

{% hint style="info" %}
Ce codec est minimaliste et ne permet que de gérer en lecture/écriture le mode du Fil Pilote.
{% endhint %}

La configuration du *report* (envoi périodique d'*uplink*) peut se faire en envoyant un *downlink* manuel. Plus d'informations ici : <https://support.watteco.com/pilote-wire-lora-remote/> (section "Frame examples").

## Codec

{% code title="watteco-fil\_pilote.codec.js" lineNumbers="true" expandable="true" %}

```js
// get endpoint number
function getFctrl(byte) {
    const mapping = {
        0x11: 0, 0x31: 1, 0x51: 2, 0x71: 3, 0x91: 4,
        0xB1: 5, 0xD1: 6, 0xF1: 7, 0x13: 8, 0x33: 9
    };

    if (mapping.hasOwnProperty(byte)) {
        return mapping[byte];
    }
    throw new Error("Unhandled Fctrl: Byte 0x" + byte.toString(16) + " not found in mapping.");
}

function decodeUplink(input) {

    if (!input || !input.bytes || input.bytes.length < 8) {
        throw new Error("Unhandled data: Payload too short or invalid");
    }

    const bytes = input.bytes;
    const fctrlSeq = getFctrl(bytes[0]);

    // Checking CmdID, ClusterID (16-bit), AttributeID (16-bit), and AttributeType
    const isStandardReport = 
        bytes[1] === 0x0a &&                     // CmdID: Report Attributes
        (bytes[2] << 8 | bytes[3]) === 0x0013 && // ClusterID: MultiState Output
        (bytes[4] << 8 | bytes[5]) === 0x0055 && // AttributeID: Present Value
        bytes[6] === 0x20;                       // Attribute Type: UINT8

    if (!isStandardReport) {
        throw new Error("Unhandled data: Frame structure does not match a standard Fil Pilote report");
    }

    const rawCode = bytes[7];
    const modes = {
        0x00: "Comfort [OFF]",
        0x01: "Economic [ON]",
        0x02: "AntiFreeze",
        0x03: "Stop",
        0x04: "Comfort -1°C",
        0x05: "Comfort -2°C"
    };

    if (!modes.hasOwnProperty(rawCode)) {
        throw new Error("Unhandled data: Unknown mode code 0x" + rawCode.toString(16));
    }

    return {
        data: {
            modeName: modes[rawCode],
            FilPiloteState: rawCode,
        }
    };
}

function encodeDownlink(input) {
    const bytes = [];

    if (!input || !input.data) {
        return { bytes, fPort: 125, warnings: [], errors: [] };
    }

    // avoid more than on for the moment
    if (input.data.length > 1) {
        return { bytes, fPort: 125, warnings: [], errors: ["too much data"] };
    }

    for (const key in input.data) {
        if (!input.data.hasOwnProperty(key)) continue;

        if (key === "setFilPiloteState") {
            bytes.push(0x11, 0x05, 0x00, 0x13, 0x00, 0x55, 0x20, input.data[key]);
        } 
        else if (key === "setMaxReportingInterval") {
            const interval = input.data[key];
            bytes.push(
                0x11, 0x06, 0x00, 0x13, 0x00, 0x00, 0x55, 0x20, 
                0x00, 0x0a, // min interval always 10 seconds
                (interval >> 8) & 0xFF, interval & 0xFF, // MSB, LSB : maxt interval in minutes
                0x01 // report on any change
            );
        }
    }

    return {
        bytes: bytes,
        fPort: 125,
        warnings: [],
        errors: [],
    };
}
```

{% endcode %}

## Mapping

{% code title="watteco-fil\_pilote.mapping.json" lineNumbers="true" expandable="true" %}

```json
{
  "uplink": {
    "fields": [
      {
        "name": "FilPiloteState",
        "description": "Present Fil Pilote state : 0 = comfort, 1 = Economic, 2 = antifreeze, 3 = Stop, 4 = Comfort -1°C, 5 = Comfort -2°C",
        "data_type": "NUMBER",
        "numeric_type": "UINT8",
        "access_mode": "R",
        "unit": "",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      }
    ]
  },
  "config": {
    "fields": [
      {
        "name": "setFilPiloteState",
        "description": "Set Fil Pilote state : 0 = comfort, 1 = Economic, 2 = antifreeze, 3 = Stop, 4 = Comfort -1°C, 5 = Comfort -2°C",
        "data_type": "NUMBER",
        "numeric_type": "UINT8",
        "access_mode": "R/W",
        "unit": "",
        "default_value": 1,
        "protocol_specific": {
          "modbus": { "register_type": "holding", "factor": 1 }
        }
      }
    ]
  },
  "lns_metadata":{
    "fields":[
      {
        "name":"rssi",
        "description":"Received RSSI",
        "data_type":"NUMBER",
        "numeric_type":"INT16",
        "access_mode":"R",
        "unit":"dBm",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "offset":1,
            "factor":1
          }
        }
      },
      {
        "name":"snr",
        "description":"Received SNR",
        "data_type":"NUMBER",
        "numeric_type":"INT16",
        "access_mode":"R",
        "unit":"dB",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "offset":2,
            "factor":1
          }
        }
      },
      {
        "name":"sf",
        "description":"Spreading Factor",
        "data_type":"NUMBER",
        "numeric_type":"UINT8",
        "access_mode":"R",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "offset":3,
            "factor":1
          }
        }
      },
      {
        "name":"minutesSinceLastRx",
        "description":"Minutes since last reception",
        "data_type":"NUMBER",
        "numeric_type":"UINT16",
        "access_mode":"R",
        "unit":"min",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "offset":4,
            "factor":1
          }
        }
      }
    ]
  }
}
```

{% 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://enless.gitbook.io/centre-aide/ressources/gateway-lorawan/decodeurs-capteurs-tiers/watteco-fil-pilote.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
