Git Product home page Git Product logo

sensordecoders's Issues

How do you handle the negative coordinates (south or west)

Hi,

In the specification you wrote the following: "If the device fails toget GNSSdata, the latitude or longitude will show FFFFFFFF."

Then how do you encode the negative coorinates (for example any south 0.000001° or west 0.000001° coordinates)?

It seems that the decoder in the following lines simply ignoring these "error" values and generating valid coordinates for the int -1 (FFFFFFFF) values.

else if ((channel_id === 0x04 || channel_id == 0x84) && channel_type === 0x88) {
decoded.latitude = readInt32LE(bytes.slice(i, i + 4)) / 1000000;
decoded.longitude = readInt32LE(bytes.slice(i + 4, i + 8)) / 1000000;
var status = bytes[i + 8];
decoded.motion_status = readMotionStatus(status & 0x0f);
decoded.geofence_status = readGeofenceStatus(status >> 4);
i += 9;
}

Or simply do not put any device to that 2 (~20 cm width, ~40.000 km long) circles? :)

UC511-DI-868M

I am trouble pulling the battery level from the device. I used the code as given here but only gets 4 values from the object.
data:"AwEABMgAAAAABQEABsgAAAAA"
objectJASON: 4keys{}
valve1:"off"
valve1_pulse:0
valve2:"off"
valve2_pulse:0

Please assist

UC50x decoder doesn't work in ChripStack v4

Hi there,

I tried to upload the codec from UC_Series/UC50x/UC50x_Decoder.js and it doesn't work instead it logs me out of ChirpStack.

Ended up having to clean the script to allow it to save into ChirpStack v4.

AM 107 decoder Error

Good day, GitHub community!

I hope everything is going well on your end.

I’ve been facing an issue with the AM107 Decoder function. Despite successfully running my decoder on a Lambda function and confirming data transfer (the uplink time is accurate), I can’t seem to retrieve accurate payload data.

I’m using an E-Link device to measure temperatures, and my goal is for the Lambda function to display the exact temperatures as shown on the E-Link device. I’ve followed the integration guide provided, (https://support.milesight-iot.com/support/solutions/articles/73000514172-aws-iot-core-for-lorawan-milesight-sensors-integration).

I would greatly appreciate any assistance or insights to achieve accurate data display from my Lambda function. I have attached screenshots for your reference and the Milesight IoT Am107 repo with the code (https://github.com/Milesight-IoT/SensorDecoders/blob/main/AM_Series/AM107/AM107_Decoder.js)

Thank you in advance!

image

import AWS from 'aws-sdk';
// import milesightDeviceDecode from "./decoder.js"

export const handler = (event, context, callback) => {
console.log("Event received:", event);

// Validate event.PayloadData
if (!event || !event.PayloadData) {
    console.error("Invalid event: PayloadData is missing or undefined.");
    callback(new TypeError("Invalid event: PayloadData is missing or undefined."));
    return;
}


try {
    var data = Buffer.from(event.PayloadData, 'base64');
    var chars = [...data];
    console.log("Decoded bytes:", chars);

    var params = decodeUplink(chars);
    console.log("Decoded parameters:", params);

    var iotdata = new AWS.IotData({ endpoint: '123456789-ats.iot.eu-west-1.amazonaws.com' });
    var response = {
        topic: event.WirelessMetadata.LoRaWAN.DevEui.concat("/project/sensor/decoded"),
        payload: JSON.stringify(params),
        qos: 0
    };

    console.log("Publishing to IoT topic:", response.topic);
    iotdata.publish(response, function(err, data) {
        if (err) {
            console.error("IoT publish error:", JSON.stringify(err));
            callback(err);
        } else {
            console.log("Published data:", response);
            callback(null, {
                statusCode: 200,
                body: JSON.stringify(params)
            });
        }
    });
} catch (error) {
    console.error("Error processing event:", error);
    callback(error);
}

};

function decodeUplink(input) {
// Validate input structure
if (!input || !Array.isArray(input)) {
throw new TypeError('Invalid input: input must be an array');
}

console.log("Input for decoding:", input);
var decoded = milesightDeviceDecode(input);
return { PayloadData: decoded };

}

function milesightDeviceDecode(bytes) {
var decoded = {};

for (var i = 0; i < bytes.length; ) {
    var channel_id = bytes[i++];
    var channel_type = bytes[i++];
    // BATTERY
    if (channel_id === 0x01 && channel_type === 0x75) {
        decoded.battery = bytes[i];
        i += 1;
    }
    // TEMPERATURE
    else if (channel_id === 0x03 && channel_type === 0x67) {
        // ℃
        decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
        i += 2;

        // ℉
        // decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10 * 1.8 + 32;
        // i +=2;
    }
    // HUMIDITY
    else if (channel_id === 0x04 && channel_type === 0x68) {
        decoded.humidity = bytes[i] / 2;
        i += 1;
    }
    // PIR
    else if (channel_id === 0x05 && channel_type === 0x6a) {
        decoded.activity = readUInt16LE(bytes.slice(i, i + 2));
        i += 2;
    }
    // LIGHT
    else if (channel_id === 0x06 && channel_type === 0x65) {
        decoded.illumination = readUInt16LE(bytes.slice(i, i + 2));
        decoded.infrared_and_visible = readUInt16LE(bytes.slice(i + 2, i + 4));
        decoded.infrared = readUInt16LE(bytes.slice(i + 4, i + 6));
        i += 6;
    }
    // CO2
    else if (channel_id === 0x07 && channel_type === 0x7d) {
        decoded.co2 = readUInt16LE(bytes.slice(i, i + 2));
        i += 2;
    }
    // TVOC
    else if (channel_id === 0x08 && channel_type === 0x7d) {
        decoded.tvoc = readUInt16LE(bytes.slice(i, i + 2));
        i += 2;
    }
    // PRESSURE
    else if (channel_id === 0x09 && channel_type === 0x73) {
        decoded.pressure = readUInt16LE(bytes.slice(i, i + 2)) / 10;
        i += 2;
    } else {
        break;
    }
}
console.log('Decoded data:', decoded);

return decoded;

}

function readUInt16LE(bytes) {
var value = (bytes[1] << 8) + bytes[0];
return value & 0xffff;
}

function readInt16LE(bytes) {
var ref = readUInt16LE(bytes);
return ref > 0x7fff ? ref - 0x10000 : ref;
}

How to decode the double precision floating point packet?

22fb20cb827a5c40: Little endian (little Endian), 0x405c7a82cb20fb22, the data is of double type, needs to be converted to floating point number, longitude value: 113.9142330000000 (dd.dddd format); (Double type, need change the data to Floating point)

21ea3e00a9953640: Little endian (little Endian), 0x403695a9003eea21, the data is of double type, needs to be converted to floating point number, longitude value: 22.5846100000000 (dd.dddd format); (Double type, need change the data to Floating point)

According to the IEEE 754 standard, a double precision float has the following structure:

1 bit for the sign
11 bits for the exponent
52 bits for the significand (mantissa)

I use this code, but it unable to decoded.

function hexArrayToDouble(hexArray) {
    var buffer = new ArrayBuffer(8);
    
    var uint8Array = new Uint8Array(buffer);
    for (var i = 0; i < hexArray.length; i++) {
    uint8Array[i] = hexArray[i];
    }
    
    var dataView = new DataView(buffer);
    var doubleValue = dataView.getFloat64(0, false);
    
    return doubleValue;
}
var hexArray = [0x40, 0x5c, 0x7a, 0x82, 0xcb, 0x20, 0xfb, 0x22];
var doubleValue = hexArrayToDouble(hexArray); //113.914233

Occurred Error:
js vm error: ReferenceError: 'ArrayBuffer' is not defined
js vm error: ReferenceError: 'Uint8Array' is not defined
js vm error: ReferenceError: 'DataView' is not defined

No Object for Port 0 on EM300-TH

Hi there,

My EM300 and UC300 are sending uplinks on fPort: 0

I'm getting an uplink with no object for fPort: 0 on UC300 EM300-TH , using the following decoder with the EM300-TH

Is there another decoder I should be using for this sensor or I'm not sure what the purpose for the Uplink is?

`/**

  • Payload Decoder for Chirpstack v4
  • Copyright 2024 Milesight IoT
  • @Product EM300-TH
    */
    function decodeUplink(input) {
    var decoded = milesight(input.bytes);
    return { data: decoded };
    }

function milesight(bytes) {
var decoded = {};

for (var i = 0; i < bytes.length; ) {
    var channel_id = bytes[i++];
    var channel_type = bytes[i++];

    // BATTERY
    if (channel_id === 0x01 && channel_type === 0x75) {
        decoded.battery = bytes[i];
        i += 1;
    }
    // TEMPERATURE
    else if (channel_id === 0x03 && channel_type === 0x67) {
        // ℃
        decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10;
        i += 2;

        // ℉
        // decoded.temperature = readInt16LE(bytes.slice(i, i + 2)) / 10 * 1.8 + 32;
        // i +=2;
    }
    // HUMIDITY
    else if (channel_id === 0x04 && channel_type === 0x68) {
        decoded.humidity = bytes[i] / 2;
        i += 1;
    }
    // TEMPERATURE & HUMIDITY HISTROY
    else if (channel_id === 0x20 && channel_type === 0xce) {
        var point = {};
        point.timestamp = readUInt32LE(bytes.slice(i, i + 4));
        point.temperature = readInt16LE(bytes.slice(i + 4, i + 6)) / 10;
        point.humidity = bytes[i + 6] / 2;

        decoded.history = decoded.history || [];
        decoded.history.push(point);
        i += 8;
    } else {
        break;
    }
}

return decoded;

}

/* ******************************************

  • bytes to number
    ********************************************/
    function readUInt16LE(bytes) {
    var value = (bytes[1] << 8) + bytes[0];
    return value & 0xffff;
    }

function readInt16LE(bytes) {
var ref = readUInt16LE(bytes);
return ref > 0x7fff ? ref - 0x10000 : ref;
}

function readUInt32LE(bytes) {
var value = (bytes[3] << 24) + (bytes[2] << 16) + (bytes[1] << 8) + bytes[0];
return value & 0xffffffff;
}`

EM300 with hourly measurements keeps sending empty payload.

We have a thousands of units thats been configured to have an hourly measurement.

But the sensors keeps sending blank payloads 2 times every hour, and the measurement once an hour.
Measurements are sent on Port 85 as described in documentation.
However the blank payloads are sent on application port 0 and is nowhere to be found in documentation.

We are considered that this will cost battery lifetime.

  • Why is the sensor sending these empty payloads?
  • Will it cost battery lifetime?
  • If so, How is that turned off?

We do not see this type of behavior on other provider of sensors or in EM500.

image

UC511-DI-868M Battery Levels

The UC511-DI-868M controller sends the battery reading every 6 hours, as an integer value:

"battery":5,"valve1":"off","valve1_pulse":0,"valve2":"off","valve2_pulse":0	-	"2022-10-12 14:00:53"
"battery":5,"valve1":"off","valve1_pulse":0,"valve2":"off","valve2_pulse":0	-	"2022-10-12 20:20:32"
"battery":5,"valve1":"off","valve1_pulse":0,"valve2":"off","valve2_pulse":0	-	"2022-10-13 02:20:32"
"battery":0,"valve1":"on","valve1_pulse":0,"valve2":"off","valve2_pulse":0	-	"2022-10-13 08:20:31"

I assumed that the integer is the voltage, however after receiving the 0 value, the controller is still transmitting messages. Can you please share how to translate the battery levels from the integer (0, 5) to either a voltage, or percentage value?

UC51x decoder doesn't correctly handle unknown/new data items

The UC51x decoder is structured with if {} else if {} else if {} else break. We had a older decoder installed on ChirpStack and did not realize it. Newer UC51x v3 has new data items that the decoder does not recognize, which fall down to the break - meaning a single new data item in a payload stops decoding the remainder of the payload.

Suggest removing the 'else break' and just test for each known data item. Unknown/new data items (like in UC51x v4) should be ignored without terminating decoding.

Issue in UC-t11 code

Dears

I am trying the decoder function but in response, I am getting below error packet:

Error:”js vm error: ReferenceError: ‘Decode’ is not defined”,

Also I have noted that the sensor is not sending Battery information in the packet.

See the below packet details:

Payload(hex): 0167100102683f

AT101 payload and decoder incorrectly uses positive longitude for West

I'm located in California, near 38.169N and 122.137W. By convention, southern latitudes and western longitudes are given a negative sign, so this should be:

38.169, -122.137

However, the AT101 payload and decoded value shows 38.169, 122.137.

If I give this string to Google Maps, it shows the correct location in California:

image

However, the AT101 payload and decoded value shows 38.169, 122.137, which is in the sea between China and Korea:

image

Perhaps the decoder should multiply the longitude by -1 ?

Why are there separate Chirpstack (v3) and ChirpStack v4 decoders? Single decoder works

There's no need for two different decoders, especially since this creates the chance of error where the actual payload decoding does not match.

Chirpstack v3 calls this function:

// Decode decodes an array of bytes into an object.
//  - fPort contains the LoRaWAN fPort number
//  - bytes is an array of bytes, e.g. [225, 230, 255, 0]
//  - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string)
// The function must return an object, e.g. {"temperature": 22.5}
function Decode(fPort, bytes, variables) {
  return {};
}

Chirpstack v4 calls this function:

// Decode uplink function.
//
// Input is an object with the following fields:
// - bytes = Byte array containing the uplink payload, e.g. [255, 230, 255, 0]
// - fPort = Uplink fPort.
// - variables = Object containing the configured device variables.
//
// Output must be an object with the following fields:
// - data = Object representing the decoded payload.
function decodeUplink(input) {
  return {
    data: {
      temp: 22.5
    }
  };
}

A single decoder file may contain both functions, which call a single actual decoding code.
Thus a single file will serve for both v3 and v4, allowing MileSight to make changes to a single file and users to use a single file, preventing errors.

get devEUI inside the decoder

Hello,

I'm testing the UG56 GW, to get data from em300-DI sensors, with custom decoder (copied from this github repo).
My system/application receive the data through the MQTT interface in the gateway.

the issue is that the received MQTT message is the same as the decoder output which does not include the devEUI.
so my question, is there a way to read/know the devEUI within the decoder, so we can add it to the output message?

WT201 Decoder

Im looking for a decoder for WT201-915 Thermostat. Any chance any of the current WT101 TTN code will work?

Encoder for WT101

Can you please post the encoder for the WT101 to allow writing of target temperature, control mode and position?

Downlink Encoder

Hi there,

Is there a Downlink encoder?

My use case here is to SET the spreading factor on a EM320 via downlink, so just wondering if there is a spreadsheet template or similar to make a downlink.

Set via Lorawan

Good afternoon,

Could you tell me, is it possible to manage Milesight devices via Lorawan downlink?
For example Set Transmit Interval Time, Restart, Turn On/Off, rejoin interval

Thanks for any information.

TS30X Payload Definition doesnt fit with decoder

Hi,

Payload definition of TS30x doesn't say that "magnet_chn1_alarm" exists but in the decoder.js it does exist. (line 109)

line 108                    data.magnet_chn1 = readInt16LE(bytes.slice(i, i + 2)) === 0 ? "closed" : "opened";
line 109                    data.magnet_chn1_alarm = "threshold";
line 110                    break;

Is this correct or should this be a different property?

Problem decoding up messages in EM300DI

HI, we are integrating this EM300-DI device into Chirpstack 4.8.1, after loading the decode that you have published.

https://github.com/Milesight-IoT/SensorDecoders/blob/main/EM_Series/EM300_Series/EM300-DI/EM300-DI_Decoder.js

I have a configuration where the totalizer of a water meter is sent every minute.

And I get these error messages randomly due to decoding failure.
image

Here is an image of a UP that cannot decode
image

And here is an image of a UP that decodes correctly
image

EM-300-DI.log.json

I am attaching a more complete log where you can see UP messages correctly decoded and others that are not.

What could be happening?

thanks for your help

EM-300 payload without battery value?

As payload for the EM-300-TH sensor I am receiving:
0367AD00046873

Per the decoder in github, the temperature and humidity can be decoded, but it seems that the payloadstring lacks the battery value.

Is the payload format changed with firmware 1.2, so that battery is no longer a part of the payload?

Encoder for WT201

We are looking for the encoder for the WT201 to write data such as the temperature set point, fan speed and mode. Is there an encoder available Will the encore for the WT30x work?

CT101 decoder error...

Hi forum

I'm Using your CT101 decoder, but is not reporting Product Serial Number, Hardware version and firmware version. only i get

ipso_version:"v0.1"
power:"on"

Please, can you review the decoder to show all basic information ?

Sensor Data is reporting ok.

Best Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.