diff --git a/README.md b/README.md index 3a72f27..1bac5cb 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ To install the library, simply clone this repository in the /libraries folder of ## API documentation -The API currently supports five type of commands: digital, analog, and mode, variables, and user-defined functions and api-extensions. +The API currently supports five type of commands: digital, analog, and mode, variables, and user-defined functions. ### Digital @@ -189,24 +189,6 @@ You can also define your own functions in your sketch that can be called using t * `rest.function("led",ledControl);` declares the function in the Arduino sketch * `/led?params=0` executes the function -### API-Extensions - -With api-extensions you have the possibility to extend the api by your own subcommands and customized responses. - -You define your api extensions in your sketch that can be called using the REST API. To access an user-defined api-extension defined in your sketch, you have to declare it first, and then call it from with a REST call. Note that all api-extension functions need to have the following signature `void api_extension(aREST *arest, const String& name, const String& request_url)`. For example, if your aREST instance is called "rest" and the function "aquariumController": - * `rest.api_extension("aquarium",aquariumController);` declares the api extension in the Arduino sketch - * `/aquarium/water_limit/lower/set/65` executes the api-extension function and passes the value `"/aquarium/water_limit/lower/set/65"` as the third parameter (`request_url`) into the api-extension function - * You can then customize your JSON result and extend it to something like this: - ``` - { - "sensor-ids": ["100", "101", "102", "103", "104"], - "id": "008", - "name": "dapper_drake", - "hardware": "arduino", - "connected": true - } - ``` - ### Get data about the board You can also access a description of all the variables that were declared on the board with a single command. This is useful to automatically build graphical interfaces based on the variables exposed to the API. This can be done via the following calls: diff --git a/aREST.h b/aREST.h index 0aee8a3..e115893 100644 --- a/aREST.h +++ b/aREST.h @@ -192,7 +192,7 @@ struct Handler { Handler() : include_into_root_answer{false} { } Handler(bool include) : include_into_root_answer{include} { } - virtual void addToBuffer(aREST *arest, const String& name, const String& request_url) const = 0; + virtual void addToBuffer(aREST *arest, const String& name, const String& arguments) const = 0; }; @@ -201,7 +201,7 @@ struct Variable: Handler { virtual void addToBuffer(aREST *arest) const = 0; - void addToBuffer(aREST *arest, const String& name, const String& request_url) const override { + void addToBuffer(aREST *arest, const String& name, const String& arguments) const override { if (LIGHTWEIGHT) { addToBuffer(arest); } else { @@ -231,8 +231,7 @@ struct FunctionHandler: Handler { FunctionHandler(int (*f)(String)) : func{f} { } - void addToBuffer(aREST *arest, const String& name, const String& request_url) const override { - String arguments = extractParams(name, request_url); + void addToBuffer(aREST *arest, const String& name, const String& arguments) const override { int result = func(arguments); if (!LIGHTWEIGHT) { @@ -243,36 +242,6 @@ struct FunctionHandler: Handler { // arest->addToBufferF(F(" executed\", ")); } } - - String extractParams(const String& name, const String& request_url) const { - // We're expecting a string of the form ?xxxxx=, where xxxxx can be almost anything as long as it's followed by an '=' - // Get command -- Anything following the first '=' in answer will be put in the arguments string. - uint16_t header_length = name.length() + 1; // +1 for the '/' at the start - if (request_url.substring(header_length, header_length + 1) == "?") { - // Standard operation --> strip off anything preceeding the first "=", pass the rest to the handler - if(AREST_PARAMS_MODE == 0) { - uint16_t eq_position = request_url.indexOf('=', header_length); // Replacing 'magic number' 8 for fixed location of '=' - if (eq_position != -1) - return request_url.substring(eq_position + 1, request_url.length()); - } - // All params mode --> pass all parameters, if any, to the handler. Handler will be resonsible for parsing - else if(AREST_PARAMS_MODE == 1) { - return request_url.substring(header_length + 1, request_url.length()); - } - } - return String(""); - } -}; - - -struct ApiHandler: Handler { - void (*func)(aREST *, const String&, const String&); - - ApiHandler(void (*f)(aREST *, const String&, const String&)) : func{f} { } - - void addToBuffer(aREST *arest, const String& name, const String& request_url) const override { - func(arest, name, request_url); - } }; public: @@ -313,13 +282,6 @@ void function(const char *name, int (*f)(String)) { } -void api_extension(const char *name, void (*f)(aREST *, const String&, const String&)) { - handlers[handlers_index] = new ApiHandler(f); - handler_names[handlers_index] = name; - handlers_index++; -} - - private: void initialize() { @@ -495,7 +457,7 @@ void reset_status() { reset(); answer = ""; - request_url = ""; + arguments = ""; index = 0; //memset(&buffer[0], 0, sizeof(buffer)); @@ -1182,29 +1144,42 @@ void process(char c) { // Handler request received ? if (command == 'u') { - if (answer.endsWith(" HTTP/") || answer.endsWith("\r")) { - // Check if handler name is registered in array - for (uint8_t i = 0; i < handlers_index; i++) { - if (answer.startsWith(handler_names[i])) { - - // End here - pin_selected = true; - state = 'x'; - - // Set state - command = 'h'; - value = i; - - answer.trim(); - - if (answer.endsWith(" HTTP/")) { - request_url = "/" + answer.substring(0, answer.length() - 6); // length of " HTTP/" - } else { - request_url = "/" + answer; + // Check if handler name is registered in array + for (uint8_t i = 0; i < handlers_index; i++) { + if (answer.startsWith(handler_names[i])) { + + // End here + pin_selected = true; + state = 'x'; + + // Set state + command = 'h'; + value = i; + + answer.trim(); + + // We're expecting a string of the form ?xxxxx=, where xxxxx can be almost anything as long as it's followed by an '=' + // Get command -- Anything following the first '=' in answer will be put in the arguments string. + arguments = ""; + uint16_t header_length = strlen(handler_names[i]); + if (answer.substring(header_length, header_length + 1) == "?") { + uint16_t footer_start = answer.length(); + if (answer.endsWith(" HTTP/")) + footer_start -= 6; // length of " HTTP/" + + // Standard operation --> strip off anything preceeding the first "=", pass the rest to the handler + if(AREST_PARAMS_MODE == 0) { + uint16_t eq_position = answer.indexOf('=', header_length); // Replacing 'magic number' 8 for fixed location of '=' + if (eq_position != -1) + arguments = answer.substring(eq_position + 1, footer_start); + } + // All params mode --> pass all parameters, if any, to the handler. Handler will be resonsible for parsing + else if(AREST_PARAMS_MODE == 1) { + arguments = answer.substring(header_length + 1, footer_start); } - - break; // We found what we're looking for } + + break; // We found what we're looking for } } @@ -1239,23 +1214,19 @@ void process(char c) { // Serial.print("Selected method: "); // Serial.println(method); // } - } else { - answer = ""; } - if (c == '\r' || answer.startsWith("GET /") || answer.startsWith("/")) { - answer = ""; - } + answer = ""; } -// Modifies request_url in place -void urldecode(String &request_url) { +// Modifies arguments in place +void urldecode(String &arguments) { char a, b; int j = 0; - for(int i = 0; i < request_url.length(); i++) { - // %20 ==> request_url[i] = '%', a = '2', b = '0' - if ((request_url[i] == '%') && ((a = request_url[i + 1]) && (b = request_url[i + 2])) && (isxdigit(a) && isxdigit(b))) { + for(int i = 0; i < arguments.length(); i++) { + // %20 ==> arguments[i] = '%', a = '2', b = '0' + if ((arguments[i] == '%') && ((a = arguments[i + 1]) && (b = arguments[i + 2])) && (isxdigit(a) && isxdigit(b))) { if (a >= 'a') a -= 'a'-'A'; if (a >= 'A') a -= ('A' - 10); else a -= '0'; @@ -1264,17 +1235,17 @@ void urldecode(String &request_url) { if (b >= 'A') b -= ('A' - 10); else b -= '0'; - request_url[j] = char(16 * a + b); + arguments[j] = char(16 * a + b); i += 2; // Skip ahead - } else if (request_url[i] == '+') { - request_url[j] = ' '; + } else if (arguments[i] == '+') { + arguments[j] = ' '; } else { - request_url[j] = request_url[i]; + arguments[j] = arguments[i]; } j++; } - request_url.remove(j); // Truncate string to new possibly reduced length + arguments.remove(j); // Truncate string to new possibly reduced length } @@ -1474,19 +1445,15 @@ bool send_command(bool headers, bool decodeArgs) { // Handler selected if (command == 'h') { if (decodeArgs) { - urldecode(request_url); // Modifies request_url + urldecode(arguments); // Modifies arguments } // Send feedback to client if (LIGHTWEIGHT) { - addHandlerToBuffer(value, request_url); + addHandlerToBuffer(value, arguments); } else { addToBufferF(F("{")); - auto bufferPos = index; - addHandlerToBuffer(value, request_url); - if (bufferPos < index) { - // index has changed -> the handler added some stuff to the buffer - addToBufferF(F(", ")); - } + addHandlerToBuffer(value, arguments); + addToBufferF(F(", ")); } } @@ -1901,8 +1868,8 @@ uint8_t esp_12_pin_map(uint8_t pin) { } -void addHandlerToBuffer(uint8_t index, const String& request_url) { - handlers[index]->addToBuffer(this, String(handler_names[index]), request_url); +void addHandlerToBuffer(uint8_t index, const String& arguments) { + handlers[index]->addToBuffer(this, String(handler_names[index]), arguments); } @@ -1954,7 +1921,7 @@ void setMQTTServer(char* new_mqtt_server){ char name[NAME_SIZE]; String id; - String request_url; + String arguments; // Output uffer char buffer[OUTPUT_BUFFER_SIZE]; diff --git a/examples/BLE/BLE.ino b/examples/BLE/BLE.ino index 3fd9c1c..357f09b 100644 --- a/examples/BLE/BLE.ino +++ b/examples/BLE/BLE.ino @@ -25,10 +25,6 @@ Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RD int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -46,9 +42,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id("008"); rest.set_name("ble_drake"); @@ -95,53 +88,3 @@ int ledControl(String command) { digitalWrite(7,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/ESP32/ESP32.ino b/examples/ESP32/ESP32.ino index 255296e..9a12956 100644 --- a/examples/ESP32/ESP32.ino +++ b/examples/ESP32/ESP32.ino @@ -26,7 +26,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); void setup() { @@ -43,9 +42,6 @@ void setup() // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id("1"); rest.set_name("esp32"); @@ -90,53 +86,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/ESP32_cloud/ESP32_cloud.ino b/examples/ESP32_cloud/ESP32_cloud.ino index 5069a7b..fd0d6b3 100644 --- a/examples/ESP32_cloud/ESP32_cloud.ino +++ b/examples/ESP32_cloud/ESP32_cloud.ino @@ -32,7 +32,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); // Functions void callback(char* topic, byte* payload, unsigned int length); @@ -55,9 +54,6 @@ void setup() // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id(device_id); rest.set_name("esp32"); @@ -96,53 +92,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/ESP8266/ESP8266.ino b/examples/ESP8266/ESP8266.ino index c632a42..955274e 100644 --- a/examples/ESP8266/ESP8266.ino +++ b/examples/ESP8266/ESP8266.ino @@ -28,7 +28,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); void setup(void) { @@ -44,9 +43,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id("1"); rest.set_name("esp8266"); @@ -91,53 +87,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/ESP8266_softAP/ESP8266_softAP.ino b/examples/ESP8266_softAP/ESP8266_softAP.ino index a81e323..09a65c8 100644 --- a/examples/ESP8266_softAP/ESP8266_softAP.ino +++ b/examples/ESP8266_softAP/ESP8266_softAP.ino @@ -28,7 +28,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); void setup(void) { @@ -44,9 +43,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id("1"); rest.set_name("esp8266"); @@ -89,53 +85,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/Ethernet/Ethernet.ino b/examples/Ethernet/Ethernet.ino index 99df273..a8c8782 100644 --- a/examples/Ethernet/Ethernet.ino +++ b/examples/Ethernet/Ethernet.ino @@ -28,10 +28,6 @@ aREST rest = aREST(); int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -46,9 +42,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name & ID to the device (ID should be 6 characters long) rest.set_id("008"); rest.set_name("dapper_drake"); @@ -86,53 +79,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/MKR1000/MKR1000.ino b/examples/MKR1000/MKR1000.ino index ea672cb..575084c 100644 --- a/examples/MKR1000/MKR1000.ino +++ b/examples/MKR1000/MKR1000.ino @@ -32,7 +32,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); void setup(void) { @@ -48,9 +47,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id("1"); rest.set_name("mkr1000"); @@ -99,53 +95,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/MKR1000_cloud/MKR1000_cloud.ino b/examples/MKR1000_cloud/MKR1000_cloud.ino index 4ff738d..0ce3944 100644 --- a/examples/MKR1000_cloud/MKR1000_cloud.ino +++ b/examples/MKR1000_cloud/MKR1000_cloud.ino @@ -34,7 +34,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); // Callback function for the cloud connection void callback(char* topic, byte* payload, unsigned int length); @@ -56,9 +55,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id(device_id); rest.set_name("mkr1000"); @@ -93,56 +89,6 @@ int ledControl(String command) { return 1; } -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} - // Handles message arrived on subscribed topic(s) void callback(char* topic, byte* payload, unsigned int length) { diff --git a/examples/MKR1000_cloud_and_local/MKR1000_cloud_and_local.ino b/examples/MKR1000_cloud_and_local/MKR1000_cloud_and_local.ino index 1f27a50..bcde849 100644 --- a/examples/MKR1000_cloud_and_local/MKR1000_cloud_and_local.ino +++ b/examples/MKR1000_cloud_and_local/MKR1000_cloud_and_local.ino @@ -35,7 +35,6 @@ String local_ip = ""; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); // Callback function for the cloud connection void callback(char* topic, byte* payload, unsigned int length); @@ -64,9 +63,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id(device_id); rest.set_name("mkr1000"); @@ -120,56 +116,6 @@ int ledControl(String command) { return 1; } -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} - // Handles message arrived on subscribed topic(s) void callback(char* topic, byte* payload, unsigned int length) { diff --git a/examples/MKR1000_cloud_pro/MKR1000_cloud_pro.ino b/examples/MKR1000_cloud_pro/MKR1000_cloud_pro.ino index ab5a532..ade572a 100644 --- a/examples/MKR1000_cloud_pro/MKR1000_cloud_pro.ino +++ b/examples/MKR1000_cloud_pro/MKR1000_cloud_pro.ino @@ -34,7 +34,6 @@ int humidity; // Declare functions to be exposed to the API int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); // Callback function for the cloud connection void callback(char* topic, byte* payload, unsigned int length); @@ -59,9 +58,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name to device rest.set_name("mkr1000"); @@ -95,56 +91,6 @@ int ledControl(String command) { return 1; } -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} - // Handles message arrived on subscribed topic(s) void callback(char* topic, byte* payload, unsigned int length) { diff --git a/examples/Serial/Serial.ino b/examples/Serial/Serial.ino index 150136e..66f7cb1 100644 --- a/examples/Serial/Serial.ino +++ b/examples/Serial/Serial.ino @@ -17,10 +17,6 @@ aREST rest = aREST(); int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -35,9 +31,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id("2"); rest.set_name("serial"); @@ -63,53 +56,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/WiFi/WiFi.ino b/examples/WiFi/WiFi.ino index a74e100..2221f6b 100644 --- a/examples/WiFi/WiFi.ino +++ b/examples/WiFi/WiFi.ino @@ -26,10 +26,6 @@ WiFiServer server(80); int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup() { // Start Serial @@ -43,9 +39,6 @@ void setup() { rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id("008"); rest.set_name("dapper_drake"); @@ -101,56 +94,6 @@ int ledControl(String command) { return 1; } -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} - void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); diff --git a/examples/WiFi_CC3000/WiFi_CC3000.ino b/examples/WiFi_CC3000/WiFi_CC3000.ino index 869effa..e188512 100644 --- a/examples/WiFi_CC3000/WiFi_CC3000.ino +++ b/examples/WiFi_CC3000/WiFi_CC3000.ino @@ -41,10 +41,6 @@ MDNSResponder mdns; int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -59,9 +55,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id("008"); rest.set_name("mighty_cat"); @@ -145,53 +138,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/WiFi_CC3000_Due/WiFi_CC3000_Due.ino b/examples/WiFi_CC3000_Due/WiFi_CC3000_Due.ino index d2be13b..f966034 100644 --- a/examples/WiFi_CC3000_Due/WiFi_CC3000_Due.ino +++ b/examples/WiFi_CC3000_Due/WiFi_CC3000_Due.ino @@ -40,10 +40,6 @@ MDNSResponder mdns; int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -58,9 +54,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device (ID should be 6 characters long) rest.set_id("1"); rest.set_name("wifi"); @@ -140,53 +133,3 @@ int ledControl(String command) { digitalWrite(6,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/examples/Yun/Yun.ino b/examples/Yun/Yun.ino index 4f03c14..ffe559a 100644 --- a/examples/Yun/Yun.ino +++ b/examples/Yun/Yun.ino @@ -21,10 +21,6 @@ YunServer server(80); int temperature; int humidity; -// Declare functions to be exposed to the API -int ledControl(String command); -void aquariumController(aREST *arest, const String& name, const String& request_url); - void setup(void) { // Start Serial @@ -39,9 +35,6 @@ void setup(void) // Function to be exposed rest.function("led",ledControl); - // API-Extension to be exposed - rest.api_extension("aquarium", aquariumController); - // Give name and ID to device rest.set_id("008"); rest.set_name("mighty_cat"); @@ -70,53 +63,3 @@ int ledControl(String command) { digitalWrite(7,state); return 1; } - -void aquariumController(aREST *arest, const String& name, const String& request_url) { - // check format of request_url - if (request_url == F("/aquarium") - || request_url == F("/aquarium/")) { - // Send feedback to client - if (LIGHTWEIGHT) { - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(",")); - } - auto id = i + 100; - arest->addToBuffer(id); - } - } else { - arest->addToBufferF(F("\"sensor-ids\": [")); - bool isFirstSensor = true; - auto count = 5; - for (uint32_t i = 0; i < count; ++i) { - if (isFirstSensor) { - isFirstSensor = false; - } else { - arest->addToBufferF(F(", ")); - } - arest->addToBufferF(F("\"")); - auto id = i + 100; - arest->addToBuffer(id); - arest->addToBufferF(F("\"")); - } - arest->addToBufferF(F("]")); - } - } else if (request_url.startsWith(F("/aquarium/water_limit/lower/set/"))) { - String args = request_url.substring(32); // 32 = length of "/aquarium/water_limit/lower/set/" - - // Send feedback to client - if (!LIGHTWEIGHT) { - arest->addToBufferF(F("\"message\": \"lower water limit set to ")); - arest->addToBuffer(args); - arest->addToBufferF(F("cm\"")); - } - } else { - arest->addToBufferF(F("\"message\": \"Unknown request_url '")); - arest->addToBuffer(request_url); - arest->addToBufferF(F("'.\"")); - } -} diff --git a/test/.gitignore b/test/.gitignore deleted file mode 100644 index 6db63d3..0000000 --- a/test/.gitignore +++ /dev/null @@ -1,105 +0,0 @@ - -# Created by https://www.gitignore.io/api/python - -### Python ### -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -*.egg-info/ -.installed.cfg -*.egg - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.coverage -.coverage.* -.cache -.pytest_cache/ -nosetests.xml -coverage.xml -*.cover -.hypothesis/ - -# Translations -*.mo -*.pot - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# pyenv -.python-version - -# celery beat schedule file -celerybeat-schedule.* - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ - - -# End of https://www.gitignore.io/api/python diff --git a/test/http_test.py b/test/http_test.py index a98b483..21b2e58 100644 --- a/test/http_test.py +++ b/test/http_test.py @@ -118,17 +118,5 @@ def test_function(self): answer = json.loads(curl_call(target,"/digital/6")) self.assertEqual(answer['return_value'],0) - # API-Extension call check - def test_api_extension(self): - - # Call list of sensors - answer = json.loads(curl_call(target, "/aquarium")) - l = [int(val) for val in answer['sensor-ids']] - self.assertEqual(l, [100, 101, 102, 103, 104]) - - # Call set of limit - answer = json.loads(curl_call(target, "/aquarium/water_limit/lower/set/45")) - self.assertEqual(answer['message'], "lower water limit set to 45cm") - if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/test/lightweight_test.py b/test/lightweight_test.py index 8254b09..893301c 100644 --- a/test/lightweight_test.py +++ b/test/lightweight_test.py @@ -83,17 +83,5 @@ def test_function(self): answer = curl_call(target,"/digital/6") self.assertEqual(int(answer),0) - # API-Extension call check - def test_api_extension(self): - - # Call list of sensors - answer = curl_call(target, "/aquarium") - l = [int(val) for val in answer.split(',')] - self.assertEqual(l, [100, 101, 102, 103, 104]) - - # Call set of limit - answer = curl_call(target, "/aquarium/water_limit/lower/set/45") - self.assertEqual(answer.strip(), "") - if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/test/serial_test.py b/test/serial_test.py index c43fe6c..e1a7e26 100644 --- a/test/serial_test.py +++ b/test/serial_test.py @@ -108,7 +108,7 @@ def test_variable(self): self.assertGreaterEqual(answer['temperature'],0) self.assertLessEqual(answer['temperature'],40) - # Function call check + # Function call check def test_function(self): # Call function @@ -131,19 +131,5 @@ def test_function(self): answer = json.loads(self.serial.readline()) self.assertEqual(answer['return_value'],0) - # API-Extension call check - def test_api_extension(self): - - # Call list of sensors - self.serial.write("/aquarium\r") - answer = json.loads(self.serial.readline()) - l = [int(val) for val in answer['sensor-ids']] - self.assertEqual(l, [100, 101, 102, 103, 104]) - - # Call set of limit - self.serial.write("/aquarium/water_limit/lower/set/45\r") - answer = json.loads(self.serial.readline()) - self.assertEqual(answer['message'], "lower water limit set to 45cm") - if __name__ == '__main__': unittest.main() \ No newline at end of file