more json optimization:
- reduce allocated size using correct const/not const char* - double buffer size for input serial
This commit is contained in:
parent
c61880db57
commit
ed755abb14
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
|
|
||||||
RCSwitch mySwitch = RCSwitch();
|
RCSwitch mySwitch = RCSwitch();
|
||||||
SerialReader<100> serialReader;
|
SerialReader<200> serialReader;
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
digitalWrite(RESET_PIN, HIGH);
|
digitalWrite(RESET_PIN, HIGH);
|
||||||
@ -63,7 +63,7 @@ void readRcSwitch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void handleJsonError(DeserializationError err, const char* cmd) {
|
void handleJsonError(DeserializationError err, const char* cmd) {
|
||||||
StaticJsonDocument<150> jsonError;
|
StaticJsonDocument<50> jsonError;
|
||||||
JsonObject error = jsonError.createNestedObject("error");
|
JsonObject error = jsonError.createNestedObject("error");
|
||||||
error["msg"] = err.c_str();
|
error["msg"] = err.c_str();
|
||||||
error["orig_cmd"] = cmd;
|
error["orig_cmd"] = cmd;
|
||||||
@ -71,8 +71,8 @@ void handleJsonError(DeserializationError err, const char* cmd) {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void runJsonCommand(const char* cmd) {
|
void runJsonCommand(char* cmd) {
|
||||||
StaticJsonDocument<100> jsonDoc;
|
StaticJsonDocument<50> jsonDoc;
|
||||||
DeserializationError err = deserializeJson(jsonDoc, cmd);
|
DeserializationError err = deserializeJson(jsonDoc, cmd);
|
||||||
if (err == DeserializationError::Ok) {
|
if (err == DeserializationError::Ok) {
|
||||||
if (jsonDoc.containsKey("rcSwitch")) {
|
if (jsonDoc.containsKey("rcSwitch")) {
|
||||||
@ -90,7 +90,7 @@ void runJsonCommand(const char* cmd) {
|
|||||||
|
|
||||||
void readCommand() {
|
void readCommand() {
|
||||||
if (serialReader.readLine(Serial) > 0) {
|
if (serialReader.readLine(Serial) > 0) {
|
||||||
const char* cmd = serialReader.getBuffer();
|
char* cmd = serialReader.getBuffer();
|
||||||
if (strcmp("reset", cmd) == 0) {
|
if (strcmp("reset", cmd) == 0) {
|
||||||
Serial.println("resetting...");
|
Serial.println("resetting...");
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user