summaryrefslogtreecommitdiff
path: root/minion/src/gymnasiearbete.cpp
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2022-05-23 15:27:49 +0200
committerHampusM <hampus@hampusmat.com>2022-05-23 15:27:49 +0200
commitfb4ffea4161c3ac88eeb43bc886fab63dfdc3891 (patch)
tree9a268ac6950873f6c80fdec7c95ed52dc5521d09 /minion/src/gymnasiearbete.cpp
parent0ef43baf0fc5db3a069047ac4f06bf20227f63b5 (diff)
feat(minion): add response headers
Diffstat (limited to 'minion/src/gymnasiearbete.cpp')
-rw-r--r--minion/src/gymnasiearbete.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/minion/src/gymnasiearbete.cpp b/minion/src/gymnasiearbete.cpp
index a7f1e31..5c4f725 100644
--- a/minion/src/gymnasiearbete.cpp
+++ b/minion/src/gymnasiearbete.cpp
@@ -116,6 +116,12 @@ void loop()
const auto temperature_sensor_status = temperature_sensor.read_temperature();
+ const char *response_headers[] = { "Access-Control-Allow-Origin: *",
+ "Content-Type: application/json" };
+
+ const auto response_header_cnt =
+ sizeof(response_headers) / sizeof(response_headers[0]);
+
if (temperature_sensor_status != TemperatureSensorStatus::OK)
{
Serial.print("Error: ");
@@ -124,6 +130,8 @@ void loop()
wifi_module.send_response(
connection,
HTTP_RESPONSE_STATUS_INTERNAL_SERVER_ERROR,
+ response_headers,
+ response_header_cnt,
R"({"error": "Internal server error"})"
);
@@ -137,14 +145,19 @@ void loop()
snprintf(
response_data,
RESPONSE_DATA_MAX_LENGTH,
- "{ %s: { %s: %u } }",
+ "{ %s: { %s: %u} }",
R"("data")",
R"("temperature")",
temperature_sensor.temperature()
);
- const auto send_response_ok =
- wifi_module.send_response(connection, HTTP_RESPONSE_STATUS_OK, response_data);
+ const auto send_response_ok = wifi_module.send_response(
+ connection,
+ HTTP_RESPONSE_STATUS_OK,
+ response_headers,
+ response_header_cnt,
+ response_data
+ );
if (!send_response_ok)
{