> 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/ressources-en/lorawan-gateway/third-party-sensor-decoders/nano-sensorics-ampsense.md).

# Nano Sensorics Ampsense

### Codec

{% code title="nano-sensorics-ampsense.codec" lineNumbers="true" expandable="true" %}

```js
function decodeUplink(input) {
  if(input.fPort === 10)
  {  
    var bytes = input.bytes
    return {
      data: {
            Date_time: calculateDateTime(bytes[0], bytes[1],bytes[2],bytes[3],bytes[4],bytes[5],bytes[6]),
            kWh_Imp:     (calculateInt(bytes[7], bytes[8], bytes[9] , bytes[10])/100),
            kWh_Exp:     (calculateInt(bytes[11], bytes[12], bytes[13], bytes[14])/100),
            kVarh_Imp:     (calculateInt(bytes[15], bytes[16], bytes[17], bytes[18])/100),
            kVarh_Exp:     (calculateInt(bytes[19], bytes[20], bytes[21], bytes[22])/100),    
            kVAh_Exp:    (calculateInt(bytes[23], bytes[24], bytes[25], bytes[26])/100),        
            I1_DMD:        calculate(bytes[27], bytes[28], bytes[29], bytes[30]),         
            I2_DMD:        calculate(bytes[31], bytes[32], bytes[33], bytes[34]),
            I3_DMD:        calculate(bytes[35], bytes[36], bytes[37], bytes[38]),            
            P_DMD:        calculate(bytes[39], bytes[40], bytes[41], bytes[42]),
            Q_DMD:        calculate(bytes[43], bytes[44], bytes[45], bytes[46]),    
            S_DMP:        calculate(bytes[47], bytes[48], bytes[49], bytes[50]),
            //TestDataBytes:  testDataBytes(bytes),
      },
      warnings: [],
      errors: []
    };
  }
  else
  {
    return {
      data: input.bytes,
      warnings: [],
      errors: []
    }; 
  }
}
 
function calculate(H1, H2, H3, H4){
 
    //var regex = /[0-9A-Fa-f]{8}/g;
 
    var data = new Uint8Array(4);
 
    data[0] = H4; 
 
    data[1] = H3; 
 
    data[2] = H2; 
 
    data[3] = H1; 
    
    var f32 = new Float32Array(data.buffer);
 
    var f32value = f32[0].toFixed(5);
 
    return f32value;
 
}
function calculateInt(H1, H2, H3, H4){
 
    //var regex = /[0-9A-Fa-f]{8}/g;
 
    var data = new Uint8Array(4);
 
    data[0] = H4; 
 
    data[1] = H3; 
 
    data[2] = H2; 
 
    data[3] = H1; 
    
    var f32 = new Int32Array(data.buffer);
 
    var f32value = f32[0].toFixed(5);
 
    return f32value;
 
}
 
function calculateDateTime(H1, H2, H3, H4, H5, H6, H7){
 
 
    var date;
    var HH1 = parseInt (H1);
    var HH2 = parseInt (H2);
    var HH3 = parseInt (H3);
    var HH4 = parseInt (H4);
    var HH5 = parseInt (H5);
    var HH6 = parseInt (H6);
    var HH7 = parseInt (H7);
    
    date_time = "" + HH2 + "-" + HH3 + "-" + HH4 + " " + HH5 + ":" + HH6 + ":" + HH7
    return date_time;
 
}
 
 
function testDataBytes (inputBytes) {
    var i = 0;
    var str = "";
    
    while (i < inputBytes.length) {
    
        y =  i + 1 ;
        strTmp = inputBytes[i];
        strTmp = strTmp.toString(16);
      str = str + " " + y  + "= "  + strTmp + "; ";        i++;
 
    }
    
    return str;
    
}

```

{% endcode %}

### Mapping

{% code title="nano-sensorics-ampsense.mapping.json" lineNumbers="true" expandable="true" %}

```json
{
  "uplink": {
    "fields": [
      {
        "name": "Date_time",
        "description": "Date and time",
        "data_type": "NUMBER",
        "numeric_type": "INT16",
        "access_mode": "R",
        "unit": "",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      },
      {
        "name": "kWh_Imp",
        "description": "Imported energy",
        "data_type": "NUMBER",
        "numeric_type": "INT16",
        "access_mode": "R",
        "unit": "kWh",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      },
      {
        "name": "kWh_Exp",
        "description": "Exported energy",
        "data_type": "NUMBER",
        "numeric_type": "INT16",
        "access_mode": "R",
        "unit": "kWh",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      },
      {
        "name": "kVarh_Imp",
        "description": "Imported active energy",
        "data_type": "NUMBER",
        "numeric_type": "INT16",
        "access_mode": "R",
        "unit": "kVarh",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      },
      {
        "name": "kVarh_Exp",
        "description": "Exported active energy",
        "data_type": "NUMBER",
        "numeric_type": "UINT16",
        "access_mode": "R",
        "unit": "kVarh",
        "protocol_specific": {
          "modbus": {
            "register_type": "input",
            "factor": 1
          }
        }
      },
      {
        "name": "kVAh_Exp",
        "description": "Exported reactive energy",
        "data_type": "NUMBER",
        "numeric_type": "INT16",
        "access_mode": "R",
        "unit": "kVAh",
        "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
          }
        }
      }
    ]
  },
  "config": {
    "fields": []}
  }
}
```

{% 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/ressources-en/lorawan-gateway/third-party-sensor-decoders/nano-sensorics-ampsense.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.
