Skip to content

Commit

Permalink
ci(pre-commit): Apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasssvaz committed Jun 24, 2024
1 parent b60a354 commit 11ec1d1
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 150 deletions.
2 changes: 0 additions & 2 deletions libraries/OpenThread/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,3 @@ extern OpenThreadCLI OThreadCLI;
- `setTxBufferSize(size_t tx_queue_len)`: Sets the transmit buffer size (default is 256 bytes).
- `setRxBufferSize(size_t rx_queue_len)`: Sets the receive buffer size (default is 1024 bytes).
- `write(uint8_t)`, `available()`, `read()`, `peek()`, `flush()`: Standard Stream methods implementation for OpenThread CLI object.
2 changes: 1 addition & 1 deletion libraries/OpenThread/examples/COAP/coap_lamp/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
45 changes: 17 additions & 28 deletions libraries/OpenThread/examples/COAP/coap_lamp/coap_lamp.ino
Original file line number Diff line number Diff line change
@@ -1,34 +1,25 @@
#include "OThreadCLI.h"
#include "OThreadCLI_Util.h"

#define OT_CHANNEL "24"
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
#define OT_MCAST_ADDR "ff05::abcd"
#define OT_CHANNEL "24"
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
#define OT_MCAST_ADDR "ff05::abcd"
#define OT_COAP_RESOURCE_NAME "Lamp"

const char *otSetupLeader[] = {
// clear/disable all
"coap", "stop",
"thread", "stop",
"ifconfig", "down",
"dataset", "clear",
"coap", "stop", "thread", "stop", "ifconfig", "down", "dataset", "clear",
// set dataset
"dataset", "init new",
"dataset channel", OT_CHANNEL,
"dataset networkkey", OT_NETWORK_KEY,
"dataset", "commit active",
"dataset", "init new", "dataset channel", OT_CHANNEL, "dataset networkkey", OT_NETWORK_KEY, "dataset", "commit active",
// network start
"ifconfig", "up",
"thread", "start"
"ifconfig", "up", "thread", "start"
};

const char *otCoapLamp[] = {
// create a multicast IPv6 Address for this device
"ipmaddr add", OT_MCAST_ADDR,
// start and create a CoAP resource
"coap", "start",
"coap resource", OT_COAP_RESOURCE_NAME,
"coap set", "0"
"coap", "start", "coap resource", OT_COAP_RESOURCE_NAME, "coap set", "0"
};

bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoapCmds, uint8_t nCmds2, ot_device_role_t expectedRole) {
Expand All @@ -47,7 +38,7 @@ bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoap
}
Serial.println("OpenThread started.\r\nWaiting for activating correct Device Role.");
// wait for the expected Device Role to start
uint8_t tries = 24; // 24 x 2.5 sec = 1 min
uint8_t tries = 24; // 24 x 2.5 sec = 1 min
while (tries && otGetDeviceRole() != expectedRole) {
Serial.print(".");
delay(2500);
Expand All @@ -72,22 +63,20 @@ bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoap
}
Serial.println("OpenThread setup done. Node is ready.");
// all fine! LED goes Green
neopixelWrite(RGB_BUILTIN, 0, 64, 8); // GREEN ... Lamp is ready!
neopixelWrite(RGB_BUILTIN, 0, 64, 8); // GREEN ... Lamp is ready!
return true;
}

void setupNode() {
// tries to set the Thread Network node and only returns when succeded
bool startedCorrectly = false;
while (!startedCorrectly) {
startedCorrectly |= otDeviceSetup(otSetupLeader, sizeof(otSetupLeader) / sizeof(char *) / 2,
otCoapLamp, sizeof(otCoapLamp) / sizeof(char *) / 2,
OT_ROLE_LEADER);
startedCorrectly |=
otDeviceSetup(otSetupLeader, sizeof(otSetupLeader) / sizeof(char *) / 2, otCoapLamp, sizeof(otCoapLamp) / sizeof(char *) / 2, OT_ROLE_LEADER);
if (!startedCorrectly) {
Serial.println("Setup Failed...\r\nTrying again...");
}
}

}

// this function is used by the Lamp mode to listen for CoAP frames from the Switch Node
Expand All @@ -107,16 +96,16 @@ void otCOAPListen() {
log_i("CoAP PUT [%s]\r\n", payload == '0' ? "OFF" : "ON");
if (payload == '0') {
for (int16_t c = 248; c > 16; c -= 8) {
neopixelWrite(RGB_BUILTIN, c, c, c); // ramp down
neopixelWrite(RGB_BUILTIN, c, c, c); // ramp down
delay(5);
}
neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Lamp Off
neopixelWrite(RGB_BUILTIN, 0, 0, 0); // Lamp Off
} else {
for (int16_t c = 16; c < 248; c += 8) {
neopixelWrite(RGB_BUILTIN, c, c, c); // ramp up
neopixelWrite(RGB_BUILTIN, c, c, c); // ramp up
delay(5);
}
neopixelWrite(RGB_BUILTIN, 255, 255, 255); // Lamp On
neopixelWrite(RGB_BUILTIN, 255, 255, 255); // Lamp On
}
}
}
Expand All @@ -126,8 +115,8 @@ void setup() {
Serial.begin(115200);
// LED starts RED, indicating not connected to Thread network.
neopixelWrite(RGB_BUILTIN, 64, 0, 0);
OThreadCLI.begin(false); // No AutoStart is necessary
OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response
OThreadCLI.begin(false); // No AutoStart is necessary
OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response
setupNode();
// LED goes Green when all is ready and Red when failed.
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/OpenThread/examples/COAP/coap_switch/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
49 changes: 22 additions & 27 deletions libraries/OpenThread/examples/COAP/coap_switch/coap_switch.ino
Original file line number Diff line number Diff line change
@@ -1,33 +1,30 @@
#include "OThreadCLI.h"
#include "OThreadCLI_Util.h"

#define USER_BUTTON 9 // C6/H2 Boot button
#define OT_CHANNEL "24"
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
#define OT_MCAST_ADDR "ff05::abcd"
#define USER_BUTTON 9 // C6/H2 Boot button
#define OT_CHANNEL "24"
#define OT_NETWORK_KEY "00112233445566778899aabbccddeeff"
#define OT_MCAST_ADDR "ff05::abcd"
#define OT_COAP_RESOURCE_NAME "Lamp"

const char *otSetupChild[] = {
// clear/disable all
"coap", "stop",
"thread", "stop",
"ifconfig", "down",
"dataset", "clear",
"coap", "stop", "thread", "stop", "ifconfig", "down", "dataset", "clear",
// set dataset
"dataset channel", OT_CHANNEL,
"dataset networkkey", OT_NETWORK_KEY,
"dataset", "commit active",
"dataset channel", OT_CHANNEL, "dataset networkkey", OT_NETWORK_KEY, "dataset", "commit active",
// network start
"ifconfig", "up",
"thread", "start"
"ifconfig", "up", "thread", "start"
};

const char *otCoapSwitch[] = {
// start and create a CoAP resource
"coap", "start",
"coap",
"start",
};

bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoapCmds, uint8_t nCmds2, ot_device_role_t expectedRole1, ot_device_role_t expectedRole2) {
bool otDeviceSetup(
const char **otSetupCmds, uint8_t nCmds1, const char **otCoapCmds, uint8_t nCmds2, ot_device_role_t expectedRole1, ot_device_role_t expectedRole2
) {
Serial.println("Starting OpenThread.");
Serial.println("Running as Switch - use the BOOT button to toggle the other C6/H2 as a Lamp");
uint8_t i;
Expand All @@ -43,7 +40,7 @@ bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoap
}
Serial.println("OpenThread started.\r\nWaiting for activating correct Device Role.");
// wait for the expected Device Role to start
uint8_t tries = 24; // 24 x 2.5 sec = 1 min
uint8_t tries = 24; // 24 x 2.5 sec = 1 min
while (tries && otGetDeviceRole() != expectedRole1 && otGetDeviceRole() != expectedRole2) {
Serial.print(".");
delay(2500);
Expand All @@ -68,23 +65,21 @@ bool otDeviceSetup(const char **otSetupCmds, uint8_t nCmds1, const char **otCoap
}
Serial.println("OpenThread setup done. Node is ready.");
// all fine! LED goes and stays Blue
neopixelWrite(RGB_BUILTIN, 0, 0, 64); // BLUE ... Swtich is ready!
neopixelWrite(RGB_BUILTIN, 0, 0, 64); // BLUE ... Swtich is ready!
return true;
}


void setupNode() {
// tries to set the Thread Network node and only returns when succeded
bool startedCorrectly = false;
while (!startedCorrectly) {
startedCorrectly |= otDeviceSetup(otSetupChild, sizeof(otSetupChild) / sizeof(char *) / 2,
otCoapSwitch, sizeof(otCoapSwitch) / sizeof(char *) / 2,
OT_ROLE_CHILD, OT_ROLE_ROUTER);
startedCorrectly |= otDeviceSetup(
otSetupChild, sizeof(otSetupChild) / sizeof(char *) / 2, otCoapSwitch, sizeof(otCoapSwitch) / sizeof(char *) / 2, OT_ROLE_CHILD, OT_ROLE_ROUTER
);
if (!startedCorrectly) {
Serial.println("Setup Failed...\r\nTrying again...");
}
}

}

// Sends the CoAP frame to the Lamp node
Expand Down Expand Up @@ -133,12 +128,12 @@ bool otCoapPUT(bool lampState) {
void checkUserButton() {
static long unsigned int lastPress = 0;
const long unsigned int debounceTime = 500;
static bool lastLampState = true; // first button press will turn the Lamp OFF from inital Green
static bool lastLampState = true; // first button press will turn the Lamp OFF from inital Green

pinMode(USER_BUTTON, INPUT_PULLUP); // C6/H2 User Button
pinMode(USER_BUTTON, INPUT_PULLUP); // C6/H2 User Button
if (millis() > lastPress + debounceTime && digitalRead(USER_BUTTON) == LOW) {
lastLampState = !lastLampState;
if (!otCoapPUT(lastLampState)) { // failed: Lamp Node is not responding due to be off or unreachable
if (!otCoapPUT(lastLampState)) { // failed: Lamp Node is not responding due to be off or unreachable
// timeout from the CoAP PUT message... restart the node.
neopixelWrite(RGB_BUILTIN, 255, 0, 0); // RED ... something failed!
Serial.println("Reseting the Node as Switch... wait.");
Expand All @@ -153,8 +148,8 @@ void setup() {
Serial.begin(115200);
// LED starts RED, indicating not connected to Thread network.
neopixelWrite(RGB_BUILTIN, 64, 0, 0);
OThreadCLI.begin(false); // No AutoStart is necessary
OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response
OThreadCLI.begin(false); // No AutoStart is necessary
OThreadCLI.setTimeout(250); // waits 250ms for the OpenThread CLI response
setupNode();
// LED goes and keeps Blue when all is ready and Red when failed.
}
Expand Down
9 changes: 4 additions & 5 deletions libraries/OpenThread/examples/SimpleCLI/SimpleCLI.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
* OpenThread.begin(false) will not automatically start a node in a Thread Network
* The user will need to start it manually using the OpenThread CLI commands
* Use the Serial Monitor to interact with the OpenThread CLI
*
*
* Type 'help' for a list of commands.
* Documentation: https://openthread.io/reference/cli/commands
*
*
*/

#include "OThreadCLI.h"

void setup() {
Serial.begin(115200);
OThreadCLI.begin(false); // No AutoStart - fresh start
OThreadCLI.begin(false); // No AutoStart - fresh start
Serial.println("OpenThread CLI started - type 'help' for a list of commands.");
OThreadCLI.startConsole(Serial);
}

void loop() {
}
void loop() {}
2 changes: 1 addition & 1 deletion libraries/OpenThread/examples/SimpleCLI/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
6 changes: 3 additions & 3 deletions libraries/OpenThread/examples/SimpleNode/SimpleNode.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* OpenThread.begin() will automatically start a node in a Thread Network
* If NVS is empty, default configuration will be as follow:
*
*
* NETWORK_NAME "OpenThread-ESP"
* MESH_LOCAL_PREFIX "fd00:db8:a0:0::/64"
* NETWORK_CHANNEL 15
Expand All @@ -21,8 +21,8 @@

void setup() {
Serial.begin(115200);
OThreadCLI.begin(); // AutoStart using Thread default settings
otPrintNetworkInformation(Serial); // Print Current Thread Network Information
OThreadCLI.begin(); // AutoStart using Thread default settings
otPrintNetworkInformation(Serial); // Print Current Thread Network Information
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion libraries/OpenThread/examples/SimpleNode/ci.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
* OpenThread.begin(false) will not automatically start a node in a Thread Network
* A Leader node is the first device, that has a complete dataset, to start Thread
* A complete dataset is easily achieved by using the OpenThread CLI command "dataset init new"
*
* In order to allow other node to join the network,
*
* In order to allow other node to join the network,
* all of them shall use the same network master key
* The network master key is a 16-byte key that is used to secure the network
*
*
* Using the same channel will make the process faster
*
*
*/

#include "OThreadCLI.h"
#include "OThreadCLI_Util.h"

#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_CHANEL "dataset channel 24"

void setup() {
Serial.begin(115200);
OThreadCLI.begin(false); // No AutoStart - fresh start
OThreadCLI.begin(false); // No AutoStart - fresh start
Serial.println("Setting up OpenThread Node as Leader");

OThreadCLI.println("dataset init new");
OThreadCLI.println(CLI_NETWORK_KEY);
OThreadCLI.println(CLI_NETWORK_CHANEL);
Expand All @@ -34,4 +34,4 @@ void loop() {
Serial.print("Thread Node State: ");
Serial.println(otGetStringDeviceRole());
delay(5000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/*
* OpenThread.begin(false) will not automatically start a node in a Thread Network
* A Router/Child node is the device that will join an existing Thread Network
*
* In order to allow this node to join the network,
* A Router/Child node is the device that will join an existing Thread Network
*
* In order to allow this node to join the network,
* it shall use the same network master key as used by the Leader Node
* The network master key is a 16-byte key that is used to secure the network
*
*
* Using the same channel will make the process faster
*
*
*/

#include "OThreadCLI.h"
#include "OThreadCLI_Util.h"

#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_KEY "dataset networkkey 00112233445566778899aabbccddeeff"
#define CLI_NETWORK_CHANEL "dataset channel 24"

void setup() {
Serial.begin(115200);
OThreadCLI.begin(false); // No AutoStart - fresh start
OThreadCLI.begin(false); // No AutoStart - fresh start
Serial.println("Setting up OpenThread Node as Router/Child");
Serial.println("Make sure the Leader Node is already running");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"esp32s2": false,
"esp32s3": false
}
}
}
4 changes: 2 additions & 2 deletions libraries/OpenThread/examples/ThreadScan/ThreadScan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

void setup() {
Serial.begin(115200);
OThreadCLI.begin(true); // For scanning, AutoStart must be active, any setup
OThreadCLI.setTimeout(100); // Set a timeout for the CLI response
OThreadCLI.begin(true); // For scanning, AutoStart must be active, any setup
OThreadCLI.setTimeout(100); // Set a timeout for the CLI response
Serial.println();
Serial.println("This sketch will continuously scan the Thread Local Network and all devices IEEE 802.15.4 compatible");
}
Expand Down
Loading

0 comments on commit 11ec1d1

Please sign in to comment.