* # License
* Copyright 2019 Silicon Laboratories Inc.
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
#include "gos.h"
#include "common.h"
extern bool led_value;
* This handles a standard GET request with RESTful arguments
* GET http://<domain>/set_light/<on/off>
gos_result_t set_light_request(const gos_hs_request_t *request, const char *arg)
gos_result_t result;
char buffer[256];
bool value;
if (str_parse_bool(arg, &value) != GOS_SUCCESS)
snprintf(buffer, sizeof(buffer), "<h1>Bad Request</h1>Unknown arg: %s", arg);
return gos_hs_return_status_code(request, 400, buffer);
led_value = value;
GOS_LOG("New LED value: %d", led_value);
int len = sprintf(buffer, "<h3>LED%d value: %d</h3>", PLATFORM_STD_LED, led_value);
if (GOS_FAILED(result, gos_hs_write_reply_header(request, "text/html", len, GOS_HS_RESPONSE_FLAG_NONE)))
else if (GOS_FAILED(result, gos_hs_write_data(request, buffer, len, true)))
return result;