Skip to content
ELSYS
  • Webshop
  • About us
    • About us
    • News
    • Career
  • Products
    • All Sensors
    • LoRaWAN
      • ERS series LoRa
        • ERS LoRa
        • ERS Lite LoRa
        • ERS CO2 LoRa
        • ERS CO2 Lite LoRa
        • ERS VOC LoRa
        • ERS Eye LoRa
        • ERS Sound LoRa
      • ERS Display series LoRa
        • ERS Display LoRa
        • ERS Display CO2 LoRa
        • ERS Display Lite LoRa
        • ERS Display CO2 Lite LoRa
      • ERS Eco series LoRa
        • ERS Eco Lite LoRa
        • ERS Eco CO2 Lite LoRa
      • EMS series LoRa
        • EMS LoRa
        • EMS Lite LoRa
        • EMS Door LoRa
        • EMS Desk LoRa
      • ELT series LoRa
        • ELT LoRa
        • ELT Internal antenna
        • ELT Lite LoRa
        • ELT Ultrasonic LoRa
        • ELT Radar LoRa
    • NB-IoT/LTE-M
      • ERS series NB-IoT/LTE-M
        • ERS Lite NB-IoT/LTE-M
        • ERS CO2 NB-IoT/LTE-M
    • wM-Bus
      • ERS series wM-Bus
        • ERS Temp wM-Bus
  • Case Studies
  • Partners
  • Contact & Support
    • Contact Us
    • FAQ
    • Documents
    • Firmware
    • Battery Life Calculator
    • Sensor Payload Decoder
    • Downlink Generator
    • Sensor Settings – Application Help
    • Guides
      • TTN Guide

LoRa® Elsys Payload src

  • 2016-09-132016-10-18
  • by Peter Bjoerk
/*
  ______ _       _______     _______ 
 |  ____| |     / ____\ \   / / ____|
 | |__  | |    | (___  \ \_/ / (___  
 |  __| | |     \___ \  \   / \___ \ 
 | |____| |____ ____) |  | |  ____) |
 |______|______|_____/   |_| |_____/ 
 
  ELSYS simple payload decoder. 
  Use it as it is or remove the bugs
  www.elsys.se
  peter@elsys.se
*/
const TYPE_TEMP    	=0x01; //temp 2 bytes -3276.8°C -->3276.7°C
const TYPE_RH		=0x02; //Humidity 1 byte  0-100%
const TYPE_ACC		=0x03; //acceleration 3 bytes X,Y,Z -128 --> 127 +/-63=1G
const TYPE_LIGHT	=0x04; //Light 2 bytes 0-->65535 Lux
const TYPE_MOTION	=0x05; //No of motion 1 byte  0-255
const TYPE_CO2		=0x06; //Co2 2 bytes 0-65535 ppm 
const TYPE_VDD		=0x07; //VDD 2byte 0-65535mV
const TYPE_ANALOG1  =0x08; //VDD 2byte 0-65535mV
const TYPE_GPS      =0x09; //3bytes lat 3bytes long binary
const TYPE_PULSE1   =0x0A; //2bytes relative pulse count
function bin16dec(bin) {
    var num=bin&0xFFFF;
    if (0x8000 & num)
        num = - (0x010000 - num);
    return num;
}
function bin8dec(bin) {
    var num=bin&0xFF;
    if (0x80 & num) 
        num = - (0x0100 - num);
    return num;
}
function hexToBytes(hex) {
    for (var bytes = [], c = 0; c < hex.length; c += 2)
        bytes.push(parseInt(hex.substr(c, 2), 16));
    return bytes;
}
function DecodeElsysPayload(data){
    var obj = new Object();
    for(i=0;i<data.length;i++){
        console.log(data[i]);
        switch(data[i]){
            case TYPE_TEMP: //Temperature
                var temp=(data[i+1]<<8)|(data[i+2]);
                temp=bin16dec(temp);
                obj.temperature=temp;
                i+=2;
            break
            case TYPE_RH: //Humidity
                var rh=(data[i+1]);
                obj.humidity=rh;
                i+=1;
            break
            case TYPE_ACC: //Acceleration
                obj.x=bin8dec(data[i+1]);
                obj.y=bin8dec(data[i+2]);
                obj.z=bin8dec(data[i+3]);
                i+=3;
            break
            case TYPE_LIGHT: //Light
                var light=(data[i+1]<<8)|(data[i+2]);
                obj.light=light;
                i+=2;
            break
            case TYPE_MOTION: //Motion sensor(PIR)
                var motion=(data[i+1]);
                obj.motion=motion;
                i+=1;
            break
            case TYPE_CO2: //CO2
                var co2=(data[i+1]<<8)|(data[i+2]);
                obj.co2=co2;
                i+=2;
            break
            case TYPE_VDD: //Battery level
                var vdd=(data[i+1]<<8)|(data[i+2]);
                obj.vdd=vdd;
                i+=2;
            break
            case TYPE_ANALOG1: //Analog input 1
                var analog1=(data[i+1]<<8)|(data[i+2]);
                obj.analog1=analog1;
                i+=2;
            break
            case TYPE_GPS: //gps
                obj.lat=(data[i+1]<<16)|(data[i+2]<<8)|(data[i+3]);
                obj.long=(data[i+4]<<16)|(data[i+5]<<8)|(data[i+6]);
                i+=6;
            break
            case TYPE_PULSE1: //Pulse input 1
                var pulse1=(data[i+1]<<8)|(data[i+2]);
                obj.pulse1=pulse1;
                i+=2;
            break
        }
    }
    return obj;
}
$(function() {
    $("#convert").click(function() {
        console.log("click");
        var res=DecodeElsysPayload(hexToBytes($('#inputData').val()));
        var json=JSON.stringify(res,null,4);
        $('#result').html(json);
    });
});

 

LoRa® Elsys Payload
Programming kit
peter

Related articles

Badplatser_slim
Badplatser_desktop
ERS Sensors columns
Product series
NFC
Battery life calculator2
LoRaWAN Certified
mwc2019
Elsys downlink payload
Untitled

Firmware updates and news. Subscribe here.

Cookie policy
Privacy policy
© Elektroniksystem i Umeå AB 2024
Theme by Colorlib Powered by WordPress
  • Home
  • Product series
  • Webshop
  • Contact