> 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/eastron-sdm230mct-and-sdm630mct.md).

# Eastron SDM230MCT & SDM630MCT

{% hint style="info" %}
Les codecs et mappings suivants couvrent uniquement les SDM230MCT et SDM630MCT dans leurs configurations initiales.
{% endhint %}

## Eastron SDM230MCT

### Codec

{% code title="eastron-SDM230MCT-LoRa.codec.js" lineNumbers="true" expandable="true" %}

```js
// round a number to a set number of places whilst avoiding floating point precision errors
function epsilonRound(num, places) {
    return Math.round((num + Math.pow(2, -52)) * Math.pow(10, places)) / Math.pow(10, places);
}

// convert a byte to uint8
function bytesToUInt8(bytes) {
    return parseInt(bytes[0]);
}

// convert 2 bytes to a uint16
function bytesToUInt16(bytes) {
    console.log(bytes);
    var result = (bytes[0] << 8) | bytes[1];
    return parseInt(result);
}

// convert 4 bytes to a uint32
function bytesToUInt32(bytes) {
    var result = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
    return parseInt(result);
}

// convert 4 bytes to a float32
function bytesToFloat32(bytes) {
    var bits = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
    var sign = (bits >>> 31 === 0) ? 1.0 : -1.0;
    var e = bits >>> 23 & 0xff;
    var m = (e === 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
    var f = sign * m * Math.pow(2, e - 150);
    return parseFloat(f);
}

function decodeUplink(input) {

    var bytes = input.bytes;

    return {
        data: {
            serialNumber: bytesToUInt32(bytes.slice(0, 4)),
            totalEnergy: epsilonRound(bytesToFloat32(bytes.slice(6, 10)), 3) * 1000,
            voltage: epsilonRound(bytesToFloat32(bytes.slice(10, 14)), 3) * 1000,
            totalCurrent: epsilonRound(bytesToFloat32(bytes.slice(14, 18)), 3) * 1000,
            powerFactor: epsilonRound(bytesToFloat32(bytes.slice(18, 22)), 3) * 1000,
            frequency: epsilonRound(bytesToFloat32(bytes.slice(22, 26)), 3) * 1000
        }
    };
}
```

{% endcode %}

### Mapping

{% code title="eastron-SDM230MCT-LoRa.codec.mapping.json" lineNumbers="true" expandable="true" %}

```json
{
  "uplink":{
    "fields":[
      {
        "name":"serialNumber",
        "description":"Serial number",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"totalEnergy",
        "description":"Total energy",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"Wh",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"voltage",
        "description":"Voltage",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"mV",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"frequency",
        "description":"Frequency",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"0.001 Hz",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"powerFactor",
        "description":"Power factor",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"totalCurrent",
        "description":"Total current",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"mA",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "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 %}

## SDM630MCT

### Codec

{% code title="eastron-SDM630MCT-LoRa.codec.js" lineNumbers="true" expandable="true" %}

```js
// round a number to a set number of places whilst avoiding floating point precision errors
function epsilonRound(num, places) {
    return Math.round((num + Math.pow(2, -52)) * Math.pow(10, places)) / Math.pow(10, places);
}

// convert a byte to uint8
function bytesToUInt8(bytes) {
    return parseInt(bytes[0]);
}

// convert 2 bytes to a uint16
function bytesToUInt16(bytes) {
    console.log(bytes);
    var result = (bytes[0] << 8) | bytes[1];
    return parseInt(result);
}

// convert 4 bytes to a uint32
function bytesToUInt32(bytes) {
    var result = (bytes[0] << 24) | (bytes[1] << 16) | (bytes[2] << 8) | bytes[3];
    return parseInt(result);
}

// convert 4 bytes to a float32
function bytesToFloat32(bytes) {
    var bits = bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3];
    var sign = (bits >>> 31 === 0) ? 1.0 : -1.0;
    var e = bits >>> 23 & 0xff;
    var m = (e === 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
    var f = sign * m * Math.pow(2, e - 150);
    return parseFloat(f);
}

function decodeUplink(input) {

    var bytes = input.bytes;

    return {
        data: {
            serialNumber: bytesToUInt32(bytes.slice(0, 4)),
            totalEnergy: epsilonRound(bytesToFloat32(bytes.slice(6, 10)), 3) * 1000,
            frequency: epsilonRound(bytesToFloat32(bytes.slice(10, 14)), 3) * 1000,
            totalPowerFactor: epsilonRound(bytesToFloat32(bytes.slice(14, 18)), 3) * 1000,
            maxTotalSystemPowerDemand: epsilonRound(bytesToFloat32(bytes.slice(18, 22)), 3) * 1000,
            totalCurrent: epsilonRound(bytesToFloat32(bytes.slice(22, 26)), 3) * 1000
        }
    };
}
```

{% endcode %}

### Mapping

{% code title="eastron-SDM630MCT-LoRa.codec.mapping.json" lineNumbers="true" expandable="true" %}

```json
{
  "uplink":{
    "fields":[
      {
        "name":"serialNumber",
        "description":"Serial number",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"totalEnergy",
        "description":"Total energy",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"Wh",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"frequency",
        "description":"Frequency",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"0.001 Hz",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"totalPowerFactor",
        "description":"Total power factor",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"maxTotalSystemPowerDemand",
        "description":"Maximum Total System Power Demand",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"mW",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "factor":1
          }
        }
      },
      {
        "name":"totalCurrent",
        "description":"Total current",
        "data_type":"NUMBER",
        "numeric_type":"UINT32",
        "access_mode":"R",
        "unit":"mA",
        "protocol_specific":{
          "modbus":{
            "register_type":"input",
            "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/eastron-sdm230mct-and-sdm630mct.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.
