Sidewalk: The IoT network from Amazon
08.05.2024
Elektronik | Funk | Software
Der Technik-Blog
Note: This decoder has been tested and checked with two smoke detectors. No warranty is given for possible errors or malfunctions.
The decoder was developed based on the payload documentation provided by the manufacturer. The script was tested with two smoke detectors in TTNs LoRaWAN network. In addition, the decoder always provides a Boolean value (smoke_detection) about a smoke alarm with True/False in addition to various status information.
/** * Decoder for Zenner smoke detector (Easy Protect Rauchwarnmelder RWM3) * More information: https://www.aeq-web.com/zenner-smoke-detector-rauch-warn-melder-3-payload-decoder/ * Version 1.2 */ function Decoder(bytes, port) { var packet = bytes[0]; var packetType = (packet >> 4) & 0x0F; var packetSubtype = packet & 0x0F; var smokeDetection = false; var packetMessage = "unkown"; if (packetType == 9) { if (packetSubtype == 2) { var firmwareVersion = "V" + bytes[4] + "." + bytes[3] + "." + bytes[2] var lorawanVersion = "V" + bytes[7] + "." + bytes[6] + "." + bytes[5] var lorawanCmdVersion = "V" + bytes[9] + "." + bytes[8] packetMessage = "SP9_02 (startup)"; return_data = { message: packetMessage, firmware_version: firmwareVersion, lorawan_version: lorawanVersion, lw_comand_version: lorawanCmdVersion, smoke_detection: smokeDetection } } else if (packetSubtype == 1 && (bytes[1] == convertToDec("CA") || bytes[1] == convertToDec("CE"))) { //LoRaWAN com. scenario if (bytes[1] == convertToDec("CA")) { packetMessage = "Smoke alarm via LoRaWAN is disabled"; } else if (bytes[1] == convertToDec("CE")) { packetMessage = "Smoke alarm via LoRaWAN is enabled"; } else { packetMessage = "unkown message"; } return_data = { message: packetMessage, smoke_detection: smokeDetection } } else if (packetSubtype == 1) { var dateTime = convertDateTime(bytes[4], bytes[3], bytes[2], bytes[1]); var statusCode = bytes[6] << 8 | bytes[5]; packetMessage = "SP9_01 (status)"; return_data = { message: packetMessage, datetime: dateTime, status: statusCode, smoke_detection: smokeDetection } } else { packetMessage = "SP9 (unkown subtype)"; return_data = { message: packetMessage, smoke_detection: smokeDetection } } } else if (packetType == 1) { var mValue = bytes[4] << 24 | bytes[3] << 16 | bytes[2] << 8 | bytes[1]; packetMessage = "SP1 (daily message)"; return_data = { message: packetMessage, value: mValue, smoke_detection: smokeDetection } } else if (packetType == convertToDec("A")) { var eventDate = convertDate(bytes[4], bytes[3]); if (bytes[1] == convertToDec(19)) { smokeDetection = true; packetMessage = "Smoke detection alarm"; } else if (bytes[1] == convertToDec(2)) { packetMessage = "Smoke detector removed from holder"; } else if (bytes[1] == convertToDec("1C")) { packetMessage = "Object close to the sensor"; } return_data = { message: packetMessage, date: eventDate, smoke_detection: smokeDetection } } else if (bytes[0] == convertToDec("FE") && bytes[1] == convertToDec(92)) { packetMessage = "Message via LoRaWAN will be sent when smoke detection triggers"; return_data = { message: packetMessage, smoke_detection: smokeDetection } } else { return_data = { error: "Packet type is unkown!" } } function convertToDec(b) { var return_value = parseInt(b, 16); return return_value; } function convertDate(b0, b1) { var day = "0" + (b1 & 0x1F); var mon = "0" + (b0 & 0x0F); var year = ((b1 & 0xE0) >> 5) | ((b0 & 0xF0) >> 1); var date = day.substr(-2) + "-" + mon.substr(-2) + "-20" + year; return date; } function convertDateTime(b0, b1, b2, b3) { var day = "0" + (b1 & 0x1F); var mon = "0" + (b0 & 0x0F); var year = ((b1 & 0xE0) >> 5) | ((b0 & 0xF0) >> 1); var hour = "0" + (b2 & 0x1F); var min = "0" + (b3 & 0x3F); var datetime = day.substr(-2) + "-" + mon.substr(-2) + "-20" + year + " " + hour.substr(-2) + ":" + min.substr(-2); return datetime; } return return_data }
The following payload data sets were recorded from a smoke detector and can be tested with the payload simulator at TTN:
Initial activation status packet:
921C001402020001200008FFFFFFFF0000Smoke detection alarm packet:
a01900ec29Query if alarm is also sent via LoRaWAN (DL: 91677E):
Smoke alarm feedback via LoRaWAN is on:
91ca00
Smoke alarm feedback via LoRaWAN is off:
91ce00
Feedback after activation of LoRaWAN alarm packet (DL: 92CE0064A1) :
FE92
Every day hundreds of meteorological radiosondes fall from the sky. In this article we convert a radiosonde into a GPS tracker for APRS, RTTY & CW
read moreTTN Payload Decoder for Zenner Easy Protect LoRaWAN Smoke Detector (RWM3)
read moreAEQ-WEB © 2015-2024 All Right Reserved