Skip to content

Commit 3ee4a29

Browse files
committed
Merge branch 'wifi_connection-issue' of https://github.com/jeremypoulter/ESP32_WiFi_V4.x into wifi_connection-issue
2 parents 85cd826 + 7968d38 commit 3ee4a29

16 files changed

+4553
-4905
lines changed

platformio.ini

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@ default_envs = openevse_wifi_v1
3131
[common]
3232
version = -D BUILD_TAG=4.1.8
3333
lib_deps =
34-
bblanchon/ArduinoJson@6.19.1
34+
bblanchon/ArduinoJson@6.20.1
3535
jeremypoulter/[email protected]
3636
jeremypoulter/Micro [email protected]
3737
jeremypoulter/[email protected]
38-
jeremypoulter/[email protected].11
38+
jeremypoulter/[email protected].12
3939
jeremypoulter/[email protected]
4040
jeremypoulter/[email protected]
4141
jeremypoulter/[email protected]
42-
erropix/ESP32 [email protected]
43-
4442
4543
4644
lib_ignore = WebSockets ; ArduinoOcpp: don't compile built-in WS library
@@ -100,15 +98,16 @@ build_flags =
10098
build_partitions = min_spiffs.csv
10199
build_partitions_debug = min_spiffs_debug.csv
102100

103-
neopixel_lib = adafruit/Adafruit [email protected]
101+
neopixel_lib = adafruit/Adafruit [email protected]
102+
104103

105104
[env]
106105
# specify exact Arduino ESP SDK version, requires platformio 3.5+ (curently dev version)
107106
# http://docs.platformio.org/en/latest/projectconf/section_env_general.html#platform
108107
#platform = https://github.com/platformio/platform-espressif32.git#feature/stage
109108
#platform = https://github.com/platformio/platform-espressif32.git#develop
110109
#platform = [email protected]
111-
platform = espressif32@5.0.0
110+
platform = espressif32@6.0.1
112111
#framework = arduino, espidf
113112
framework = arduino
114113
lib_deps = ${common.lib_deps}

src/LedManagerTask.cpp

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,24 @@
66
#include <openevse.h>
77

88
#ifdef ESP32
9-
#include <analogWrite.h>
9+
//#include <analogWrite.h>
10+
#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
11+
#ifndef RED_LEDC_CHANNEL
12+
#define RED_LEDC_CHANNEL 1
13+
#endif
14+
#ifndef GREEN_LEDC_CHANNEL
15+
#define GREEN_LEDC_CHANNEL 2
16+
#endif
17+
#ifndef BLUE_LEDC_CHANNEL
18+
#define BLUE_LEDC_CHANNEL 3
19+
#endif
20+
#ifndef LEDC_FREQUENCY
21+
#define LEDC_FREQUENCY 5000
22+
#endif
23+
#ifndef LEDC_RESOLUTION
24+
#define LEDC_RESOLUTION 8
25+
#endif
26+
#endif
1027
#endif
1128

1229
#include "debug.h"
@@ -29,7 +46,7 @@ Adafruit_NeoPixel strip = Adafruit_NeoPixel(NEO_PIXEL_LENGTH, NEO_PIXEL_PIN, NEO
2946
#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
3047

3148
// https://learn.adafruit.com/led-tricks-gamma-correction/the-quick-fix
32-
const uint8_t PROGMEM gamma8[] = {
49+
const uint8_t gamma8[] = {
3350
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3451
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1,
3552
1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2,
@@ -55,10 +72,13 @@ const uint8_t PROGMEM gamma8[] = {
5572
#define WIFI_BUTTON_SHARE_LED WIFI_LED
5673
#elif defined(RED_LED) && RED_LED == WIFI_BUTTON
5774
#define WIFI_BUTTON_SHARE_LED RED_LED
75+
#define WIFI_BUTTON_SHARE_LEDC_CHANNEL RED_LEDC_CHANNEL
5876
#elif defined(GREEN_LED) && GREEN_LED == WIFI_BUTTON
5977
#define WIFI_BUTTON_SHARE_LED GREEN_LED
78+
#define WIFI_BUTTON_SHARE_LEDC_CHANNEL GREEN_LEDC_CHANNEL
6079
#elif defined(BLUE_LED) && BLUE_LED == WIFI_BUTTON
6180
#define WIFI_BUTTON_SHARE_LED BLUE_LED
81+
#define WIFI_BUTTON_SHARE_LLEDC_CHANNELBLUE_LEDC_CHANNEL
6282
#endif
6383

6484
#endif
@@ -114,12 +134,13 @@ void LedManagerTask::setup()
114134

115135
#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
116136
DBUGF("Initialising RGB LEDs, %d, %d, %d", RED_LED, GREEN_LED, BLUE_LED);
117-
pinMode(RED_LED, OUTPUT);
118-
digitalWrite(RED_LED, LOW);
119-
pinMode(GREEN_LED, OUTPUT);
120-
digitalWrite(GREEN_LED, LOW);
121-
pinMode(BLUE_LED, OUTPUT);
122-
digitalWrite(BLUE_LED, LOW);
137+
// configure LED PWM functionalitites
138+
ledcSetup(RED_LEDC_CHANNEL, LEDC_FREQUENCY, LEDC_RESOLUTION);
139+
ledcAttachPin(RED_LED, RED_LEDC_CHANNEL);
140+
ledcSetup(GREEN_LEDC_CHANNEL, LEDC_FREQUENCY, LEDC_RESOLUTION);
141+
ledcAttachPin(GREEN_LED, GREEN_LEDC_CHANNEL);
142+
ledcSetup(BLUE_LEDC_CHANNEL, LEDC_FREQUENCY, LEDC_RESOLUTION);
143+
ledcAttachPin(BLUE_LED, BLUE_LEDC_CHANNEL);
123144
#endif
124145

125146
#ifdef WIFI_LED
@@ -320,41 +341,7 @@ int LedManagerTask::fadeLed(int fadeValue, int FadeDir)
320341
#if RGB_LED
321342
void LedManagerTask::setAllRGB(uint8_t red, uint8_t green, uint8_t blue)
322343
{
323-
DBUG("LED R:");
324-
DBUG(red);
325-
DBUG(" G:");
326-
DBUG(green);
327-
DBUG(" B:");
328-
DBUGLN(blue);
329-
330-
if(brightness) { // See notes in setBrightness()
331-
red = (red * brightness) >> 8;
332-
green = (green * brightness) >> 8;
333-
blue = (blue * brightness) >> 8;
334-
}
335-
336-
#if defined(NEO_PIXEL_PIN) && defined(NEO_PIXEL_LENGTH)
337-
uint32_t col = strip.gamma32(strip.Color(red, green, blue));
338-
DBUGVAR(col, HEX);
339-
strip.fill(col);
340-
strip.show();
341-
#endif
342-
343-
#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
344-
analogWrite(RED_LED, pgm_read_byte(&gamma8[red]));
345-
analogWrite(GREEN_LED, pgm_read_byte(&gamma8[green]));
346-
analogWrite(BLUE_LED, pgm_read_byte(&gamma8[blue]));
347-
348-
#ifdef WIFI_BUTTON_SHARE_LED
349-
#if RED_LED == WIFI_BUTTON_SHARE_LED
350-
buttonShareState = red;
351-
#elif GREEN_LED == WIFI_BUTTON_SHARE_LED
352-
buttonShareState = green;
353-
#elif BLUE_LED == WIFI_BUTTON_SHARE_LED
354-
buttonShareState = blue;
355-
#endif
356-
#endif
357-
#endif
344+
setEvseAndWifiRGB(red, green, blue, red, green, blue);
358345
}
359346
#endif
360347

@@ -384,6 +371,20 @@ void LedManagerTask::setEvseAndWifiRGB(uint8_t evseRed, uint8_t evseGreen, uint8
384371
wifiBlue = (wifiBlue * brightness) >> 8;
385372
}
386373

374+
DBUG("EVSE LED R:");
375+
DBUG(evseRed);
376+
DBUG(" G:");
377+
DBUG(evseGreen);
378+
DBUG(" B:");
379+
DBUGLN(evseBlue);
380+
381+
DBUG("WiFi LED R:");
382+
DBUG(wifiRed);
383+
DBUG(" G:");
384+
DBUG(wifiGreen);
385+
DBUG(" B:");
386+
DBUGLN(wifiBlue);
387+
387388
#if defined(NEO_PIXEL_PIN) && defined(NEO_PIXEL_LENGTH)
388389
uint32_t col = strip.gamma32(strip.Color(evseRed, evseGreen, evseBlue));
389390
DBUGVAR(col, HEX);
@@ -393,18 +394,24 @@ void LedManagerTask::setEvseAndWifiRGB(uint8_t evseRed, uint8_t evseGreen, uint8
393394
#endif
394395

395396
#if defined(RED_LED) && defined(GREEN_LED) && defined(BLUE_LED)
396-
analogWrite(RED_LED, pgm_read_byte(&gamma8[wifiRed]));
397-
analogWrite(GREEN_LED, pgm_read_byte(&gamma8[wifiGreen]));
398-
analogWrite(BLUE_LED, pgm_read_byte(&gamma8[wifiBlue]));
397+
398+
DBUGVAR(gamma8[wifiRed]);
399+
DBUGVAR(gamma8[wifiGreen]);
400+
DBUGVAR(gamma8[wifiBlue]);
401+
402+
ledcWrite(RED_LEDC_CHANNEL, gamma8[wifiRed]);
403+
ledcWrite(GREEN_LEDC_CHANNEL, gamma8[wifiGreen]);
404+
ledcWrite(BLUE_LEDC_CHANNEL, gamma8[wifiBlue]);
399405

400406
#ifdef WIFI_BUTTON_SHARE_LED
401407
#if RED_LED == WIFI_BUTTON_SHARE_LED
402-
buttonShareState = wifiRed;
408+
buttonShareState = gamma8[wifiRed];
403409
#elif GREEN_LED == WIFI_BUTTON_SHARE_LED
404-
buttonShareState = wifiGreen;
410+
buttonShareState = gamma8[wifiGreen];
405411
#elif BLUE_LED == WIFI_BUTTON_SHARE_LED
406-
buttonShareState = wifiBlue;
412+
buttonShareState = gamma8[wifiBlue];
407413
#endif
414+
DBUGVAR(buttonShareState);
408415
#endif
409416
#endif
410417
}
@@ -507,34 +514,26 @@ void LedManagerTask::setWifiMode(bool client, bool connected)
507514
int LedManagerTask::getButtonPressed()
508515
{
509516
#if defined(WIFI_BUTTON_SHARE_LED)
510-
#ifdef ESP32
511-
int channel = analogWriteChannel(WIFI_BUTTON_SHARE_LED);
512-
if(-1 != channel) {
513-
ledcDetachPin(WIFI_BUTTON_SHARE_LED);
514-
}
517+
#ifdef RGB_LEDC_CHANNEL
518+
ledcDetachPin(WIFI_BUTTON_SHARE_LED);
519+
#else
520+
digitalWrite(WIFI_BUTTON_SHARE_LED, HIGH);
515521
#endif
516522

517-
digitalWrite(WIFI_BUTTON_SHARE_LED, HIGH);
518523
pinMode(WIFI_BUTTON_SHARE_LED, WIFI_BUTTON_PRESSED_PIN_MODE);
519524
#endif
520525

521526
// Pressing the boot button for 5 seconds will turn on AP mode, 10 seconds will factory reset
522527
int button = digitalRead(WIFI_BUTTON);
523528

524529
#if defined(WIFI_BUTTON_SHARE_LED)
525-
pinMode(WIFI_BUTTON, OUTPUT);
526-
527-
#ifdef ESP32
528-
if(-1 != channel) {
529-
ledcAttachPin(WIFI_BUTTON_SHARE_LED, channel);
530-
}
530+
#ifdef WIFI_BUTTON_SHARE_LEDC_CHANNEL
531+
ledcAttachPin(WIFI_BUTTON_SHARE_LED, WIFI_BUTTON_SHARE_LEDC_CHANNEL);
532+
ledcWrite(WIFI_BUTTON_SHARE_LED, buttonShareState);
533+
#else
534+
pinMode(WIFI_BUTTON_SHARE_LED, OUTPUT);
535+
digitalWrite(WIFI_BUTTON_SHARE_LED, buttonShareState ? HIGH : LOW);
531536
#endif
532-
533-
if(0 == buttonShareState || 255 == buttonShareState) {
534-
digitalWrite(WIFI_BUTTON_SHARE_LED, buttonShareState ? HIGH : LOW);
535-
} else {
536-
analogWrite(WIFI_BUTTON_SHARE_LED, buttonShareState);
537-
}
538537
#endif
539538

540539
return button;
@@ -548,11 +547,7 @@ void LedManagerTask::setBrightness(uint8_t brightness)
548547
// adding 1 here may (intentionally) roll over...so 0 = max brightness
549548
// (color values are interpreted ltimingiterally; no scaling), 1 = min
550549
// brightness (off), 255 = just below max brightness.
551-
this->brightness = brightness - 1;
552-
553-
//#if defined(NEO_PIXEL_PIN) && defined(NEO_PIXEL_LENGTH)
554-
// strip.setBrightness(LED_DEFAULT_BRIGHTNESS);
555-
//#endif
550+
this->brightness = brightness + 1;
556551

557552
DBUGVAR(this->brightness);
558553

src/LedManagerTask.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ class LedManagerTask : public MicroTasks::Task
4545

4646
#if RGB_LED
4747
void setAllRGB(uint8_t red, uint8_t green, uint8_t blue);
48-
#endif
49-
#if RGB_LED
5048
void setEvseAndWifiRGB(uint8_t evseRed, uint8_t evseGreen, uint8_t evseBlue, uint8_t wifiRed, uint8_t wifiGreen, uint8_t wifiBlue);
5149
#endif
5250

src/app_config.cpp

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -359,55 +359,7 @@ void config_set(const char *name, double val) {
359359
user_config.set(name, val);
360360
}
361361

362-
void config_save_emoncms(bool enable, String server, String node, String apikey,
363-
String fingerprint)
364-
{
365-
uint32_t newflags = flags & ~CONFIG_SERVICE_EMONCMS;
366-
if(enable) {
367-
newflags |= CONFIG_SERVICE_EMONCMS;
368-
}
369362

370-
user_config.set("emoncms_server", server);
371-
user_config.set("emoncms_node", node);
372-
user_config.set("emoncms_apikey", apikey);
373-
user_config.set("emoncms_fingerprint", fingerprint);
374-
user_config.set("flags", newflags);
375-
user_config.commit();
376-
}
377-
378-
void
379-
config_save_mqtt(bool enable, int protocol, String server, uint16_t port, String topic, bool retained, String user, String pass, String solar, String grid_ie, String live_pwr, bool reject_unauthorized)
380-
{
381-
uint32_t newflags = flags & ~(CONFIG_SERVICE_MQTT | CONFIG_MQTT_PROTOCOL | CONFIG_MQTT_ALLOW_ANY_CERT | CONFIG_MQTT_RETAINED);
382-
if(enable) {
383-
newflags |= CONFIG_SERVICE_MQTT;
384-
}
385-
if(!reject_unauthorized) {
386-
newflags |= CONFIG_MQTT_ALLOW_ANY_CERT;
387-
}
388-
if (retained) {
389-
newflags |= CONFIG_MQTT_RETAINED;
390-
}
391-
newflags |= protocol << 4;
392-
393-
user_config.set("mqtt_server", server);
394-
user_config.set("mqtt_port", port);
395-
user_config.set("mqtt_topic", topic);
396-
user_config.set("mqtt_user", user);
397-
user_config.set("mqtt_pass", pass);
398-
user_config.set("mqtt_solar", solar);
399-
user_config.set("mqtt_grid_ie", grid_ie);
400-
user_config.set("mqtt_live_pwr", live_pwr);
401-
user_config.set("flags", newflags);
402-
user_config.commit();
403-
}
404-
405-
void
406-
config_save_admin(String user, String pass) {
407-
user_config.set("www_username", user);
408-
user_config.set("www_password", pass);
409-
user_config.commit();
410-
}
411363

412364
void
413365
config_save_sntp(bool sntp_enable, String tz)
@@ -436,51 +388,6 @@ void config_set_timezone(String tz)
436388
tzset();
437389
}
438390

439-
void
440-
config_save_advanced(String hostname, String sntp_host) {
441-
user_config.set("hostname", hostname);
442-
user_config.set("sntp_hostname", sntp_host);
443-
user_config.commit();
444-
}
445-
446-
void
447-
config_save_wifi(String qsid, String qpass)
448-
{
449-
user_config.set("ssid", qsid);
450-
user_config.set("pass", qpass);
451-
user_config.commit();
452-
}
453-
454-
void
455-
config_save_ohm(bool enable, String qohm)
456-
{
457-
uint32_t newflags = flags & ~CONFIG_SERVICE_OHM;
458-
if(enable) {
459-
newflags |= CONFIG_SERVICE_OHM;
460-
}
461-
462-
user_config.set("ohm", qohm);
463-
user_config.set("flags", newflags);
464-
user_config.commit();
465-
}
466-
467-
void
468-
config_save_rfid(bool enable, String storage){
469-
uint32_t newflags = flags & ~CONFIG_RFID;
470-
if(enable) {
471-
newflags |= CONFIG_RFID;
472-
}
473-
user_config.set("flags", newflags);
474-
user_config.set("rfid_storage", rfid_storage);
475-
user_config.commit();
476-
}
477-
478-
void
479-
config_save_flags(uint32_t newFlags) {
480-
user_config.set("flags", newFlags);
481-
user_config.commit();
482-
}
483-
484391
void
485392
config_reset() {
486393
ResetEEPROM();

0 commit comments

Comments
 (0)