Optimized template

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-11 11:08:54 +02:00
parent be51e2db35
commit ac374dc040
2 changed files with 22 additions and 18 deletions

View File

@ -3,6 +3,7 @@ return
"<!DOCTYPE html>"
"<html>"
"<head>"
"<meta charset=\"UTF-8\">"
"<title>"+String(titel)+"</title>"
"<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css\">"
"<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js\"></script>"
@ -14,7 +15,7 @@ return
"<div class=\"container\">"
"<h1>"+String(titel)+"</h1>"
"<p>An REST-API Arduino microcontroller, which allows you to interact with hardware and the physical environment.</p>"
"<h2>Actors <i class=\"fas fa-cogs\"></i></h2>"
"<h2>Actions <i class=\"fas fa-cogs\"></i></h2>"
"<h3>Remote Plugs <i class=\"fas fa-plug\"></i></h3>"
"<form method=\"get\" >"
"<div class=\"form-group\">"
@ -33,8 +34,11 @@ return
"</div>"
"<input type=\"submit\" class=\"btn btn-secondary\">"
"</form>"
"<h2>Sensors <i class=\"fas fa-thermometer\"></i></h2>"
"<p>The sensor datas can be reached <a href=\"?format=json\">here</a>.</p>"
"<h2>Data <i class=\"fas fa-database\"></i></h2>"
"<pre>"
+ getJson() +
"</pre>"
"<p>The sensor datas in plane text can be reached <a href=\"?format=json\">here</a>.</p>"
"<hr />"
"<p><small>Please check out the <a href=\"https://github.com/kevinveenbirkenbach/physical-interface\">git-repository</a> to get more information about this software.</small></p>"
"</div>"

View File

@ -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());