Skip to content

Commit 6a7cced

Browse files
committed
publish json parse failure message in update config
1 parent f9eb82b commit 6a7cced

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

examples/ESP32/UpdateConfig/UpdateConfig.ino

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,55 @@ int UpdateConfig_Hanlder(char* args, char* actionId) {
128128
DeserializationError err = deserializeJson(doc, args);
129129

130130
if(err) {
131+
Serial.printf("deserializeJson() failed : %s\n", err.c_str());
132+
131133
// publish action failed status
132134
if(!Bytebeam.publishActionFailed(actionId, "Json Deserialization Failed")) {
133135
Serial.println("Failed to publish action failed response for Update Config action");
134136
}
135137

136-
Serial.printf("deserializeJson() failed : %s\n", err.c_str());
137138
return -1;
138139
}
139140

140-
const char* name = doc["name"];
141+
const char* name = doc["name"];
142+
143+
if(name == NULL) {
144+
Serial.println("Error parsing update config name");
145+
146+
// publish action failed status
147+
if(!Bytebeam.publishActionFailed(actionId, "Error parsing update config name")) {
148+
Serial.println("Failed to publish action failed response for Update Config action");
149+
}
150+
151+
return -1;
152+
}
153+
141154
const char* version = doc["version"];
142-
ledDutyCycle = doc["step_value"];
155+
156+
if(version == NULL) {
157+
Serial.println("Error parsing update config version");
158+
159+
// publish action failed status
160+
if(!Bytebeam.publishActionFailed(actionId, "Error parsing update config version")) {
161+
Serial.println("Failed to publish action failed response for Update Config action");
162+
}
163+
164+
return -1;
165+
}
166+
167+
if(doc.containsKey("step_value")) {
168+
// get the led duty cycle
169+
ledDutyCycle = doc["step_value"];
170+
} else {
171+
Serial.println("Error parsing update config step value");
172+
173+
// publish action failed status
174+
if(!Bytebeam.publishActionFailed(actionId, "Error parsing update config step value")) {
175+
Serial.println("Failed to publish action failed response for Update Config action");
176+
}
177+
178+
return -1;
179+
}
143180

144181
// generate the pwm signal
145182
analogWrite(BOARD_LED, ledDutyCycle);

0 commit comments

Comments
 (0)