Copyright Micropelt

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Milesight Codec Uplink Decoder

function Decode(fPort, bytes) {
  switch (fPort) {
    case 1:
      {
        var output = {};

        output.DEV_EUI = LoRaObject.devEUI;
        output.RSSI = LoRaObject.rxInfo[0].rssi;
        output.SNR = LoRaObject.rxInfo[0].loRaSNR;
        output.Data = LoRaObject.data;
        output.ADR = LoRaObject.txInfo.adr;
        output.coderate = LoRaObject.txInfo.codeRate;
        output.FCnt = LoRaObject.fCnt;
        output.Port = LoRaObject.fPort;
        output.Frequency = LoRaObject.txInfo.frequency;
        output.Modulation = LoRaObject.txInfo.dataRate.modulation;
        output.Bandwidth = LoRaObject.txInfo.dataRate.bandwidth;
        output.SpreadingFactor = LoRaObject.txInfo.dataRate.spreadFactor;

        output.Current_Valve_Position = bytes[0];
        output.Flow_Sensor_Raw = bytes[1] * 0.5;
        output.Flow_Temperature = bytes[2] * 0.5;
        output.Ambient_Sensor_Raw = bytes[3] * 0.25;
        output.Ambient_Temperature = bytes[4] * 0.25;
        output.Energy_Storage = bytes[5] >> 6 & 0x01;
        output.Harvesting_Active = bytes[5] >> 5 & 0x01;
        output.Ambient_Sensor_Failure = bytes[5] >> 4 & 0x01;
        output.Flow_Sensor_Failure = bytes[5] >> 3 & 0x01;
        output.Radio_Communication_Error = bytes[5] >> 2 & 0x01;
        output.Received_Signal_Strength = bytes[5] >> 1 & 0x01;
        output.Motor_Error = bytes[5] >> 0 & 0x01;
        output.Storage_Voltage = Number((bytes[6] * 0.02).toFixed(2));
        output.Average_Current_Consumed = bytes[7] * 10;
        output.Average_Current_Generated = bytes[8] * 10;
        output.Reference_Completed = bytes[9] >> 4 & 0x01;
        output.Operating_Mode = bytes[9] >> 7 & 0x01;
        output.Storage_Fully_Charged = bytes[9] >> 6 & 0x01;

        if (bytes.length === 11) {
          var um = bytes[9] & 0x03;
          var uv = (um === 0) ? bytes[10] : bytes[10] * 0.5;
          output.User_Mode = um;
          output.User_Value = uv;
        }

        return output;
      }
    default:
      return {
        errors: ['unknown FPort'],
      };
  }
}

Milesight Codec Downlink Encoder

function Encode(fPort, obj) 
{
  var encoded = [];

  if ("Valve_Position" in obj) {
    var new_vp = obj.Valve_Position;
    encoded = [new_vp,0x00,0x28,0x00,0x30,0x40];
  }

  if ("Set_Point_Ambient_Temperature" in obj) {
    var new_spt = (obj.Set_Point_Ambient_Temperature)*2;
    encoded = [new_spt,0x00,0x28,0x08,0x30,0x40];
  }

  return encoded;
}

  • No labels