Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function can send String, and standard command can be disabled #140

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions aREST.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
#define LIGHTWEIGHT 0
#endif

// Use light answer mode
#ifndef EXPOSE_STANDARD_COMMANDS
#define EXPOSE_STANDARD_COMMANDS 1
#endif

// Default number of max. exposed variables
#ifndef NUMBER_VARIABLES
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(CORE_WILDFIRE) || defined(ESP8266) || !defined(ADAFRUIT_CC3000_H)
Expand Down Expand Up @@ -944,7 +949,7 @@ void process(char c){
}

}

if(EXPOSE_STANDARD_COMMANDS){
// Digital command received ?
if (answer.startsWith("digital")) {command = 'd';}

Expand All @@ -960,7 +965,7 @@ void process(char c){
#endif

}

}
// Variable or function request received ?
if (command == 'u') {

Expand Down Expand Up @@ -1291,13 +1296,15 @@ bool send_command(bool headers) {
if (command == 'f') {

// Execute function
int result = functions[value](arguments);

String result = functions[value](arguments);
// Send feedback to client
if (!LIGHTWEIGHT) {
addToBuffer(F("{\"return_value\": "));
addToBuffer(F("{\"return_value\": \""));
addToBuffer(result);
addToBuffer(F(", "));
addToBuffer(F("\", "));
/*addToBuffer(F("\"ciao\": \""));
addToBuffer(prova);
addToBuffer(F("\","));*/
//addToBuffer(F(", \"message\": \""));
//addToBuffer(functions_names[value]);
//addToBuffer(F(" executed\", "));
Expand Down Expand Up @@ -1481,7 +1488,7 @@ void variable(char * variable_name, String *variable){
}
#endif

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

functions_names[functions_index] = function_name;
functions[functions_index] = f;
Expand Down Expand Up @@ -1916,7 +1923,7 @@ void setMQTTServer(char* new_mqtt_server){

// Functions array
uint8_t functions_index;
int (*functions[NUMBER_FUNCTIONS])(String);
String (*functions[NUMBER_FUNCTIONS])(String);
char * functions_names[NUMBER_FUNCTIONS];

// Memory debug
Expand Down