Skip to content

Commit

Permalink
Merge branch 'master' into json-quoting
Browse files Browse the repository at this point in the history
  • Loading branch information
eykamp authored Feb 4, 2018
2 parents f230dec + 1b2ca9b commit e5f68fb
Showing 1 changed file with 12 additions and 30 deletions.
42 changes: 12 additions & 30 deletions aREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void handle(HardwareSerial& serial){
if (serial.available()) {

// Handle request
handle_proto(serial,false,1);
handle_proto(serial,false,1,false);

// Answer
sendBuffer(serial,25,1);
Expand Down Expand Up @@ -1339,14 +1339,10 @@ bool send_command(bool headers, bool decodeArgs) {
}
else {
addToBufferF(F("{"));
addToBuffer(variable_names[value], true);
addToBufferF(F("\": "));
variables[value]->addToBuffer(this);
addToBufferF(F(", "));
}
addVariableToBuffer(value);
}
}


// Function selected
if (command == 'f') {

Expand Down Expand Up @@ -1385,13 +1381,8 @@ bool send_command(bool headers, bool decodeArgs) {

else {
if (command != 'r' && command != 'u') {
addToBufferF(F("\"id\": "));
addToBuffer(id, true);
addToBufferF(F(", \"name\": "));
addToBuffer(name, true);
addToBufferF(F(", \"hardware\": "));
addToBuffer(HARDWARE, true);
addToBufferF(F(", \"connected\": true}\r\n"));
addHardwareToBuffer();
addToBufferF(F("\r\n"));
}
}

Expand Down Expand Up @@ -1425,35 +1416,29 @@ virtual void root_answer() {
else {
addToBufferF(F("{\"variables\": {"));

for (uint8_t i = 0; i < variables_index; i++){
for (uint8_t i = 0; i < variables_index; i++) {
addToBuffer(variable_names[i], true);

addToBufferF(F(": "));
variables[i]->addToBuffer(this);

// Add a comma unless this is our last variable
if (i < variables_index - 1) {
addToBufferF(F(", "));
}
}

addToBufferF(F("}, "));
// END
}

// End
addToBufferF(F("\"id\": "));
addToBuffer(id, true);
addToBufferF(F(", \"name\": "));
addToBuffer(name, true);
addToBufferF(F(", \"hardware\": "));
addToBuffer(HARDWARE, true);
addHardwareToBuffer();

#if defined(PubSubClient_h)
addToBufferF(F("\", \"connected\": true}"));
#else
addToBufferF(F("\", \"connected\": true}\r\n"));
#ifndef PubSubClient_h
addToBufferF(F("\r\n"));
#endif
}


void function(char * function_name, int (*f)(String)){

functions_names[functions_index] = function_name;
Expand Down Expand Up @@ -1833,15 +1818,13 @@ uint8_t esp_12_pin_map(uint8_t pin) {

}


void addVariableToBuffer(uint8_t index) {
addToBuffer(variable_names[index], true);
addToBufferF(F(": "));
variables[index]->addToBuffer(this);
addToBufferF(F(", "));
}


void addHardwareToBuffer() {
addToBufferF(F("\"id\": "));
addToBuffer(id, true);
Expand All @@ -1852,7 +1835,6 @@ void addHardwareToBuffer() {
addToBufferF(F(", \"connected\": true}"));
}


// For non AVR boards
#if defined (__arm__)
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
Expand Down

0 comments on commit e5f68fb

Please sign in to comment.