You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: libraries/OpenThread/README.md
+195-6Lines changed: 195 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,177 @@
1
1
| Supported Targets | ESP32-C6 | ESP32-H2 |
2
2
| ----------------- | -------- | -------- |
3
3
4
-
# ESP32 Arduino OpenThreadCLI
4
+
# General View
5
5
6
-
The `OpenThreadCLI` class is an Arduino API for interacting with the OpenThread Command Line Interface (CLI). It allows you to manage and configure the Thread stack using a command-line interface.
6
+
This Arduino OpenThread Library allows using ESP OpenThread implementation using CLI and/or Native OpenThread API.
7
+
8
+
The Library implements 3 C++ Classes:
9
+
-`OThread` Class for Native OpenThread API
10
+
-`OThreadCLI` Class for CLI OpenThread API
11
+
-`DataSet` Class for OpenThread dataset manipulation using Native `OThread` Class
12
+
13
+
# ESP32 Arduino OpenThread Native
14
+
15
+
The `OThread` class provides methods for managing the OpenThread instance and controlling the Thread network. It allows you to initialize, start, stop, and manage the Thread network using native OpenThread APIs.
16
+
17
+
## Class Definition
18
+
19
+
```cpp
20
+
classOpenThread {
21
+
public:
22
+
static bool otStarted; // Indicates whether the OpenThread stack is running.
23
+
24
+
// Get the current Thread device role (e.g., Leader, Router, Child, etc.).
25
+
static ot_device_role_t otGetDeviceRole();
26
+
27
+
// Get the current Thread device role as a string.
28
+
static const char *otGetStringDeviceRole();
29
+
30
+
// Print network information (e.g., network name, channel, PAN ID) to the specified stream.
// Returns true if the OpenThread stack is running.
37
+
operator bool() const;
38
+
39
+
// Initialize the OpenThread stack.
40
+
static void begin(bool OThreadAutoStart = true);
41
+
42
+
// Deinitialize the OpenThread stack.
43
+
static void end();
44
+
45
+
// Start the Thread network.
46
+
void start();
47
+
48
+
// Stop the Thread network.
49
+
void stop();
50
+
51
+
// Bring up the Thread network interface (equivalent to "ifconfig up").
52
+
void networkInterfaceUp();
53
+
54
+
// Bring down the Thread network interface (equivalent to "ifconfig down").
55
+
void networkInterfaceDown();
56
+
57
+
// Commit a dataset to the OpenThread instance.
58
+
void commitDataSet(const DataSet &dataset);
59
+
60
+
private:
61
+
static otInstance *mInstance; // Pointer to the OpenThread instance.
62
+
DataSet mCurrentDataSet; // Current dataset being used by the OpenThread instance.
63
+
};
64
+
65
+
extern OpenThread OThread;
66
+
```
67
+
## Class Overview
68
+
69
+
The `OThread` class provides a simple and intuitive interface for managing the OpenThread stack and Thread network. It abstracts the complexity of the OpenThread APIs and provides Arduino-style methods for common operations.
70
+
71
+
## Public Methods
72
+
### Initialization and Deinitialization
73
+
- `begin(bool OThreadAutoStart = true)`: Initializes the OpenThread stack. If `OThreadAutoStart` is `true`, the Thread network will start automatically using NVS data.
74
+
- `end()`: Deinitializes the OpenThread stack and releases resources.
75
+
### Thread Network Control
76
+
- `start()`: Starts the Thread network. This is equivalent to the CLI command "thread start".
77
+
- `stop()`: Stops the Thread network. This is equivalent to the CLI command "thread stop".
78
+
### Network Interface Control
79
+
- `networkInterfaceUp()`: Brings up the Thread network interface. This is equivalent to the CLI command "ifconfig up".
80
+
- `networkInterfaceDown()`: Brings down the Thread network interface. This is equivalent to the CLI command "ifconfig down".
81
+
### Dataset Management
82
+
- `commitDataSet(const DataSet &dataset)`: Commits a dataset to the OpenThread instance. This is used to configure the Thread network with specific parameters (e.g., network name, channel, PAN ID).
83
+
### Network Information
84
+
- `otGetDeviceRole()`: Returns the current Thread device role as an `ot_device_role_t` enum (e.g., `OT_ROLE_LEADER`, `OT_ROLE_ROUTER`).
85
+
- `otGetStringDeviceRole()`: Returns the current Thread device role as a string (e.g., "Leader", "Router").
86
+
- `otPrintNetworkInformation(Stream &output)`: Prints the current network information (e.g., network name, channel, PAN ID) to the specified stream.
87
+
88
+
## Key Features
89
+
- **Initialization and Cleanup**: Easily initialize and deinitialize the OpenThread stack.
90
+
- **Network Control**: Start and stop the Thread network with simple method calls.
91
+
- **Dataset Management**: Configure the Thread network using the `DataSet` class and commit it to the OpenThread instance.
92
+
- **Network Information**: Retrieve and print the current network information and device role.
93
+
94
+
## Notes
95
+
- The `OThread` class is designed to simplify the use of OpenThread APIs in Arduino sketches.
96
+
- It works seamlessly with the DataSet class for managing Thread network configurations.
97
+
- Ensure that the OpenThread stack is initialized (`OThread.begin()`) before calling other methods.
98
+
99
+
This documentation provides a comprehensive overview of the `OThread` class, its methods, and example usage. It is designed to help developers quickly integrate OpenThread functionality into their Arduino projects.
100
+
101
+
# DataSet Class
102
+
103
+
The `DataSet` class provides a structured way to manage and configure Thread network datasets using native OpenThread APIs. It allows you to set and retrieve network parameters such as the network name, channel, PAN ID, and more. The `DataSet` class works seamlessly with the `OThread` class to apply these configurations to the OpenThread instance.
104
+
105
+
## Class Definition
106
+
107
+
```cpp
108
+
class DataSet {
109
+
public:
110
+
DataSet();
111
+
void clear();
112
+
void initNew();
113
+
const otOperationalDataset &getDataset() const;
114
+
115
+
// Setters
116
+
void setNetworkName(const char *name);
117
+
void setExtendedPanId(const uint8_t *extPanId);
118
+
void setNetworkKey(const uint8_t *key);
119
+
void setChannel(uint8_t channel);
120
+
void setPanId(uint16_t panId);
121
+
122
+
// Getters
123
+
const char *getNetworkName() const;
124
+
const uint8_t *getExtendedPanId() const;
125
+
const uint8_t *getNetworkKey() const;
126
+
uint8_t getChannel() const;
127
+
uint16_t getPanId() const;
128
+
129
+
// Apply the dataset to the OpenThread instance
130
+
void apply(otInstance *instance);
131
+
132
+
private:
133
+
otOperationalDataset mDataset; // Internal representation of the dataset
134
+
};
135
+
```
136
+
137
+
## Class Overview
138
+
The DataSet` class simplifies the management of Thread network datasets by providing intuitive methods for setting, retrieving, and applying network parameters. It abstracts the complexity of the OpenThread dataset APIs and provides Arduino-style methods for common operations.
139
+
140
+
## Public Methods
141
+
### Initialization
142
+
-`DataSet()`: Constructor that initializes an empty dataset.
143
+
-`void clear()`: Clears the dataset, resetting all fields to their default values.
144
+
-`void initNew()`: Initializes a new dataset with default values (equivalent to the CLI command dataset init new).
145
+
### Setters
146
+
-`void setNetworkName(const char *name)`: Sets the network name.
147
+
-`void setExtendedPanId(const uint8_t *extPanId)`: Sets the extended PAN ID.
148
+
-`void setNetworkKey(const uint8_t *key)`: Sets the network key.
149
+
-`void setChannel(uint8_t channel)`: Sets the channel.
150
+
-`void setPanId(uint16_t panId)`: Sets the PAN ID.
151
+
### Getters
152
+
-`const char *getNetworkName() const`: Retrieves the network name.
153
+
-`const uint8_t *getExtendedPanId() const`: Retrieves the extended PAN ID.
154
+
-`const uint8_t *getNetworkKey() const`: Retrieves the network key.
155
+
-`uint8_t getChannel() const`: Retrieves the channel.
156
+
-`uint16_t getPanId() const`: Retrieves the PAN ID.
157
+
### Dataset Application
158
+
-`void apply(otInstance *instance)`: Applies the dataset to the specified OpenThread instance.
159
+
160
+
## Key Features
161
+
-**Dataset Initialization**: Easily initialize a new dataset with default values using initNew().
162
+
-**Custom Configuration**: Set custom network parameters such as the network name, channel, and PAN ID using setter methods.
163
+
-**Dataset Application**: Apply the configured dataset to the OpenThread instance using apply().
164
+
165
+
** Notes
166
+
- The `DataSet` class is designed to work seamlessly with the `OThread` class for managing Thread network configurations.
167
+
- Ensure that the OpenThread stack is initialized (`OThread.begin()`) before applying a dataset.
168
+
- The initNew()`` method provides default values for the dataset, which can be customized using the setter methods.
169
+
170
+
This documentation provides a comprehensive overview of the `DataSet` class, its methods, and example usage. It is designed to help developers easily manage Thread network configurations in their Arduino projects.
171
+
172
+
# OpenThreadCLI Class
173
+
174
+
The `OpenThreadCLI` class is an Arduino API for interacting with the OpenThread Command Line Interface (CLI). It allows you to send commands to the OpenThread stack and receive responses. This class is designed to simplify the use of OpenThread CLI commands in Arduino sketches.
7
175
8
176
There is one main class called `OpenThreadCLI` and a global object used to operate OpenThread CLI, called `OThreadCLI`.\
9
177
Some [helper functions](helper_functions.md) were made available for working with the OpenThread CLI environment.
@@ -20,7 +188,7 @@ Below are the details of the class:
- `setTxBufferSize(size_t tx_queue_len)`: Sets the transmit buffer size (default is 256 bytes).
71
242
- `setRxBufferSize(size_t rx_queue_len)`: Sets the receive buffer size (default is 1024 bytes).
72
-
- `write(uint8_t)`, `available()`, `read()`, `peek()`, `flush()`: Standard Stream methods implementation for OpenThread CLI object.
243
+
### Stream Methods
244
+
- `write(uint8_t)`: Writes a byte to the CLI.
245
+
- `available()`: Returns the number of bytes available to read.
246
+
- `read()`: Reads a byte from the CLI.
247
+
- `peek()`: Returns the next byte without removing it from the buffer.
248
+
- `flush()`: Flushes the CLI buffer.
249
+
250
+
## Key Features
251
+
- **Arduino Stream Compatibility**: Inherits from the Stream class, making it compatible with Arduino's standard I/O functions.
252
+
- **Customizable Console**: Allows customization of the CLI prompt, echoback behavior, and buffer sizes.
253
+
- **Callback Support**: Provides a callback mechanism to handle CLI responses asynchronously.
254
+
- **Seamless Integration**: Designed to work seamlessly with the OThread and DataSet classes
255
+
256
+
## Notes
257
+
- The `OThreadCLI` class is designed to simplify the use of OpenThread CLI commands in Arduino sketches.
258
+
- It works seamlessly with the `OThread` and `DataSet` classes for managing Thread networks.
259
+
- Ensure that the OpenThread stack is initialized (`OThreadCLI.begin()`) before starting the CLI console.
260
+
261
+
This documentation provides a comprehensive overview of the `OThreadCLI` class, its methods, and example usage. It is designed to help developers easily integrate OpenThread CLI functionality into their Arduino projects.
0 commit comments