RUI3 (RAK Unified Interface 3) - RAK4631
RAKSystem::atMode

Public Member Functions

bool add (char *cmd, char *usage, char *title, PF_handle handle, unsigned int perm=RAK_ATCMD_PERM_WRITE|RAK_ATCMD_PERM_READ)
 

Member Function Documentation

◆ add()

bool add ( char *  cmd,
char *  usage,
char *  title,
PF_handle  handle,
unsigned int  perm = RAK_ATCMD_PERM_WRITE|RAK_ATCMD_PERM_READ 
)
Description
Provide developers to create AT CMD.
Syntax
api.system.atMode.add(cmd, usage, title, handle, perm)
Parameters
cmdthe cmd to define cmd name
usagethe cmd usage
titlethe cmd title
handlethe handler that this command will execute
permthe cmd execution permission
Returns
Example
uint32_t led_status;

int led_handle(SERIAL_PORT port, char *cmd, stParam *param) {
    if (param->argc == 1 && !strcmp(param->argv[0], "?")) {
        Serial.print(cmd);
        Serial.print("=");
        Serial.println(led_status?"HIGH":"LOW");
    } else if (param->argc == 1) {
        for (int i = 0 ; i < strlen(param->argv[0]) ; i++) {
            if (!isdigit(*(param->argv[0]+i))) {
                return AT_PARAM_ERROR;
            }
        }

        led_status = strtoul(param->argv[0], NULL, 10);
        if (led_status != 0 && led_status != 1) {
            return AT_PARAM_ERROR;
        }

        pinMode(GREEN_LED, OUTPUT);
        pinMode(BLUE_LED, OUTPUT);
        digitalWrite(GREEN_LED, (led_status == 1)?HIGH:LOW);
        digitalWrite(BLUE_LED, (led_status == 1)?HIGH:LOW);
    } else {
        return AT_PARAM_ERROR;
    }

    return AT_OK;
}

void setup()
{
    api.system.atMode.add("LED", "This controls both green and blue LEDs.", "LED", led_handle, RAK_ATCMD_PERM_WRITE | RAK_ATCMD_PERM_READ);
}

void loop()
{
}