This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

Retrieve Data from ARIA App

v1.1.3
    This is an explanation of the sample sketch monitor_spot_app_aria that retrieves and displays data from the ARIA app (App_ARIA).

    Location of the Sample Sketch

    If you have installed the MWings library, you can open the sketch from Arduino IDE via File -> Examples -> MWings -> TWELITE SPOT -> Receive -> monitor_spot_app_aria.

    Example of the location display

    Example of the location display

    Sketch

    Below is the main source code.

    // Monitor example for TWELITE SPOT: Receive data from App_ARIA (ARIA Mode)
    
    #include <Arduino.h>
    #include "MWings.h"
    
    const int RST_PIN = 5;
    const int PRG_PIN = 4;
    const int LED_PIN = 18;
    
    const uint8_t TWE_CHANNEL = 18;
    const uint32_t TWE_APP_ID = 0x67720102;
    
    void printMagnetState(const uint8_t state, const bool changed);
    
    void setup()
    {
        // Initialize serial ports
        Serial.begin(115200);
        Serial.println("Monitor example for TWELITE SPOT: App_ARIA (ARIA Mode)");
        Serial2.begin(115200, SERIAL_8N1);
    
        // Initialize TWELITE
        Twelite.begin(Serial2,
                      LED_PIN, RST_PIN, PRG_PIN,
                      TWE_CHANNEL, TWE_APP_ID);
    
        // Attach an event handler to process packets from App_ARIA
        Twelite.on([](const ParsedAppAriaPacket& packet) {
            Serial.println("");
            Serial.print("Packet Number:     #");
            Serial.println(packet.u16SequenceNumber, DEC);
            Serial.print("Source Logical ID: 0x");
            Serial.println(packet.u8SourceLogicalId, HEX);
            Serial.print("LQI:               ");
            Serial.println(packet.u8Lqi, DEC);
            Serial.print("Supply Voltage:    ");
            Serial.print(packet.u16SupplyVoltage, DEC); Serial.println(" mV");
            Serial.print("Air Temperature:   ");
            Serial.print(packet.i16Temp100x / 100.0f, 2); Serial.println(" C");
            Serial.print("Relative Humidity: ");
            Serial.print(packet.u16Humid100x / 100.0f, 2); Serial.println(" %");
            Serial.print("Magnet State:      ");
            printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
        });
    }
    
    void loop()
    {
        // Update TWELITE
        Twelite.update();
    }
    
    void printMagnetState(const uint8_t state, const bool changed)
    {
        if (changed) {
            switch (state) {
            case 0x0: { Serial.print("Leaving or not found"); break; }
            case 0x1: { Serial.print("N-pole is getting closer"); break; }
            case 0x2: { Serial.print("S-pole is getting closer"); break; }
            default: break;
            }
        } else {
            switch (state) {
            case 0x0: { Serial.print("Not found"); break; }
            case 0x1: { Serial.print("N-pole is close"); break; }
            case 0x2: { Serial.print("S-pole is close"); break; }
            default: break;
            }
            Serial.print(" (Periodic packet)");
        }
        Serial.println("");
    }

    Including the Library

    Line 4 includes the MWings library.

    #include "MWings.h"

    Defining Pin Numbers

    Lines 6-8 define the pin numbers.

    const int RST_PIN = 5;
    const int PRG_PIN = 4;
    const int LED_PIN = 18;
    NameDescription
    RST_PINPin number connected to the RST pin of TWELITE
    PRG_PINPin number connected to the PRG pin of TWELITE
    LED_PINPin number connected to the ESP32 LED on the board

    Defining TWELITE Settings

    Lines 10-11 define the settings applied to the TWELITE parent device mounted on the TWELITE SPOT.

    const uint8_t TWE_CHANNEL = 18;
    const uint32_t TWE_APP_ID = 0x67720102;
    NameDescription
    TWE_CHANNELTWELITE frequency channel
    TWE_APP_IDTWELITE application ID

    Serial Port Settings

    Lines 18-20 initialize the serial ports used and output a startup message to the serial monitor.

        Serial.begin(115200);
        Serial.println("Monitor example for TWELITE SPOT: App_ARIA (ARIA Mode)");
        Serial2.begin(115200, SERIAL_8N1);

    Serial is used for communication with the Arduino IDE’s serial monitor. The baud rate is set to 115200 bps to match the serial monitor settings.

    On the other hand, Serial2 is used for communication with the TWELITE parent device mounted on the TWELITE SPOT. The baud rate is also set to 115200 bps to match the initial settings of the TWELITE parent device.

    TWELITE Configuration

    Lines 23-25 call Twelite.begin() to configure and start the TWELITE parent device mounted on the TWELITE SPOT.

        Twelite.begin(Serial2,
                          LED_PIN, RST_PIN, PRG_PIN,
                          TWE_CHANNEL, TWE_APP_ID);

    Registering Event on Packet Reception

    Lines 28-44 call Twelite.on() to register the processing to be done on received data.

    Here, the contents of the received packet are output to the serial monitor.

        Twelite.on([](const ParsedAppAriaPacket& packet) {
            Serial.println("");
            Serial.print("Packet Number:     #");
            Serial.println(packet.u16SequenceNumber, DEC);
            Serial.print("Source Logical ID: 0x");
            Serial.println(packet.u8SourceLogicalId, HEX);
            Serial.print("LQI:               ");
            Serial.println(packet.u8Lqi, DEC);
            Serial.print("Supply Voltage:    ");
            Serial.print(packet.u16SupplyVoltage, DEC); Serial.println(" mV");
            Serial.print("Air Temperature:   ");
            Serial.print(packet.i16Temp100x / 100.0f, 2); Serial.println(" C");
            Serial.print("Relative Humidity: ");
            Serial.print(packet.u16Humid100x / 100.0f, 2); Serial.println(" %");
            Serial.print("Magnet State:      ");
            printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
        });

    The above event is called only when a packet is received from the ARIA app (TWELITE ARIA mode).

    The contents of the received packet are stored in the argument packet of type ParsedAppAriaPacket.

    Contents of the Messages

    MessageDescription
    Packet NumberPacket sequence number
    Source Logical IDLogical device ID of the sending TWELITE
    LQIWireless communication quality (0-255)
    Supply VoltagePower supply voltage (mV)
    Air TemperatureTemperature measured by TWELITE ARIA (°C)
    Relative HumidityRelative humidity measured by TWELITE ARIA (%)
    Magnet StateMagnetic sensor state
    Magnetic Sensor State

    The magnetic sensor states output are as follows:

    • S-pole is getting closer Newly detected S pole of the magnet.
    • N-pole is getting closer Newly detected N pole of the magnet.
    • Leaving or Not found Magnet not detected.
    • S-pole is close (Periodic packet) Magnet’s S pole is detected.
    • N-pole is close (Periodic packet) Magnet’s N pole is detected.
    • Not found (Periodic packet) Magnet not continuously detected (periodic packet).

    Updating TWELITE Data

    Line 50 calls Twelite.update().

        Twelite.update();