I fixed the line that caused compiling warnings.
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'char* TimeToString(long unsigned int)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:220:16: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int' [-Wformat=]
220 | sprintf(str, "%02ld:%02d:%02d.%03d", h, m, s, ms);
| ^~~~~~~~~~~~~~~~~~~~~~ ~
| |
| int
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'void initOLED()':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:307:7: warning: unused variable 'ylineHeight' [-Wunused-variable]
307 | int ylineHeight = DISPLAY_HIGHT / 3;
| ^~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'bool saveModelJson(String)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:661:38: warning: 'bool ArduinoJson::V742PB22::JsonDocument::containsKey(const TString&) const [with TString = String; typename ArduinoJson::V742PB22::detail::enable_if<ArduinoJson::V742PB22::detail::IsString<TString>::value, int>::type <anonymous> = 0]' is deprecated: use doc[key].is<T>() instead [-Wdeprecated-declarations]
661 | if (jsonDoc.containsKey(modelName)) {
| ^
In file included from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:42,
from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,
from C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:110:
c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Document/JsonDocument.hpp:176:8: note: declared here
176 | bool containsKey(const TString& key) const {
| ^~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'bool openModelJson(String)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:710:38: warning: 'bool ArduinoJson::V742PB22::JsonDocument::containsKey(const TString&) const [with TString = String; typename ArduinoJson::V742PB22::detail::enable_if<ArduinoJson::V742PB22::detail::IsString<TString>::value, int>::type <anonymous> = 0]' is deprecated: use doc[key].is<T>() instead [-Wdeprecated-declarations]
710 | if (jsonDoc.containsKey(modelName)) {
| ^
In file included from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:42,
from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,
from C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:110:
c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Document/JsonDocument.hpp:176:8: note: declared here
176 | bool containsKey(const TString& key) const {
| ^~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'bool deleteModelJson(String)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:763:38: warning: 'bool ArduinoJson::V742PB22::JsonDocument::containsKey(const TString&) const [with TString = String; typename ArduinoJson::V742PB22::detail::enable_if<ArduinoJson::V742PB22::detail::IsString<TString>::value, int>::type <anonymous> = 0]' is deprecated: use doc[key].is<T>() instead [-Wdeprecated-declarations]
763 | if (jsonDoc.containsKey(modelName)) {
| ^
In file included from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:42,
from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,
from C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:110:
c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Document/JsonDocument.hpp:176:8: note: declared here
176 | bool containsKey(const TString& key) const {
| ^~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'void getParameter()':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:876:49: warning: 'bool ArduinoJson::V742PB22::JsonDocument::containsKey(TChar*) const [with TChar = char]' is deprecated: use doc["key"].is<T>() instead [-Wdeprecated-declarations]
876 | if (!error && jsonDoc.containsKey(model.name)) {
| ^
In file included from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.hpp:42,
from c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson.h:9,
from C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:110:
c:\Users\sarve\Documents\Arduino\libraries\ArduinoJson\src/ArduinoJson/Document/JsonDocument.hpp:167:8: note: declared here
167 | bool containsKey(TChar* key) const {
| ^~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'void saveParameter()':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:1039:18: warning: comparison with string literal results in unspecified behavior [-Waddress]
1039 | if (model.name != "") {
| ~~~~~~~~~~~^~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'bool handleFileRead(String)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:1160:12: warning: unused variable 'sent' [-Wunused-variable]
1160 | size_t sent = server.streamFile(file, contentType);
| ^~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'bool httpsUpdate(uint8_t)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:1220:26: warning: unused parameter 'command' [-Wunused-parameter]
1220 | bool httpsUpdate(uint8_t command) {
| ~~~~~~~~^~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino: In function 'char* TimeToString(long unsigned int)':
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:220:16: warning: '%03d' directive writing between 3 and 6 bytes into a region of size between 2 and 4 [-Wformat-overflow=]
220 | sprintf(str, "%02ld:%02d:%02d.%03d", h, m, s, ms);
| ^~~~~~~~~~~~~~~~~~~~~~
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:220:16: note: directive argument in the range [-59000, 59999]
C:\Users\sarve\Documents\Arduino\CG_scale-master\CG_scale\CG_scale.ino:220:10: note: 'sprintf' output between 13 and 18 bytes into a destination of size 13
220 | sprintf(str, "%02ld:%02d:%02d.%03d", h, m, s, ms);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here is the fixed code prepared by Claude.AI:
Just delete the .txt extension.
@nightflyer88 could you review and implement this code?
CG_scale.ino.txt
These are the changes:
1. Format specifier warning (Line 220)
cpp// Current problematic code:
sprintf(str, "%02ld:%02d:%02d.%03d", h, m, s, ms);
Fix: Change %02ld to %02d since h is an int, not a long:
cppsprintf(str, "%02d:%02d:%02d.%03d", h, m, s, ms);
2. Unused variable warning (Line 307)
// Remove this line or use the variable:
int ylineHeight = DISPLAY_HIGHT / 3; // Remove if not needed
3. Deprecated ArduinoJson containsKey() warnings (Lines 661, 710, 763, 876)
Replace all instances of containsKey() with the new syntax:
cpp// Old way:
if (jsonDoc.containsKey(modelName)) {
// New way:
if (jsonDoc[modelName].is<JsonObject>()) {
4. String comparison warning (Line 1039)
cpp// Current problematic code:
if (model.name != "") {
// Fix:
if (strlen(model.name) != 0) {
// OR
if (String(model.name) != "") {
5. Unused variables (Lines 1160, 1220)
size_t sent = server.streamFile(file, contentType);
(void)sent; // Cast to void to suppress warning
// Line 1220 - Add (void) to suppress unused parameter warning:
bool httpsUpdate(uint8_t command) {
(void)command; // Add this line at the start of the function
// ... rest of function
}
6. Buffer overflow warning (Line 220)
The sprintf buffer might be too small. Increase the buffer size:
cpp// In the TimeToString function, make sure your buffer is large enough:
char str[20]; // Instead of char str[13]
I fixed the line that caused compiling warnings.
Here is the fixed code prepared by Claude.AI:
Just delete the .txt extension.
@nightflyer88 could you review and implement this code?
CG_scale.ino.txt
These are the changes:
1. Format specifier warning (Line 220)
2. Unused variable warning (Line 307)
3. Deprecated ArduinoJson containsKey() warnings (Lines 661, 710, 763, 876)
4. String comparison warning (Line 1039)
5. Unused variables (Lines 1160, 1220)
6. Buffer overflow warning (Line 220)