monitor_spot_app_cue
that retrieves and displays data from the Queue App (App_CUE).This is the multi-page printable view of this section. Click here to print...
Retrieve Data from Queue App
monitor_spot_app_cue
that retrieves and displays data from the Queue App1 - Get Data from the Queue App
monitor_spot_app_cue
that obtains and displays data from the Queue App (App_CUE).Location of the Sample Sketch
If you have installed the MWings library, you can open the sketch from Arduino IDE by selecting File -> Examples -> MWings -> TWELITE SPOT -> Receive -> monitor_spot_app_cue.

Example of the Save Location Display
Sketch
Below is the source code.
// Monitor example for TWELITE SPOT: Receive data from App_CUE (CUE Mode)
#include <Arduino.h>
#include "MWings.h"
const int RST_PIN = 5;
const int PRG_PIN = 4;
const int LED_PIN = 18;
const int8_t RX1_PIN = 16;
const int8_t TX1_PIN = 17;
const uint8_t TWE_CHANNEL = 18;
const uint32_t TWE_APP_ID = 0x67720102;
void printAccelEvent(const uint8_t event);
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_CUE (CUE Mode)");
Serial2.begin(115200, SERIAL_8N1, RX1_PIN, TX1_PIN);
// 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_CUE
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
}
void loop()
{
// Update TWELITE
Twelite.update();
}
void printAccelEvent(const uint8_t event)
{
switch (event) {
case 0x01: { Serial.print("Dice (1)"); break; }
case 0x02: { Serial.print("Dice (2)"); break; }
case 0x03: { Serial.print("Dice (3)"); break; }
case 0x04: { Serial.print("Dice (4)"); break; }
case 0x05: { Serial.print("Dice (5)"); break; }
case 0x06: { Serial.print("Dice (6)"); break; }
case 0x08: { Serial.print("Shake"); break; }
case 0x10: { Serial.print("Move"); break; }
default: break;
}
Serial.println("");
}
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"
Pin Number Definitions
Lines 6-11 define the pin numbers.
const int RST_PIN = 5;
const int PRG_PIN = 4;
const int LED_PIN = 18;
const int8_t RX1_PIN = 16;
const int8_t TX1_PIN = 17;
Name | Description |
---|---|
RST_PIN | Pin number connected to the TWELITE RST pin |
PRG_PIN | Pin number connected to the TWELITE PRG pin |
LED_PIN | Pin number connected to the ESP32 onboard LED on the board |
RX1_PIN | Pin number connected to the TWELITE RX1 pin |
TX1_PIN | Pin number connected to the TWELITE TX1 pin |
TWELITE Configuration Definitions
Lines 13-14 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;
Name | Description |
---|---|
TWE_CHANNEL | TWELITE frequency channel |
TWE_APP_ID | TWELITE application ID |
Serial Port Settings
Lines 22-24 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_CUE (CUE Mode)");
Serial2.begin(115200);
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. This also uses a baud rate of 115200
bps to match the initial setting of the TWELITE parent device.
TWELITE Settings
Lines 27-29 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 the Packet Reception Event
Lines 32-52 call Twelite.on()
to register the processing to be performed on the received data.
Here, the contents of the received packet are output to the serial monitor.
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
The above event is called only when a packet from the Queue App (TWELITE CUE mode) is received.
The contents of the received packet are stored in the argument packet
of type ParsedAppCuePacket
.
Message Contents
Message | Description |
---|---|
Packet Number | Packet sequence number |
Source Logical ID | Logical device ID of the sending TWELITE |
LQI | Wireless communication quality (0–255) |
Supply Voltage | Power supply voltage (mV) |
Accel Event | Accelerometer sensor status |
Accel X Axis | X-axis acceleration (1st sample) |
Accel Y Axis | Y-axis acceleration (1st sample) |
Accel Z Axis | Z-axis acceleration (1st sample) |
Magnet State | Magnetic sensor status |
Accelerometer Sensor Status
The output accelerometer sensor statuses are as follows:
Dice (1)
-Dice (6)
Detected the dice face (orientation).Shake
Detected a shaking motion.Move
Detected a slow movement.
Magnetic Sensor Status
The output magnetic sensor statuses are as follows:
S-pole is getting closer
Newly detected the S pole of a magnet.N-pole is getting closer
Newly detected the N pole of a magnet.Leaving or Not found
Magnet not detected.S-pole is close (Periodic packet)
Detecting the S pole of a magnet.N-pole is close (Periodic packet)
Detecting the N pole of a magnet.Not found (Periodic packet)
Magnet not continuously detected (periodic packet).
Updating TWELITE Data
Line 58 calls Twelite.update()
.
Twelite.update();
2 - Acquiring Data from the Queue App
monitor_spot_app_cue
that acquires and displays data from the Queue App (App_CUE).Location of the Sample Sketch
If you have installed the MWings library, you can open the sketch from Arduino IDE by navigating to File -> Examples -> MWings -> monitor_spot_app_cue.

Location
Sketch
Below is the main source code.
// Monitor example for TWELITE SPOT: Receive data from App_CUE (CUE 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 printAccelEvent(const uint8_t event);
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_CUE (CUE Mode)");
Serial2.begin(115200);
// 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_CUE
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
}
void loop()
{
// Update TWELITE
Twelite.update();
}
void printAccelEvent(const uint8_t event)
{
switch (event) {
case 0x01: { Serial.print("Dice (1)"); break; }
case 0x02: { Serial.print("Dice (2)"); break; }
case 0x03: { Serial.print("Dice (3)"); break; }
case 0x04: { Serial.print("Dice (4)"); break; }
case 0x05: { Serial.print("Dice (5)"); break; }
case 0x06: { Serial.print("Dice (6)"); break; }
case 0x08: { Serial.print("Shake"); break; }
case 0x10: { Serial.print("Move"); break; }
default: break;
}
Serial.println("");
}
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"
Pin Number Definitions
Lines 6-8 define the pin numbers.
const int RST_PIN = 5;
const int PRG_PIN = 4;
const int LED_PIN = 18;
Name | Description |
---|---|
RST_PIN | Pin number connected to the TWELITE RST pin |
PRG_PIN | Pin number connected to the TWELITE PRG pin |
LED_PIN | Pin number connected to the ESP32 onboard LED |
TWELITE Configuration Definitions
Lines 10-11 define the settings applied to the TWELITE parent device installed on the TWELITE SPOT.
const uint8_t TWE_CHANNEL = 18;
const uint32_t TWE_APP_ID = 0x67720102;
Name | Description |
---|---|
TWE_CHANNEL | TWELITE frequency channel |
TWE_APP_ID | TWELITE application ID |
Serial Port Settings
Lines 19-21 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_CUE (CUE Mode)");
Serial2.begin(115200);
Serial
is used for communication with the Arduino IDE 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. This also uses a baud rate of 115200
bps to match the initial TWELITE parent device settings.
TWELITE Settings
Lines 24-26 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 the Packet Reception Event
Lines 29-49 call Twelite.on()
to register the processing to be done for the received data.
Here, the contents of the received packet are output to the serial monitor.
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
The above event is called only when a packet is received from the Queue App (TWELITE CUE mode).
The contents of the received packet are stored in the argument packet
of type ParsedAppCuePacket
.
Message Contents
Message | Description |
---|---|
Packet Number | Packet sequence number |
Source Logical ID | Logical device ID of the sending TWELITE |
LQI | Wireless communication quality (0–255) |
Supply Voltage | Supply voltage (mV) |
Accel Event | Accelerometer sensor state |
Accel X Axis | X-axis acceleration (1st sample) |
Accel Y Axis | Y-axis acceleration (1st sample) |
Accel Z Axis | Z-axis acceleration (1st sample) |
Magnet State | Magnetic sensor state |
Accelerometer Sensor State
The output accelerometer sensor states are as follows:
Dice (1)
-Dice (6)
: Detected dice face (orientation).Shake
: Detected shaking motion.Move
: Detected slow movement.
Magnetic Sensor State
The output magnetic sensor states are as follows:
S-pole is getting closer
: Newly detected magnetic S-pole.N-pole is getting closer
: Newly detected magnetic N-pole.Leaving or Not found
: No magnet detected.S-pole is close (Periodic packet)
: Magnetic S-pole is detected.N-pole is close (Periodic packet)
: Magnetic N-pole is detected.Not found (Periodic packet)
: Magnet not detected continuously (periodic packet).
Updating TWELITE Data
Line 55 calls Twelite.update()
.
Twelite.update();
3 - Retrieve Data from Queue App
monitor_spot_app_cue
for retrieving and displaying data from the Queue App (App_CUE).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_cue.

Example of the location display
Sketch
Below is the main source code.
// Monitor example for TWELITE SPOT: Receive data from App_CUE (CUE 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 printAccelEvent(const uint8_t event);
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_CUE (CUE Mode)");
Serial2.begin(115200);
// 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_CUE
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
}
void loop()
{
// Update TWELITE
Twelite.update();
}
void printAccelEvent(const uint8_t event)
{
switch (event) {
case 0x01: { Serial.print("Dice (1)"); break; }
case 0x02: { Serial.print("Dice (2)"); break; }
case 0x03: { Serial.print("Dice (3)"); break; }
case 0x04: { Serial.print("Dice (4)"); break; }
case 0x05: { Serial.print("Dice (5)"); break; }
case 0x06: { Serial.print("Dice (6)"); break; }
case 0x08: { Serial.print("Shake"); break; }
case 0x10: { Serial.print("Move"); break; }
default: break;
}
Serial.println("");
}
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;
Name | Description |
---|---|
RST_PIN | Pin number connected to the RST pin of TWELITE |
PRG_PIN | Pin number connected to the PRG pin of TWELITE |
LED_PIN | Pin number connected to the ESP32 onboard LED |
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;
Name | Description |
---|---|
TWE_CHANNEL | TWELITE frequency channel |
TWE_APP_ID | TWELITE application ID |
Serial Port Setup
Lines 19-21 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_CUE (CUE Mode)");
Serial2.begin(115200);
Serial
is used for communication with the Arduino IDE 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. This is also set to 115200
bps to match the initial settings of the TWELITE parent device.
TWELITE Configuration
Lines 24-26 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 Packet Reception Event
Lines 29-49 call Twelite.on()
to register the processing to be performed on the received data.
Here, the contents of the received packet are output to the serial monitor.
Twelite.on([](const ParsedAppCuePacket& 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("Accel Event: ");
printAccelEvent(packet.u8AccelEvent);
Serial.print("Accel X Axis [0]: ");
Serial.print(packet.i16SamplesX[0], DEC); Serial.println(" mG");
Serial.print("Accel Y Axis [0]: ");
Serial.print(packet.i16SamplesY[0], DEC); Serial.println(" mG");
Serial.print("Accel Z Axis [0]: ");
Serial.print(packet.i16SamplesZ[0], DEC); Serial.println(" mG");
Serial.print("Magnet State: ");
printMagnetState(packet.u8MagnetState, packet.bMagnetStateChanged);
});
The above event is called only when a packet is received from the Queue App (TWELITE CUE Mode).
The contents of the received packet are stored in the argument packet
of type ParsedAppCuePacket
.
Message Contents
Message | Description |
---|---|
Packet Number | Packet sequence number |
Source Logical ID | Logical device ID of the sending TWELITE |
LQI | Wireless communication quality (0-255) |
Supply Voltage | Power supply voltage (mV) |
Accel Event | Accelerometer sensor status |
Accel X Axis | X-axis acceleration (1st sample) |
Accel Y Axis | Y-axis acceleration (1st sample) |
Accel Z Axis | Z-axis acceleration (1st sample) |
Magnet State | Magnetic sensor status |
Accelerometer Sensor Status
The accelerometer sensor status output is as follows:
Dice (1)
-Dice (6)
Detected dice face (orientation).Shake
Detected shaking movement.Move
Detected slow movement.
Magnetic Sensor Status
The magnetic sensor status output is 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 was 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 has not been continuously detected (periodic packet).
Updating TWELITE Data
Line 55 calls Twelite.update()
.
Twelite.update();