Skip to content

Commit bb1253d

Browse files
authored
Create matter_temp_sensor_sleep.ino
Matter sleep mode temperature sensor example
1 parent c51e6c0 commit bb1253d

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Matter sleep mode temperature sensor example
3+
4+
The example shows how to create a sleep mode temperature sensor with the Arduino Matter API.
5+
6+
The example creates a Matter temperature sensor device and publishes the current CPU temperature through it.
7+
It goes to sleep mode for 10 minutes.
8+
The device has to be commissioned to a Matter hub first.
9+
10+
Compatible boards:
11+
- Arduino Nano Matter
12+
- SparkFun Thing Plus MGM240P
13+
- xG24 Explorer Kit
14+
- xG24 Dev Kit
15+
- Seeed Studio XIAO MG24 (Sense)
16+
17+
Author: Tamas Jozsi (Silicon Labs)
18+
*/
19+
#include <Matter.h>
20+
#include <MatterTemperature.h>
21+
#include "ArduinoLowPower.h"
22+
23+
MatterTemperature matter_temp_sensor;
24+
25+
void setup()
26+
{
27+
Serial.begin(115200);
28+
Matter.begin();
29+
matter_temp_sensor.begin();
30+
31+
Serial.println("Matter temperature sensor");
32+
33+
if (!Matter.isDeviceCommissioned()) {
34+
Serial.println("Matter device is not commissioned");
35+
Serial.println("Commission it to your Matter hub with the manual pairing code or QR code");
36+
Serial.printf("Manual pairing code: %s\n", Matter.getManualPairingCode().c_str());
37+
Serial.printf("QR code URL: %s\n", Matter.getOnboardingQRCodeUrl().c_str());
38+
}
39+
while (!Matter.isDeviceCommissioned()) {
40+
delay(200);
41+
}
42+
43+
Serial.println("Waiting for Thread network...");
44+
while (!Matter.isDeviceThreadConnected()) {
45+
delay(200);
46+
}
47+
Serial.println("Connected to Thread network");
48+
49+
Serial.println("Waiting for Matter device discovery...");
50+
while (!matter_temp_sensor.is_online()) {
51+
delay(200);
52+
}
53+
Serial.println("Matter device is now online");
54+
}
55+
56+
void loop()
57+
{
58+
// Delay to operate after sleep mode exit
59+
delay(1000);
60+
float current_cpu_temp = getCPUTemp();
61+
matter_temp_sensor.set_measured_value_celsius(current_cpu_temp);
62+
Serial.printf("Current CPU temperature: %.02f C\n", current_cpu_temp);
63+
delay(2000);
64+
// Going to sleep mode for 10 minutes (600 s = 600.000 ms)
65+
LowPower.sleep(600000);
66+
}

0 commit comments

Comments
 (0)