summaryrefslogtreecommitdiff
path: root/minion/src/gymnasiearbete.cpp
diff options
context:
space:
mode:
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)
{