|
1 | | -// Copyright 2024 Espressif Systems (Shanghai) PTE LTD |
2 | | -// |
3 | | -// Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | -// you may not use this file except in compliance with the License. |
5 | | -// You may obtain a copy of the License at |
6 | | - |
7 | | -// http://www.apache.org/licenses/LICENSE-2.0 |
8 | | -// |
9 | | -// Unless required by applicable law or agreed to in writing, software |
10 | | -// distributed under the License is distributed on an "AS IS" BASIS, |
11 | | -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | -// See the License for the specific language governing permissions and |
13 | | -// limitations under the License. |
14 | | - |
15 | | -/* |
16 | | - * This example is an example code that will create a Matter Device which can be |
17 | | - * commissioned and controlled from a Matter Environment APP. |
18 | | - * Additionally the ESP32 will send debug messages indicating the Matter activity. |
19 | | - * Turning DEBUG Level ON may be useful to following Matter Accessory and Controller messages. |
20 | | - */ |
21 | | - |
22 | | -// Matter Manager |
23 | | -#include <Matter.h> |
24 | | -#include <WiFi.h> |
25 | | - |
26 | | -// List of Matter Endpoints for this Node |
27 | | -// Matter Temperature Sensor Endpoint |
28 | | -MatterTemperatureSensor SimulatedTemperatureSensor; |
29 | | - |
30 | | -// WiFi is manually set and started |
31 | | -const char *ssid = "your-ssid"; // Change this to your WiFi SSID |
32 | | -const char *password = "your-password"; // Change this to your WiFi password |
33 | | - |
34 | | -// Simulate a temperature sensor - add your prefered temperature sensor library code here |
35 | | -float getSimulatedTemperature() { |
36 | | - // The Endpoint implementation keeps an int16_t as internal value information, |
37 | | - // which stores data in 1/100th of any temperature unit |
38 | | - static float simulatedTempHWSensor = -10.0; |
39 | | - |
40 | | - // it will increase from -10C to 10C in 0.5C steps to simulate a temperature sensor |
41 | | - simulatedTempHWSensor = simulatedTempHWSensor + 0.5; |
42 | | - if (simulatedTempHWSensor > 10) { |
43 | | - simulatedTempHWSensor = -10; |
44 | | - } |
45 | | - |
46 | | - return simulatedTempHWSensor; |
47 | | -} |
48 | | - |
49 | | -void setup() { |
50 | | - Serial.begin(115200); |
51 | | - |
52 | | - // Manually connect to WiFi |
53 | | - WiFi.begin(ssid, password); |
54 | | - // Wait for connection |
55 | | - while (WiFi.status() != WL_CONNECTED) { |
56 | | - delay(500); |
57 | | - Serial.print("."); |
58 | | - } |
59 | | - Serial.println(); |
60 | | - |
61 | | - // set initial temperature sensor measurement |
62 | | - // Simulated Sensor - it shall initially print -25 degrees and then move to the -10 to 10 range |
63 | | - SimulatedTemperatureSensor.begin(-25.00); |
64 | | - |
65 | | - // Matter beginning - Last step, after all EndPoints are initialized |
66 | | - Matter.begin(); |
67 | | - |
68 | | - // Check Matter Accessory Commissioning state, which may change during execution of loop() |
69 | | - if (!Matter.isDeviceCommissioned()) { |
70 | | - Serial.println(""); |
71 | | - Serial.println("Matter Node is not commissioned yet."); |
72 | | - Serial.println("Initiate the device discovery in your Matter environment."); |
73 | | - Serial.println("Commission it to your Matter hub with the manual pairing code or QR code"); |
74 | | - Serial.printf("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str()); |
75 | | - Serial.printf("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str()); |
76 | | - // waits for Matter Temperature Sensor Commissioning. |
77 | | - uint32_t timeCount = 0; |
78 | | - while (!Matter.isDeviceCommissioned()) { |
79 | | - delay(100); |
80 | | - if ((timeCount++ % 50) == 0) { // 50*100ms = 5 sec |
81 | | - Serial.println("Matter Node not commissioned yet. Waiting for commissioning."); |
82 | | - } |
83 | | - } |
84 | | - Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); |
85 | | - } |
86 | | -} |
87 | | - |
88 | | -void loop() { |
89 | | - Serial.printf("Current Temperature is %.02f <Temperature Units>\r\n", SimulatedTemperatureSensor.getTemperature()); |
90 | | - // update the temperature sensor value every 5 seconds |
91 | | - // Matter APP shall display the updated temperature |
92 | | - delay(5000); |
93 | | - SimulatedTemperatureSensor.setTemperature(getSimulatedTemperature()); |
94 | | -} |
| 1 | +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | + |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +/* |
| 16 | + * This example is an example code that will create a Matter Device which can be |
| 17 | + * commissioned and controlled from a Matter Environment APP. |
| 18 | + * Additionally the ESP32 will send debug messages indicating the Matter activity. |
| 19 | + * Turning DEBUG Level ON may be useful to following Matter Accessory and Controller messages. |
| 20 | + */ |
| 21 | + |
| 22 | +// Matter Manager |
| 23 | +#include <Matter.h> |
| 24 | +#include <WiFi.h> |
| 25 | + |
| 26 | +// List of Matter Endpoints for this Node |
| 27 | +// Matter Temperature Sensor Endpoint |
| 28 | +MatterTemperatureSensor SimulatedTemperatureSensor; |
| 29 | + |
| 30 | +// WiFi is manually set and started |
| 31 | +const char *ssid = "your-ssid"; // Change this to your WiFi SSID |
| 32 | +const char *password = "your-password"; // Change this to your WiFi password |
| 33 | + |
| 34 | +// Simulate a temperature sensor - add your prefered temperature sensor library code here |
| 35 | +float getSimulatedTemperature() { |
| 36 | + // The Endpoint implementation keeps an int16_t as internal value information, |
| 37 | + // which stores data in 1/100th of any temperature unit |
| 38 | + static float simulatedTempHWSensor = -10.0; |
| 39 | + |
| 40 | + // it will increase from -10C to 10C in 0.5C steps to simulate a temperature sensor |
| 41 | + simulatedTempHWSensor = simulatedTempHWSensor + 0.5; |
| 42 | + if (simulatedTempHWSensor > 10) { |
| 43 | + simulatedTempHWSensor = -10; |
| 44 | + } |
| 45 | + |
| 46 | + return simulatedTempHWSensor; |
| 47 | +} |
| 48 | + |
| 49 | +void setup() { |
| 50 | + Serial.begin(115200); |
| 51 | + |
| 52 | + // Manually connect to WiFi |
| 53 | + WiFi.begin(ssid, password); |
| 54 | + // Wait for connection |
| 55 | + while (WiFi.status() != WL_CONNECTED) { |
| 56 | + delay(500); |
| 57 | + Serial.print("."); |
| 58 | + } |
| 59 | + Serial.println(); |
| 60 | + |
| 61 | + // set initial temperature sensor measurement |
| 62 | + // Simulated Sensor - it shall initially print -25 degrees and then move to the -10 to 10 range |
| 63 | + SimulatedTemperatureSensor.begin(-25.00); |
| 64 | + |
| 65 | + // Matter beginning - Last step, after all EndPoints are initialized |
| 66 | + Matter.begin(); |
| 67 | + |
| 68 | + // Check Matter Accessory Commissioning state, which may change during execution of loop() |
| 69 | + if (!Matter.isDeviceCommissioned()) { |
| 70 | + Serial.println(""); |
| 71 | + Serial.println("Matter Node is not commissioned yet."); |
| 72 | + Serial.println("Initiate the device discovery in your Matter environment."); |
| 73 | + Serial.println("Commission it to your Matter hub with the manual pairing code or QR code"); |
| 74 | + Serial.printf("Manual pairing code: %s\r\n", Matter.getManualPairingCode().c_str()); |
| 75 | + Serial.printf("QR code URL: %s\r\n", Matter.getOnboardingQRCodeUrl().c_str()); |
| 76 | + // waits for Matter Temperature Sensor Commissioning. |
| 77 | + uint32_t timeCount = 0; |
| 78 | + while (!Matter.isDeviceCommissioned()) { |
| 79 | + delay(100); |
| 80 | + if ((timeCount++ % 50) == 0) { // 50*100ms = 5 sec |
| 81 | + Serial.println("Matter Node not commissioned yet. Waiting for commissioning."); |
| 82 | + } |
| 83 | + } |
| 84 | + Serial.println("Matter Node is commissioned and connected to Wi-Fi. Ready for use."); |
| 85 | + } |
| 86 | +} |
| 87 | + |
| 88 | +void loop() { |
| 89 | + Serial.printf("Current Temperature is %.02f <Temperature Units>\r\n", SimulatedTemperatureSensor.getTemperature()); |
| 90 | + // update the temperature sensor value every 5 seconds |
| 91 | + // Matter APP shall display the updated temperature |
| 92 | + delay(5000); |
| 93 | + SimulatedTemperatureSensor.setTemperature(getSimulatedTemperature()); |
| 94 | +} |
0 commit comments