Giter Site home page Giter Site logo

vhuynen / adeunis-dry-contacts-mailbox-lorawan Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 3.68 MB

This is the third version of the Mailbox Notifier project. This iteration utilizes a LoRaWAN Adeunis Dry Contacts device. The device is compatible with the LoRaWAN Helium Network and is particularly well-suited for outdoor use (IP68).

JavaScript 100.00%
adeunis helium-network iot-device lorawan mailbox home-assistant

adeunis-dry-contacts-mailbox-lorawan's Introduction

Adeunis-Dry-Contacts-Mailbox-LoRaWAN

This project utilizes a high-quality Adeunis Dry Contacts device, specifically designed for outdoor durability (IP68) as well as low power consumption and long battery life. Adeunis provides a straightforward yet efficient mobile application for configuring basic parameters such as APP_EUI, APP_KEK, and the behavior of the Dry Contacts. For more advanced LoRaWAN settings, you can communicate with the device using AT Commands.

Each Dry Contacts unit can operate in either event mode or periodic mode. In event mode, the device sends a data frame as soon as an event is triggered, adhering to the fair use policy. Conversely, in periodic mode, it counts events across all interfaces during a predefined time frame and transmits the data.

In other words, this module gathers all the requirements I need for this project.

Table of Contents

Architecture Schema

architecture

This architecure can be described like this :

  • Helium Gateway and Data Retrieval:

    • A Helium Gateway collects data frames from connected devices. These gateways use the LongFi network, which combines the LoRaWAN wireless protocol with Helium Blockchain. This allows any LoRaWAN-compatible device to transfer data.
    • It then forwards these frames to the respective Helium accounts associated with each device.
  • Data Decoding and AWS Integration:

    • In the Helium console, the received data frames are decoded. This process converts the raw data into a JSON format.
    • The decoded data is then forwarded to AWS IoT Core using an MQTT Integration between Helium and your AWS Account.
  • MQTT Topic and MQTT Bridge:

    • Within AWS IoT Core, a rule is configured to route incoming messages to a specific MQTT topic.
    • This MQTT Topic is consumed by an MQTT Bridge, which is hosted on your on-premises Home Assistant. The MQTT Bridge acts as a bridge between the cloud-based AWS IoT Core and your local Home Assistant setup.
  • Node-RED Flow and Custom Logic:

    • Finally, the messages received by the MQTT Bridge are processed by a Node-RED Flow.
    • The Node-RED Flow analyzes each data frame and performs custom logic based on your specific requirements. In my own projects, I send notifications via SMS and Telegram, announce events using Text-to-Speech through Alexa, and update certain entities to visualize them on a custom button in Home Assistant.

This architecture allows you to collect, decode, and process data from connected devices using Helium, AWS IoT Core, MQTT, and Node-RED.

Electic Schema

Two normally closed reed switches are used to detect if a door has been opened. The magnets attached to the doors keep the switches open when the doors are closed. When a door is opened, the respective switch closes the circuit, and the rising signal wakes up the device that sends the event to the LoRaWAN Gateway. The unit TOR 1 is used for the flip door, and the TOR 2 is used for the main door.

electric

Configuration

Helium Console

Register the device

First, you need to add a new device to your Helium account. Then, override the Device EUI value with the number printed on the label of the device casing. You will have to wait for your device to be recorded into the blockchain before attempting to join the network. This operation can take up to 20 minutes.

Decoder Function

Adeunis provides JavaScript libraries to decode all raw data in JSON format for all of these products. A simple adaptation was needed to be compatible with Helium's JavaScript decoder function.

Moreover, an online tool allows you to decode the raw data: Codec Adeunis Decoder 🚀

Flows

You will need to forward the data from the mailbox to AWS Integration.

flows

Adeunis Dry Contacts V1

Network Settings

Configuring the device is straightforward. The IoT Configurator tool from Adeunis simplifies the process of setting up essential network parameters for joining the LoRa network. Here are the steps:

  • Connect the transmitter via USB to the IoT Configurator application.
  • Access the ‘Network Configuration’ menu within the tool.
  • Set the mode of activation at OTAA.
  • Set the APP_EUI and APP_KEY properties provided by the Helium console.
  • Save the configuration.
  • Unplug the USB cable.
  • The device will then attempt to join the network.

For the remaining network settings, I have enabled ADR (Adaptive Data Rate) and set the duty cycle to ON.

❗ Unfortunately, it is not possible to change the Spread Factor (SF) because, by design, the property is read-only.

Application Settings

Below, the details of the application's principal registers:

Register Description Value Comment
S300 Transmission period of the Keep Alive frame 144 144 x 10min = 1444min (Every 24 hours)
S306 Global operation 1 PRODUCTION MODE
S320 Input TOR1 configuration 0x34 - Event mode
- Detection of high edges only
- Debounce period of 50ms
S321 Input TOR2 configuration 0x34 - Event mode
- Detection of high edges only
- Debounce period of 50ms
S322 Input TOR3 configuration 0x00 Disabled
S323 Input TOR4 configuration 0x00 Disabled

The I/O interfaces TOR1 and TOR2 are configured to transmit a data frame when the signal rises, with a debounce period of 50 ms.

AWS

In order to retrieve data from Helium to Home Assistant through an MQTT Bridge with AWS IoT Core, I advise you to read this post that I wrote a while ago : Helium-Network-AWS-IoT-Core-Home-Assistant.

IoT Rule

It will be necessary to add a rule to republish messages from Helium to Home Assistant through the MQTT Bridge :

  • First, select all content from Helium :
SELECT * FROM 'topic/gateway' where dev_eui = '0018BXXXXXXXXXXX'
  • Finnaly, repost the message in the Topic dedicated to the mailbox :

arn:aws:iot:<region>:<account>:thing/Home_Assistant/outdoor/mailbox

Home Assistant

Four entities have been added to handle the mailbox behavior within Home Assistant. :

Name Type Comment
mailbox_present input_boolean true if a letter or parcel has been delivered, false when the mailbox has been emptied.
mailbox_arrived input_datetime The current datetime is recorded when something is deposited in the mailbox.
mailbox_keep_alive input_boolean The entity is set to true when a keep-alive frame is received.
mailbox_status input_boolean The entity is set to false when a hardware or low battery issue has been detected.

Node-Red

Each data frame retrieved from Helium via IoT Core is performed by a specific Node-Red flow. You can customize the flow according to your own needs.

mailbox-nore-red-flow

Dry Contacts Data - Frame 0x40

The join-wait node allows detection of whether the flip door and the main door have been opened successively. The join-wait node waits for 60 seconds each time it receives a message. If it receives two different messages within 60 seconds, it is likely that you have emptied your mailbox. If the countdown expires, then you have received a letter or a parcel.

Based on the output of the join-wait node, the flow updates the state of the mailbox_present entity (true or false) and the timestamp of the mailbox_arrived entity if you have received something. Afterward, a Telegram message is sent to notify you of what is going on.

Keep Alive - Frame 0x30

The Dry contact is configured to send a healty report at Home Assistant every 24 hours (1440 mins) :

  • When a frame is received, the mailbox_keep_alive entity is set to true, and a countdown of 1438 minutes is triggered to set the entity to false just a few minutes before the next Keep Alive frame. This allows us to detect if the module is still alive. This tip allows for updating the entity every day, as Home Assistant doesn’t update the last_changed attribute of the entity if the state remains the same.

  • When a the frame is received, the mailbox_status entity is set to false. If the payload contains any issues (hardware or low battery), then the entity is set to true indicating trouble with the module. If an issue is detected, a health report is sent via Telegram.

Dashboard

A custom button allows you to quickly view the state of the mailbox. The heart pulse icon allows you to check that the module is still functioning since the last 24 hours, and the battery icon allows you to verify that there are no hardware or battery issues.

Below, the visual of the custom button :

No Mail Mail Arrived
flows flows

3D Printer support

In order to prevent creating holes in my mailbox, I have modeled a magnetic 3D support.

References

If you appreciate this project, please don’t hesitate to star ⭐ it and feel free to provide your feedback !

adeunis-dry-contacts-mailbox-lorawan's People

Contributors

vhuynen avatar

Stargazers

 avatar

Watchers

 avatar

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.