Skip to content

Commit 3419d17

Browse files
committedJan 31, 2025
Works on C6 !
0 parents  commit 3419d17

File tree

6 files changed

+222
-0
lines changed

6 files changed

+222
-0
lines changed
 

‎.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch
6+
.vscode

‎include/README

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

‎lib/README

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

‎partitions.csv

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Name, Type, SubType, Offset, Size, Flags
2+
nvs, data, nvs, 0x9000, 0x5000,
3+
otadata, data, ota, 0xe000, 0x2000,
4+
app0, app, ota_0, 0x10000, 0x140000,
5+
app1, app, ota_1, 0x150000,0x140000,
6+
spiffs, data, spiffs, 0x290000,0x15B000,
7+
zb_storage, data, fat, 0x3EB000,0x4000,
8+
zb_fct, data, fat, 0x3EF000,0x1000,
9+
coredump, data, coredump,0x3F0000,0x10000,

‎platformio.ini

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:esp32-c6-devkitc-1]
12+
platform = https://github.com/pioarduino/platform-espressif32/releases/download/53.03.11/platform-espressif32.zip
13+
board = esp32-c6-devkitc-1
14+
framework = arduino
15+
monitor_speed = 115200
16+
build_flags =
17+
-DZIGBEE_MODE_ED=1
18+
-DARDUINO_USB_MODE=1
19+
-DARDUINO_USB_CDC_ON_BOOT=1
20+
21+
board_build.partitions = partitions.csv

‎src/main.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
* @brief This example demonstrates simple Zigbee light bulb.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a end device light bulb.
19+
* The light bulb is a Zigbee end device, which is controlled by a Zigbee coordinator.
20+
*
21+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
22+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23+
*
24+
* Please check the README.md for instructions and more detailed description.
25+
*
26+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27+
*/
28+
29+
#ifndef ZIGBEE_MODE_ED
30+
#error "Zigbee end device mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include "Zigbee.h"
34+
35+
/* Zigbee light bulb configuration */
36+
#define ZIGBEE_LIGHT_ENDPOINT 10
37+
uint8_t led = RGB_BUILTIN;
38+
uint8_t button = BOOT_PIN;
39+
40+
ZigbeeLight zbLight = ZigbeeLight(ZIGBEE_LIGHT_ENDPOINT);
41+
42+
/********************* RGB LED functions **************************/
43+
void setLED(bool value) {
44+
digitalWrite(led, value);
45+
}
46+
47+
/********************* Arduino functions **************************/
48+
void setup() {
49+
Serial.begin(115200);
50+
51+
// Init LED and turn it OFF (if LED_PIN == RGB_BUILTIN, the rgbLedWrite() will be used under the hood)
52+
pinMode(led, OUTPUT);
53+
digitalWrite(led, LOW);
54+
55+
// Init button for factory reset
56+
pinMode(button, INPUT_PULLUP);
57+
58+
//Optional: set Zigbee device name and model
59+
zbLight.setManufacturerAndModel("Espressif", "ZBLightBulb");
60+
61+
// Set callback function for light change
62+
zbLight.onLightChange(setLED);
63+
64+
//Add endpoint to Zigbee Core
65+
Serial.println("Adding ZigbeeLight endpoint to Zigbee Core");
66+
Zigbee.addEndpoint(&zbLight);
67+
68+
// When all EPs are registered, start Zigbee. By default acts as ZIGBEE_END_DEVICE
69+
if (!Zigbee.begin()) {
70+
Serial.println("Zigbee failed to start!");
71+
Serial.println("Rebooting...");
72+
ESP.restart();
73+
}
74+
Serial.println("Connecting to network");
75+
while (!Zigbee.connected()) {
76+
Serial.print(".");
77+
delay(100);
78+
}
79+
Serial.println();
80+
}
81+
82+
void loop() {
83+
// Checking button for factory reset
84+
if (digitalRead(button) == LOW) { // Push button pressed
85+
// Key debounce handling
86+
delay(100);
87+
int startTime = millis();
88+
while (digitalRead(button) == LOW) {
89+
delay(50);
90+
if ((millis() - startTime) > 3000) {
91+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
92+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
93+
delay(1000);
94+
Zigbee.factoryReset();
95+
}
96+
}
97+
// Toggle light by pressing the button
98+
zbLight.setLight(!zbLight.getLightState());
99+
}
100+
delay(100);
101+
}

0 commit comments

Comments
 (0)
Please sign in to comment.