Skip to content

Commit b5d1001

Browse files
committed
fix ArduinoJson errros
1 parent 9b5d8e5 commit b5d1001

File tree

8 files changed

+86
-73
lines changed

8 files changed

+86
-73
lines changed

platformio.ini

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,38 @@
11
; PlatformIO Project Configuration File
22
; https://docs.platformio.org/page/projectconf.html
33

4-
; ================================================================
5-
; = =
6-
; = DO NOT USE PLATFORMIO FOR THIS PROJECT =
7-
; = =
8-
; = 14 March 2022 : When built with Platformio this project =
9-
; = does not run properly; any streams you start will fail =
10-
; = with 'ESP_ERR_HTTPD_RESP_SEND' in the serial console and =
11-
; = ERR_INVALID_CHUNK_ENCODING 200 (OK) in the browser console.=
12-
; = =
13-
; = This is a difficult issue, and currently unresolved. =
14-
; = See: =
15-
; = https://github.com/easytarget/esp32-cam-webserver/issues/218 =
16-
; = =
17-
; = The focus of thei project is to show a expanded example =
18-
; = using the official Arduino IDE. PlatformIO is, and has =
19-
; = always been, a nice-to-have; so I will be releasing 4.x =
20-
; = without platformio support. See the above github issue if =
21-
; = you are able to help fixing this. =
22-
; = =
23-
; ================================================================
24-
;
25-
26-
; The esp32-cam-webserver project is intended to be easily compilable
27-
; with the stock Arduino IDE.
28-
; - Maintaining compatibility with other development environments
29-
; is important, but I wont accept changes to the PlatformIO build that
30-
; break compatibilty with the stock IDE. Eg by using non-standard
31-
; partition schemes or overriding Arduino defined limits, etc.
324

335
[env]
34-
platform_packages = framework-arduinoespressif32@https://github.com/espressif/arduino-esp32.git#2.0.3
356
monitor_speed = 115200
367
upload_speed = 921600
8+
platform = espressif32
9+
framework = arduino
3710
monitor_rts = 0
3811
monitor_dtr = 0
12+
; https://registry.platformio.org/tools/espressif/toolchain-riscv32-esp/versions
13+
;platform_packages = espressif/toolchain-riscv32-esp
3914
board_build.partitions = partitions.csv
4015
;board_build.partitions = min_spiffs.csv
16+
board_build.filesystem = littlefs
4117
monitor_filters = esp32_exception_decoder
18+
build_flags =
19+
!python scripts/build_flags.py git_branch
20+
!python scripts/build_flags.py git_repo
21+
!python scripts/build_flags.py git_owner
22+
-D GITHUB_RUN=\"${sysenv.GITHUB_RUN}\"
23+
; -D WIFISSID=\"gast\" ; use fixed WiFi credentials if Improv-WiFi-Library isn´t supported by your board
24+
; -D WIFIPASSWORD=\"12345678\" ; use fixed WiFi credentials if Improv-WiFi-Library isn´t supported by your board
4225
lib_deps =
43-
https://github.com/me-no-dev/ESPAsyncWebServer.git
26+
https://github.com/mathieucarbou/ESPAsyncWebServer ; installing by ElegantOTA
4427
https://github.com/espressif/json_generator.git
4528
https://github.com/espressif/json_parser.git
46-
bblanchon/ArduinoJson
47-
29+
bblanchon/ArduinoJson@>6.19.0
30+
;https://github.com/tobiasfaust/Improv-WiFi-Library.git
31+
;https://github.com/tobiasfaust/ElegantOTA.git
32+
4833

4934
[env:firmware_ESP32]
50-
platform = espressif32
5135
board = esp32dev
52-
framework = arduino
53-
board_build.filesystem = littlefs
5436
build_flags = ${env.build_flags}
5537
-DBOARD_HAS_PSRAM
5638
-mfix-esp32-psram-cache-issue

scripts/build_flags.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import subprocess;
2+
import sys;
3+
import os, re;
4+
5+
def git_branch():
6+
print('-D GIT_BRANCH=\\"%s\\"' % subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip().decode())
7+
8+
def git_repo():
9+
output = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'])
10+
repo = os.path.basename(output).strip().decode()
11+
print('-D GIT_REPO=\\"%s\\"' % repo);
12+
13+
def git_owner():
14+
# get the github owner of the origin repo
15+
output = subprocess.check_output(['git', 'config', '--get', 'remote.origin.url'])
16+
owner = re.search(r'github.com[:/](.*)/', output.decode()).group(1)
17+
print('-D GIT_OWNER=\\"%s\\"' % owner);
18+
19+
20+
if __name__ == '__main__':
21+
globals()[sys.argv[1]]()

src/app_component.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ unsigned char CLAppComponent::hex2int(char c) {
114114
return(0);
115115
}
116116

117-
int CLAppComponent::urlDecode(String* decoded, String* source) {
117+
int CLAppComponent::urlDecode(String& decoded, const char* source) {
118118
char c;
119119
char code0;
120120
char code1;
121-
for (int i =0; i < source->length(); i++){
122-
c=decoded->charAt(i);
121+
for (int i = 0; i < strlen(source); i++){
122+
c=decoded.charAt(i);
123123
if (c == '+'){
124124
decoded += ' ';
125-
}else if (c == '%') {
125+
} else if (c == '%') {
126126
i++;
127-
code0=source->charAt(i);
127+
code0=source[i];
128128
i++;
129-
code1=source->charAt(i);
129+
code1=source[i];
130130
c = (this->hex2int(code0) << 4) | this->hex2int(code1);
131131
decoded += c;
132132
} else{
@@ -140,13 +140,13 @@ int CLAppComponent::urlDecode(String* decoded, String* source) {
140140
return OS_SUCCESS;
141141
}
142142

143-
int CLAppComponent::urlEncode(String* encoded, String* source) {
143+
int CLAppComponent::urlEncode(String& encoded, const char* source) {
144144
char c;
145145
char code0;
146146
char code1;
147147
char code2;
148-
for (int i =0; i < source->length(); i++){
149-
c=source->charAt(i);
148+
for (int i = 0; i < strlen(source); i++){
149+
c=source[i];
150150
if (c == ' '){
151151
encoded += '+';
152152
} else if (isalnum(c)){

src/app_component.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ class CLAppComponent {
5858
int urlEncode(char * encoded, char * source, size_t len);
5959

6060
unsigned char hex2int(char c);
61-
int urlDecode(String* decoded, String* source);
62-
int urlEncode(String* encoded, String* source);
61+
int urlDecode(String& decoded, const char* source);
62+
int urlEncode(String& encoded, const char* source);
6363

6464

6565
private:

src/app_conn.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ int CLAppConn::start() {
8989
// WiFi.setHostname(mdnsName);
9090

9191
// Initiate network connection request (3rd argument, channel = 0 is 'auto')
92-
WiFi.begin(bestBSSID, stationList[bestStation]->password.c_str(), 0, bestBSSID);
92+
//WiFi.begin(bestBSSID, stationList[bestStation]->password.c_str(), 0, bestBSSID);
93+
WiFi.begin(stationList[bestStation]->ssid.c_str(), stationList[bestStation]->password.c_str());
9394

9495
// Wait to connect, or timeout
9596
unsigned long start = millis();
@@ -231,7 +232,7 @@ int CLAppConn::loadPrefs() {
231232
json["stations"].as<JsonArray>()[i]["pass"] ) {
232233
Station s;
233234
s.ssid = json["stations"].as<JsonArray>()[i]["ssid"].as<String>();
234-
this->urlDecode(&s.password, &json["stations"].as<JsonArray>()[i]["pass"].as<String>());
235+
this->urlDecode(s.password, json["stations"].as<JsonArray>()[i]["pass"].as<String>().c_str());
235236
Serial.println(s.ssid);
236237
stationList[i] = &s;
237238
stationCount++;
@@ -255,7 +256,8 @@ int CLAppConn::loadPrefs() {
255256
load_as_ap = json["accesspoint"].as<bool>();
256257
this->apName = json["ap_ssid"].as<String>().c_str();
257258

258-
this->urlDecode(&this->apPass, &json["ap_pass"].as<String>());
259+
String apPassStr = json["ap_pass"].as<String>();
260+
this->urlDecode(this->apPass, json["ap_pass"].as<String>().c_str());
259261

260262
if(json["ap_channel"]) { this->ap_channel = json["ap_channel"].as<int>(); } else { ap_channel = 1; }
261263
if(json["ap_dhcp"]) { this->ap_dhcp = json["ap_dhcp"].as<bool>(); } else { ap_dhcp = true; }
@@ -272,7 +274,7 @@ int CLAppConn::loadPrefs() {
272274

273275
// OTA
274276
this->otaEnabled = json["ota_enabled"].as<bool>();
275-
this->urlDecode(&this->otaPassword, &json["ota_password"].as<String>());
277+
this->urlDecode(this->otaPassword, json["ota_password"].as<String>().c_str());
276278

277279
// NTP
278280
this->ntpServer = json["ntp_server"].as<String>();
@@ -323,18 +325,22 @@ int CLAppConn::savePrefs() {
323325
uint8_t i=0;
324326
if(index < 0 && this->ssid != "") {
325327
json["stations"][i]["ssid"] = this->ssid;
326-
this->urlEncode(&this->password, &json["stations"][i]["pass"].as<String>());
328+
this->urlEncode(this->password, json["stations"][i]["pass"].as<String>().c_str());
327329
i++;
328330
}
329331

330332
for(int i=0; i < count && stationList[i]; i++) {
331333
json["stations"][i]["ssid"] = stationList[i]->ssid;
332334

333335
if(index >= 0 && i == index) {
334-
this->urlEncode(&json["stations"][i]["pass"].as<String>(), &this->password);
336+
String encString("");
337+
this->urlEncode(encString, this->password.c_str());
338+
json["stations"][i]["pass"] = encString;
335339
}
336340
else {
337-
this->urlEncode(&json["stations"][i]["pass"].as<String>(), &stationList[i]->password);
341+
String encString("");
342+
this->urlEncode(encString, stationList[i]->password.c_str());
343+
json["stations"][i]["pass"] = encString;
338344
}
339345
}
340346
}
@@ -351,11 +357,15 @@ int CLAppConn::savePrefs() {
351357
json["user"] = this->user;
352358
json["pwd"] = this->pwd;
353359
json["ota_enabled"] = this->otaEnabled;
354-
this->urlEncode(&json["ota_password"].as<String>(), &this->otaPassword);
360+
String t("");
361+
this->urlEncode(t, this->otaPassword.c_str());
362+
json["ota_password"] = t;
355363

356364
json["accesspoint"] = this->load_as_ap;
357365
json["ap_ssid"] = this-> apName;
358-
this->urlEncode(&json["ap_pass"].as<String>(), &this->otaPassword);
366+
t = "";
367+
this->urlEncode(t, this->otaPassword.c_str());
368+
json["ap_pass"] = t;
359369
json["ap_dhcp"] = this->ap_dhcp;
360370
if(apIP.ip) json["ap_ip"]["ip"] = apIP.ip->toString();
361371
if(apIP.netmask) json["ap_ip"]["netmask"] = apIP.netmask->toString();

src/app_httpd.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ int CLAppHttpd::start() {
2323
ws = new AsyncWebSocket("/ws");
2424

2525
server->on("/", HTTP_GET, [](AsyncWebServerRequest *request){
26-
if(!request->authenticate(AppConn.getUser(), AppConn.getPwd()))
26+
if(!request->authenticate(AppConn.getUser().c_str(), AppConn.getPwd().c_str()))
2727
return request->requestAuthentication();
2828
if(AppConn.isConfigured())
2929
request->send(Storage.getFS(), "/www/camera.html", "", false, processor);
@@ -32,25 +32,25 @@ int CLAppHttpd::start() {
3232
});
3333

3434
server->on("/camera", HTTP_GET, [](AsyncWebServerRequest *request){
35-
if(!request->authenticate(AppConn.getUser(), AppConn.getPwd()))
35+
if(!request->authenticate(AppConn.getUser().c_str(), AppConn.getPwd().c_str()))
3636
return request->requestAuthentication();
3737
request->send(Storage.getFS(), "/www/camera.html", "", false, processor);
3838
});
3939

4040
server->on("/setup", HTTP_GET, [](AsyncWebServerRequest *request){
41-
if(!request->authenticate(AppConn.getUser(), AppConn.getPwd()))
41+
if(!request->authenticate(AppConn.getUser().c_str(), AppConn.getPwd().c_str()))
4242
return request->requestAuthentication();
4343
request->send(Storage.getFS(), "/www/setup.html", "", false, processor);
4444
});
4545

4646
server->on("/dump", HTTP_GET, [](AsyncWebServerRequest *request){
47-
if(!request->authenticate(AppConn.getUser(), AppConn.getPwd()))
47+
if(!request->authenticate(AppConn.getUser().c_str(), AppConn.getPwd().c_str()))
4848
return request->requestAuthentication();
4949
request->send(Storage.getFS(), "/www/dump.html", "", false, processor);
5050
});
5151

5252
server->on("/view", HTTP_GET, [](AsyncWebServerRequest *request){
53-
if(!request->authenticate(AppConn.getUser(), AppConn.getPwd()))
53+
if(!request->authenticate(AppConn.getUser().c_str(), AppConn.getPwd().c_str()))
5454
return request->requestAuthentication();
5555
if(request->arg("mode") == "stream" ||
5656
request->arg("mode") == "still") {

src/app_httpd.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#include <esp_task_wdt.h>
66
#include <freertos/timers.h>
77

8-
#include "esp32pwm.h"
9-
#include "ESPAsyncWebServer.h"
10-
#include "storage.h"
11-
#include "app_conn.h"
12-
#include "app_cam.h"
8+
#include <esp32pwm.h>
9+
#include <ESPAsyncWebServer.h>
10+
#include <storage.h>
11+
#include <app_conn.h>
12+
#include <app_cam.h>
1313
#include <ArduinoJson.h>
1414

1515
#define MAX_URI_MAPPINGS 32

src/main.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11

2-
#include "app_config.h" // global definitions
3-
#include "storage.h" // Filesystem
4-
#include "app_conn.h" // Conectivity
5-
#include "app_cam.h" // Camera
6-
#include "app_httpd.h" // Web server
7-
#include "camera_pins.h" // Pin Mappings
2+
#include <app_config.h> // global definitions
3+
#include <storage.h> // Filesystem
4+
#include <app_conn.h> // Conectivity
5+
#include <app_cam.h> // Camera
6+
#include <app_httpd.h> // Web server
7+
#include <camera_pins.h> // Pin Mappings
88

99
/*
1010
* This sketch is a extension/expansion/rework of the ESP32 Camera webserer example.
@@ -80,8 +80,8 @@ void setup() {
8080
Serial.begin(115200);
8181
Serial.setDebugOutput(true);
8282

83-
Serial.println("Start ESP32 Cam Webserver");
84-
Serial.println("Initialize....");
83+
Serial.println("Start ESP32 Cam Webserver");
84+
Serial.println("Initialize....");
8585

8686
// Warn if no PSRAM is detected (typically user error with board selection in the IDE)
8787
if(!psramFound()){

0 commit comments

Comments
 (0)