From ac374dc0403372fc8125bb09d82319913bf6acbd Mon Sep 17 00:00:00 2001 From: "Kevin Veen-Birkenbach [aka. Frantz]" Date: Mon, 11 May 2020 11:08:54 +0200 Subject: [PATCH] Optimized template --- main/homepage_template.h | 10 +++++++--- main/main.ino | 30 +++++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/main/homepage_template.h b/main/homepage_template.h index 5656ab7..ddcb75d 100644 --- a/main/homepage_template.h +++ b/main/homepage_template.h @@ -3,6 +3,7 @@ return "" "" "" + "" ""+String(titel)+"" "" "" @@ -14,7 +15,7 @@ return "
" "

"+String(titel)+"

" "

An REST-API Arduino microcontroller, which allows you to interact with hardware and the physical environment.

" - "

Actors

" + "

Actions

" "

Remote Plugs

" "
" "
" @@ -33,8 +34,11 @@ return "
" "" "
" - "

Sensors

" - "

The sensor datas can be reached here.

" + "

Data

" + "
"
+         + getJson() +
+      "
" + "

The sensor datas in plane text can be reached here.

" "
" "

Please check out the git-repository to get more information about this software.

" "
" diff --git a/main/main.ino b/main/main.ino index 58a20fc..0bd6087 100644 --- a/main/main.ino +++ b/main/main.ino @@ -23,9 +23,6 @@ // Configuration #include "config.h" -// Templates -#include "homepage_template.h" - // Define Constants const int pin_ritter = 13; const int pin_pir = 14; @@ -121,18 +118,6 @@ void setIrColor(decode_type_t type,int data, int bits) { Serial.print("The code \"" + String(data) + "\" with \"" + String(bits) + "\"was send in format \"" + getDecodeType(type) + "\"."); } -String getJsonDht(void){ - return "{\"temperature\":\""+String(dht.readTemperature())+"\",\"humidity\":\""+String(dht.readHumidity())+"\"}"; -} - -String getJsonPir(void){ - return "{\"motion\":\""+String(digitalRead(pin_pir))+"\""; -} - -String getJson(void){ - return "{\"DHT\":"+String(getJsonDht())+",\"PIR\":"+String(getJsonPir())+"}"; -} - bool isParameterDefined(String parameter_name){ for (uint8_t parameter_index = 0; parameter_index < server.args(); parameter_index++) { if(server.argName(parameter_index)==parameter_name){ @@ -155,6 +140,21 @@ void controller(void){ } } + +String getJsonDht(void){ + return "{\"temperature\":\""+String(dht.readTemperature())+"\",\"humidity\":\""+String(dht.readHumidity())+"\"}"; +} + +String getJsonPir(void){ + return "{\"motion\":\""+String(digitalRead(pin_pir))+"\"}"; +} + +String getJson(void){ + return "{\"DHT\":"+String(getJsonDht())+",\"PIR\":"+String(getJsonPir())+"}"; +} + +#include "homepage_template.h" + void view(void){ if(server.arg("format")=="json"){ server.send ( 200, "text/html", getJson());