Saved development process

This commit is contained in:
Kevin Veen-Birkenbach 2020-05-06 17:26:39 +02:00
parent 4758f80d83
commit c7c9b3f6b5
5 changed files with 79 additions and 28 deletions

View File

@ -4,8 +4,14 @@
Software to build up an REST-API on an Arduino based microcontroller, to interact with hardware and the physical environment.
## Todo
- Implement support for Arduino
## Setup
First update the necessary software via typing in:
```bash
bash ./scripts/library-update.sh
bash ./scripts/board-update.sh
```
## License
The ["GNU AFFERO GENERAL PUBLIC LICENSE"](./LICENSE.txt) applies to this project.

View File

44
main/config.h.dist Normal file
View File

@ -0,0 +1,44 @@
const String titel = "Physical Interface";
// Setup for wifi connection.
const char *ssid = ""; //SSID
const char *password = ""; //Wlan-Passwort
const String homepage =
"<!DOCTYPE html>"
"<html>"
"<head>"
"<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>"
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.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>Actors</h2>"
"<h3>Remote Plug Interface</h3>"
"<form method=\"get\" >"
"<div class=\"form-group\">"
"<label for=\"plug_id\">Plug-ID:</label>"
"<input type=\"number\" class= \"form-control\" id=\"plug_id\" name=\"plug_id\">"
"</div>"
"<div class=\"form-group\">"
"<label class=\"checkbox-inline\" for=\"on\">"
"<input type=\"radio\" id=\"on\" name=\"status\" value=\"1\">"
"on"
"</label>"
"<label class=\"checkbox-inline\" for=\"off\">"
"<input type=\"radio\" id=\"off\" name=\"status\" value=\"0\">"
"off"
"</label>"
"</div>"
"<input type=\"submit\" class=\"btn btn-secondary\">"
"</form>"
"<h2>Sensors</h2>"
"<p>The sensor datas 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>"
"<body>"
"<html>";

View File

@ -6,10 +6,17 @@
#include <DHT.h>
#include "config.h"
// Setup ritter actor
// Setup pins
const int pin_ritter = 13;
const int pin_pir = 14;
const int pin_tmp = 12;
const unsigned long ritter_group_address = 13043702;
// Setup classes
ESP8266WebServer server ( 80 );
NewRemoteTransmitter transmitter(ritter_group_address, pin_ritter);
DHT dht(pin_tmp, DHT11);
// Switchs the whole group on
void setRitterGroup(int state)
@ -33,32 +40,38 @@ void setRitterSwitch(int unit, int state)
Serial.println("\".");
}
// Setup DHT sensor
const int pin_tmp = 12;
DHT dht(pin_tmp, DHT11);
String getJsonDht(void){
return "{\"temperature\":\""+String(dht.readTemperature())+"\",\"humidity\":\""+String(dht.readHumidity())+"\"}";
}
// Setup pin für PIR
const int pin_pir = 14;
pinMode(pin_pir, INPUT);
String getJsonPir(void){
return "{\"motion\":\""+String(digitalRead(pin_pir))+"\"";
}
String getJson(void){
return "{\"DHT\":"+String(digitalRead(pirPin))+",\"PIR\":"+String(digitalRead(pirPin))+"}";
return "{\"DHT\":"+String(getJsonDht())+",\"PIR\":"+String(getJsonPir())+"}";
}
// Setup webserver
ESP8266WebServer server ( 80 );
void handleRequest(void){
if(server.arg("plug_id") && server.arg("status")){
if(server.arg("plug_id")=="group"){
setRitterGroup(server.arg("status").toInt());
}else{
setRitterSwitch(server.arg("plug_id").toInt(),server.arg("status").toInt());
}
}
if(server.arg("format")=="json"){
server.send ( 200, "text/html", getJson());
}else{
server.send ( 200, "text/html", homepage);
}
delay(100);
}
//Arduino-Setup
void setup(void)
{
pinMode(pin_pir, INPUT);
Serial.begin(115200);
Serial.println("Started program.");
//WiFi.softAPdisconnect(true);
@ -79,17 +92,5 @@ void setup(void)
void loop()
{
if(server.arg("switch") && server.arg("value")){
if(server.arg("switch")=="group"){
setRitterGroup(server.arg("value").toInt());
}else{
setRitterSwitch(server.arg("switch").toInt(),server.arg("value").toInt());
}
}
if(server.arg("mode")=="json"){
server.send ( 200, "text/html", getJson());
}else{
server.send ( 200, "text/html", "<html><head><title>Physical Interface</title></head><body>Please check out the <a href=\"https://github.com/kevinveenbirkenbach/physical-interface\">git-repository</a> to get more information about this software.<body><html>");
}
delay(100);
server.handleClient();
}

View File

@ -3,7 +3,7 @@
# This script compiles the program
# set variables
ARDUINO_PATH="$HOME/.local/share/umake/ide/arduino/arduino";
ARDUINO_PATH="/bin/arduino";
# test preconditions
if [ ! -f "$ARDUINO_PATH" ]