mirror of
https://github.com/kevinveenbirkenbach/physical-interface.git
synced 2024-11-14 06:11:04 +01:00
Finished base
This commit is contained in:
parent
e0b083276a
commit
601a0a016f
@ -1,4 +1,3 @@
|
||||
const String titel = "Physical Interface";
|
||||
// Setup for wifi connection.
|
||||
const char *ssid = ""; //SSID
|
||||
const char *password = ""; //Wlan-Passwort
|
||||
const char *ssid = "";
|
||||
const char *password = "";
|
||||
const char* hostname = "physical-interface";
|
||||
|
@ -5,30 +5,34 @@ String homepage_template(void){
|
||||
"<html>"
|
||||
"<head>"
|
||||
"<meta charset=\"UTF-8\">"
|
||||
"<title>"+String(titel)+"("+ String(hostname) +")</title>"
|
||||
"<title>Physical Interface</title>"
|
||||
"<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">"
|
||||
"<script src=\"https://code.jquery.com/jquery-3.2.1.slim.min.js\" integrity=\"sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN\" crossorigin=\"anonymous\"></script>"
|
||||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js\" integrity=\"sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q\" crossorigin=\"anonymous\"></script>"
|
||||
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\" integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl\" crossorigin=\"anonymous\"></script>"
|
||||
"<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css\">"
|
||||
"<script src=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js\"></script>"
|
||||
"<link href=\"https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css\" rel=\"stylesheet\">"
|
||||
"<script src=\"https://gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js\"></script>"
|
||||
"</head>"
|
||||
"<body>"
|
||||
"<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>Controller <i class=\"fas fa-cogs\"></i></h2>"
|
||||
"<h1>Physical Interface Controller <i class=\"fas fa-cogs\"></i></h1>"
|
||||
"<p>Interact with the physical environment:</p>"
|
||||
"<form method=\"get\" >";
|
||||
for(const char* parameter : PARAMETER_LIST){
|
||||
String parameter_type=getParameterType(parameter);
|
||||
if(parameter_type.equals("boolean")){
|
||||
homepage = homepage +
|
||||
"<div class=\"form-row\">"
|
||||
"<label for=\""+ parameter +"\" class=\"col-sm-2 col-form-label\">"+ parameter +":</label>"
|
||||
"<div class=\"col-sm-10\" >"
|
||||
"<input type=\"checkbox\" data-toggle=\"toggle\" name=\""+ parameter +"\" " + ((server.arg(parameter)=="on") ? String("checked=\"checked\""):String("")) + ">"
|
||||
"<legend class=\"col-form-label col-sm-2 pt-0\">"+ parameter +"</legend>"
|
||||
"<div class=\"col-sm-10\">"
|
||||
"<div class=\"form-check form-check-inline\">"
|
||||
"<input class=\"form-check-input\" type=\"radio\" id=\""+ parameter +"\" value=\"on\" name=\""+ parameter +"\" " + ((server.arg(parameter)=="on") ? String("checked=\"checked\""):String("")) + ">"
|
||||
"<label for=\""+ parameter +"\" class=\"form-check-label\">on</label>"
|
||||
"</div>"
|
||||
"<div class=\"form-check form-check-inline\">"
|
||||
"<input class=\"form-check-input\" type=\"radio\" id=\""+ parameter +"\" value=\"off\" name=\""+ parameter +"\" " + ((server.arg(parameter)=="off") ? String("checked=\"checked\""):String("")) + ">"
|
||||
"<label for=\""+ parameter +"\" class=\"form-check-label\">off</label>"
|
||||
"</div>"
|
||||
"</div>"
|
||||
"</div>";
|
||||
}else{
|
||||
@ -42,14 +46,16 @@ String homepage_template(void){
|
||||
}
|
||||
}
|
||||
homepage = homepage +
|
||||
"<input type=\"submit\" class=\"btn btn-secondary\">"
|
||||
"<div class=\"form-group row\" >"
|
||||
"<div class=\"col-sm-2\" >"
|
||||
"</div>"
|
||||
"<div class=\"col-sm-10\" >"
|
||||
"<input type=\"submit\" class=\"btn btn-secondary btn-block\">"
|
||||
"</div>"
|
||||
"</div>"
|
||||
"</form>"
|
||||
"<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>The data in plane text can be reached <a href=\"?format=json\">here</a>.</p>"
|
||||
"<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>"
|
||||
"<body>"
|
||||
|
@ -20,12 +20,12 @@
|
||||
/**
|
||||
* Define constants
|
||||
*/
|
||||
const uint16_t PIN_RADIO_TRANSMITTER = 13;
|
||||
const uint16_t PIN_RADIO_RECIEVER = 15;
|
||||
const uint16_t PIN_PIR = 14;
|
||||
const uint16_t PIN_DHT = 12;
|
||||
const uint16_t PIN_IR_RECIEVER = 2;
|
||||
const uint16_t PIN_IR_SEND = 4;
|
||||
const uint16_t PIN_RADIO_TRANSMITTER = D7;
|
||||
const uint16_t PIN_RADIO_RECIEVER = D8;
|
||||
const uint16_t PIN_PIR = D1;
|
||||
const uint16_t PIN_DHT = D6;
|
||||
const uint16_t PIN_IR_RECIEVER = D4;
|
||||
const uint16_t PIN_IR_SEND = D2;
|
||||
const uint16_t PIN_LDR = A0;
|
||||
const uint16_t PIN_ACTIVE_BUZZER = D5;
|
||||
|
||||
@ -152,7 +152,9 @@ String getParameterType(const char* parameter){
|
||||
}
|
||||
|
||||
void controller(void){
|
||||
switchSound(server.arg(PARAMETER_SOUND).equals("on"));
|
||||
if(isParameterDefined(PARAMETER_SOUND)){
|
||||
switchSound(server.arg(PARAMETER_SOUND).equals("on"));
|
||||
}
|
||||
if(isParameterDefined(PARAMETER_IR_TYPE) && isParameterDefined(PARAMETER_IR_CODE) && isParameterDefined(PARAMETER_IR_BITS)){
|
||||
sendIrCode(static_cast<decode_type_t>(server.arg(PARAMETER_IR_TYPE).toInt()),server.arg(PARAMETER_IR_CODE).toInt(),server.arg(PARAMETER_IR_BITS).toInt());
|
||||
}
|
||||
@ -170,7 +172,11 @@ void controller(void){
|
||||
* Getter functions
|
||||
*/
|
||||
String getJsonDht(void){
|
||||
return "{\"temperature_celcius\":\""+String(dht.readTemperature())+"\",\"humidity\":\""+String(dht.readHumidity())+"\"}";
|
||||
delay(600); // Somehow this delay is needed to don't get "nan" values
|
||||
String temperature = String(dht.readTemperature());
|
||||
delay(600); // Somehow this delay is needed to don't get "nan" values
|
||||
String humidity = String(dht.readHumidity());
|
||||
return "{\"temperature_celcius\":\""+ temperature +"\",\"relative_humidity\":\""+humidity+"\"}";
|
||||
}
|
||||
|
||||
String getJsonRadio(void){
|
||||
@ -178,12 +184,11 @@ String getJsonRadio(void){
|
||||
}
|
||||
|
||||
String getJsonPir(void){
|
||||
return "{\"motion\":\""+String(digitalRead(PIN_PIR))+"\"}";
|
||||
return "{\"motion\":\""+String((digitalRead(PIN_PIR)==HIGH)?"true":"false")+"\"}";
|
||||
}
|
||||
|
||||
String getJsonLdr(void){
|
||||
float volt = 5.0 /1024.0 * analogRead (PIN_LDR);
|
||||
return "{\"input_volt\":\""+String(volt)+"\"}";
|
||||
return "{\"actual\":\""+String(analogRead (PIN_LDR))+"\",\"minimum\":\"0\",\"maximum\":\"1023\"}";
|
||||
}
|
||||
|
||||
String getJsonIr(void){
|
||||
@ -226,8 +231,6 @@ void handleRequest(void){
|
||||
void setup(void)
|
||||
{
|
||||
Serial.begin(9600);
|
||||
Serial.println("Activate active buzzer.");
|
||||
switchSound(true);
|
||||
Serial.println("Enable PIR.");
|
||||
pinMode(PIN_PIR, INPUT);
|
||||
Serial.println("Enable remote transmitter.");
|
||||
@ -253,7 +256,9 @@ void setup(void)
|
||||
server.onNotFound(handleRequest);
|
||||
server.begin();
|
||||
Serial.println("HTTP server started.");
|
||||
delay(1000);
|
||||
Serial.println("Generate test sound.");
|
||||
switchSound(true);
|
||||
delay(200);
|
||||
switchSound(false);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user