per25 / P1-HAN-port-with-lora

MIT License
2 stars 0 forks source link

P1-HAN-port-with-lora

Background

In recent years, the technology for reading data from home electrical meters has significantly evolved. A multitude of commercial products are now available, offering real-time data capture capabilities from these meters. These products range in complexity: some are basic, designed to transmit data to an online interface through Wi-Fi, while others are more sophisticated, using meter data to optimize tasks like load balancing for electric car chargers. Simultaneously, the rise of do-it-yourself (DIY) solutions has empowered homeowners to take a more hands-on approach. These DIY methods vary, from transmitting data over Wi-Fi to integrating with home automation systems like Home Assistant, enabling a more efficient and responsive home environment.

Despite these advancements, a critical limitation remains: the dependence on Wi-Fi for wireless data transmission. This reliance presents challenges, particularly in areas with poor or no Wi-Fi connectivity, limiting the scope of installation and use of such metering systems. Recognizing these issues, there is a clear need for an alternative solution that offers reliability and broader applicability in various environments.

To address these challenges we devoloped this project with Lora(Long Range) technology. This project uses an ESP32 microcontroller and the ESP-IDF extension which is built on a real-time operating system (RTOS) to measure electricity consumption through the Han/P1 port. The collected data will be displayed on the built-in 0.96 inch OLED Display and transmitted using LoRaWAN to TTN and then to datacake.

About the project

This project is implemented in the C/C++ programming languages, offering a balance of performance and efficiency. The real-time capabilities provided by FreeRTOS ensure accurate and timely measurements, crucial for monitoring electricity consumption. The integration of LoRaWAN technology enables wireless communication, allowing users to remotely access and manage data through platforms like TTN and Datacake. The project showcases a comprehensive solution for smart metering, combining hardware components, software development with ESP-IDF, and wireless communication through LoRaWAN. This project empowers users to actively monitor and optimize their electricity usage in a user-friendly and efficient manner.

The project is built for the AIDON 6000-serie electricity meter, more specifically the AIDON 6534 which is a 3-phase energy service device for households. Link to AIDON meters: Smart Energy Service Devices by Aidon (Note!, it should work for other meters with the same specifications. It is not tested woth other meters so we can not guarantee it!)

The idea with the project is that there should be an open-source project to read data from the meter and send the data with lorawan that is reasonably easy for others to download and use, or to be inspired of for their own project. This project was a bit challening to build because it did not exist any open-source project for data-readings with LoraWAN. For a person with intrests in IoT(Internet of Things), embedded systems and software in general this project will be easy to understand and use. Hopefully it will be fairly easy for a person with less experince in this field too.

To understand the data from the meter, check this: Meter data: content of the data. This explains the data, which is needed to understand what content of the data to read. In this project we read how much Watt's are used in real-time and the utility meter gives us this measurement every 10 seconds.

This project connets the device to TTN(The Things Network) and then has a webhook to Datacake to display the data, every software enthusiast has problay worked with TTN and Datacake before. We use them in this project for the simplicity, it is not too hard to connect your device.

Components of the project

Hardware Components

Hardware Connection

Wire connection

Software Components

Necessary Installations & How to run the project

Payload decoders needed on TTN and Datacake

Payload decoder for TTN

function decodeUplink(input) {
  // Check if input.bytes has at least 4 bytes
  if (input.bytes.length < 4) {
    return {
      data: {},
      warnings: [],
      errors: ["Input does not contain enough bytes"]
    };
  }

  // Convert the first 4 bytes of the array to a 32-bit unsigned integer
  var uint32 = (input.bytes[0] << 24) | (input.bytes[1] << 16) | (input.bytes[2] << 8) | input.bytes[3];

  // Ensure the number is treated as unsigned
  var decimalNumber = uint32 >>> 0;

  return {
    data: {
      // Return the decimal number
      value: decimalNumber
    },
    warnings: [],
    errors: []
  };
}

Payload decoder for Datacake

function Decoder(payload, port) {
    var value = {};

    try {

        var uint32 = (payload[0] << 24) | (payload[1] << 16) | (payload[2] << 8) | payload[3];
        var decimalNumber = uint32 >>> 0;

        console.log(decimalNumber);
        value.WATT = decimalNumber

    } catch (e) {
        // Handle any decoding errors
        console.error("Error decoding payload:", e);
    }

    return value;
}