Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnnings #22

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ This is a sample of the nmcli commands output:

![nmcli preview commands](https://raw.githubusercontent.com/hpsaturn/esp32-wifi-cli/master/images/version2nmcli.jpg)

### nmcli connect

For instance for setup a new connection:

```bash
nmcli connect Your SSID password "Your Password"
```

Note that you could enter your ssid with spaces but without quotes, and your password with spaces but into quotes.

### nmcli tips

nmcli support many WiFi networks, and you are able to list those with `nmcli list`, also select your WiFi network default with `nmcli select #` where # is the number or ID of each WiFi network listed with `list` command. Also, you could enable multi network with `nmcli mode multi`, that means that the device will try to detect what WiFi network is available, or force with `nmcli mode single` to use only your WiFi network default.

## Custom parameters

For instance you can extend the available commands adding new ones in the setup, also add your prompt name and custom logo, like this example:
Expand Down Expand Up @@ -88,7 +102,7 @@ Be careful with the last flag `WCLI_MAX_CMDS` when you are adding more custom co

You able to install this library with pio pkg command:

`pio pkg install --library "hpsaturn/ESP32 Wifi CLI @^0.3.0"`
`pio pkg install --library "hpsaturn/ESP32 Wifi CLI @^0.3.2"`

Or add it in your ini file. Also you can compile here the examples with a simple `pio run` over root of this repo.

Expand Down
42 changes: 25 additions & 17 deletions examples/M5Atom/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,23 @@
#include <M5Atom.h>
#include <ESP32WifiCLI.hpp>

bool set_color = false;

/*********************************************************************
* Optional callback.
********************************************************************/
class mESP32WifiCLICallbacks : public ESP32WifiCLICallbacks {
void onWifiStatus(bool isConnected) {
M5.dis.setBrightness(5); // set brightness to 50%
if (isConnected)
M5.dis.fillpix(0x00ff00); // set LED to green
else
M5.dis.fillpix(0xffff00); // set LED to yellow
}

// Callback for extend the help menu.
void onHelpShow() {
Serial.println("\r\nCustom commands:\r\n");
Serial.println("blink <times> <millis>\tLED blink x times each x millis");
Serial.println("echo \"message\"\t\tEcho the input message");
Serial.println("reboot\t\t\tperform a soft ESP32 reboot");
}
void onNewWifi(String ssid, String passw) {
M5.dis.setBrightness(5); // set brightness to 50%
if (!set_color) { // when you set a color stop wifi notification
if (isConnected)
M5.dis.fillpix(0x00ff00); // set LED to green
else
M5.dis.fillpix(0xffff00); // set LED to yellow
}
}
void onHelpShow() {}
void onNewWifi(String ssid, String passw) {}
};

/*********************************************************************
Expand All @@ -60,6 +56,17 @@ void blink(char *args, Stream *response) {
}
}

void color(char *args, Stream *response){
String hexcolor = wcli.parseArgument(args);
set_color = true;
int red;
int green;
int blue;
sscanf(hexcolor.c_str(), "%i %i %i", &red, &green, &blue);
M5.dis.setBrightness(20);
M5.dis.fillpix(CRGB().setRGB(red, green, blue));
}

void echo(char *args, Stream *response) {
String echo = wcli.parseArgument(args);
Serial.println("\r\nmsg: "+echo);
Expand All @@ -76,8 +83,9 @@ void setup() {
delay(1000);
wcli.setCallback(new mESP32WifiCLICallbacks());
// User custom commands:
wcli.add("blink", &blink, "\tLED blink x times each x millis");
wcli.add("echo", &echo, "\tEcho the input message");
wcli.add("blink", &blink, "\t\tLED blink x times each x millis");
wcli.add("echo", &echo, "\t\tEcho message into quotes");
wcli.add("color", &color, "\t\tset color into quotes: i.e \"255 128 0\"");
wcli.add("reboot", &reboot, "\tperform a ESP32 reboot");
wcli.begin();
}
Expand Down
24 changes: 14 additions & 10 deletions examples/advanced/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@

#include <ESP32WifiCLI.hpp>

int LED_PIN = 13;

int LED_PIN = 13; // change it via CLI using this example :D
// for instance if you are using a LilyGO T7 v1.5 board,
// set LED like this:
// setled 19
// and the reboot with the command reboot.
// Also the LED could be ON when the WiFi is ready.

const char logo[] =
"▓█████ ▒██ ██▒ ▄▄▄ ███▄ ▄███▓ ██▓███ ██▓ ▓█████ \n"
Expand Down Expand Up @@ -57,7 +61,7 @@ class mESP32WifiCLICallbacks : public ESP32WifiCLICallbacks {
};

/*********************************************************************
* User defined commands. Example: suspend, blink, reboot, etc.
* User defined commands sectioh. Examples: suspend, blink, reboot, etc.
********************************************************************/
void gotToSuspend(int type, int seconds) {
delay(8); // waiting for writing msg on serial
Expand Down Expand Up @@ -99,7 +103,7 @@ void setled(char *args, Stream *response) {
Pair<String, String> operands = wcli.parseCommand(args);
int pin = operands.first().toInt();
if(pin >= 0 && pin <= 31) {
wcli.setInt("LED_PIN", pin);
wcli.setInt("KEY_LED_PIN", pin);
Serial.println("\r\nLED GPIO set to " + String(pin));
Serial.println("Please reboot to apply the change.");
}
Expand Down Expand Up @@ -128,22 +132,22 @@ void setup() {
delay(2000); // Only for this demo
wcli.setCallback(new mESP32WifiCLICallbacks());
wcli.setSilentMode(true); // less debug output

// Configure previously configured LED pins via CLI command
int LED_PIN = wcli.getInt("LED_PIN", LED_PIN);
pinMode(LED_PIN, OUTPUT);


// Enter your custom commands:
wcli.add("sleep", &sleep, "\t\t<mode> <time> ESP32 sleep mode (deep/light)\r\n");
wcli.add("echo", &echo, "\t\t\"message\" Echo the msg. Parameter into quotes");
wcli.add("info", &info, "\t\tsystem status info");
wcli.add("setled", &setled, "\t<PIN> config the LED GPIO for blink");
wcli.add("setled", &setled, "\t<PIN> config the LED GPIO pin");
wcli.add("blink", &blink, "\t\t<times> <millis> LED blink x times each x millis");
wcli.add("reboot", &reboot, "\tperform a ESP32 reboot");

wcli.shell->attachLogo(logo);
wcli.shell->clear();
wcli.begin(); // Alternatively, you can init with begin(115200,appname)

// Configure previously configured LED pins via CLI command
LED_PIN = (int) wcli.getInt("KEY_LED_PIN", LED_PIN);
pinMode(LED_PIN, OUTPUT);
}

void loop() {
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ESP32 Wifi CLI",
"version": "0.3.1",
"version": "0.3.2",
"homepage":"https://github.com/hpsaturn/esp32-wifi-cli#readme",
"keywords":
[
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=ESP32 Wifi CLI
version=0.3.1
version=0.3.2
author=hpsaturn <[email protected]>
maintainer=hpsaturn <[email protected]>
url=https://github.com/hpsaturn/esp32-wifi-cli.git
Expand Down
10 changes: 7 additions & 3 deletions platformio.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; ESP32 Wifi CLI
; ESP32 Wifi CLI (nmcli)
; @hpsaturn
; Full guide and details: https://github.com/hpsaturn/esp32-wifi-cli#readme

Expand All @@ -18,9 +18,13 @@ build_flags =
-D SHELLMINATOR_BUFF_DIM=70
-D COMMANDER_MAX_COMMAND_SIZE=70
-D WCLI_MAX_CMDS=7 ; only for this example
-Wall
-Wextra
; -Werror

lib_deps =
https://github.com/hpsaturn/Shellminator.git
https://github.com/hpsaturn/Commander-API.git#strcmp-fix
https://github.com/hpsaturn/Commander-API.git

board_build.partitions = min_spiffs.csv

Expand All @@ -35,7 +39,7 @@ build_src_filter = -<*> +<M5Atom/>
lib_deps =
${esp32_common.lib_deps}
m5stack/M5Atom@^0.1.2
fastled/FastLED@^3.5.0
fastled/FastLED@^3.7.8

[env:esp32]
extends = esp32_common
Expand Down
2 changes: 1 addition & 1 deletion src/ESP32WifiCLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ESP32WifiCLI::printHelp() {
this->shell->printHelp();
}

String ESP32WifiCLI::getNetKeyName(int net) {
String ESP32WifiCLI::getNetKeyName(uint8_t net) {
if (net > 99) return "";
char key[11];
sprintf(key, "key_net%02d", net);
Expand Down
6 changes: 3 additions & 3 deletions src/ESP32WifiCLI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#define RW_MODE false
#define RO_MODE true

#define ESP32WIFICLI_VERSION "0.3.1"
#define ESP32WIFICLI_REVISION 045
#define ESP32WIFICLI_VERSION "0.3.2"
#define ESP32WIFICLI_REVISION 046

#ifndef WCLI_MAX_CMDS
#define WCLI_MAX_CMDS 15 // user and public commands
Expand Down Expand Up @@ -110,7 +110,7 @@ class ESP32WifiCLI {
int size_ = 0;
int isize_ = 0;

String getNetKeyName(int net);
String getNetKeyName(uint8_t net);

ESP32WifiCLICallbacks* cb = nullptr;
};
Expand Down
7 changes: 3 additions & 4 deletions src/parser_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static Pair<String, String> ParseCommand(String message) {
return Pair<String, String>(keyword, message);
}

static String ParseArgument(String message) {
static inline String ParseArgument(String message) {
String keyword = "";
for (auto& car : message) {
if (car == '"') break;
Expand All @@ -42,11 +42,10 @@ static String ParseArgument(String message) {
return message;
}

static int ParseEnableDisable(String args) {
static inline int ParseEnableDisable(String args) {
Pair<String, String> operands = ParseCommand(args);
String param = operands.first();
param.toUpperCase();
bool enable;
if (param.equals("ENABLE"))
return 1;
else if (param.equals("DISABLE"))
Expand All @@ -55,7 +54,7 @@ static int ParseEnableDisable(String args) {
return -1;
}

static bool extract_connect_parames(const char* args, char** ssid, char** password, Stream *response) {
static inline bool extract_connect_parames(const char* args, char** ssid, char** password, Stream *response) {
const char* password_prefix = " password ";

// Find the " password " prefix
Expand Down
Loading