mirror of
https://github.com/kevinveenbirkenbach/physical-interface.git
synced 2024-11-14 14:21:04 +01:00
Saved development process
This commit is contained in:
parent
4758f80d83
commit
c7c9b3f6b5
10
README.md
10
README.md
@ -4,8 +4,14 @@
|
|||||||
|
|
||||||
Software to build up an REST-API on an Arduino based microcontroller, to interact with hardware and the physical environment.
|
Software to build up an REST-API on an Arduino based microcontroller, to interact with hardware and the physical environment.
|
||||||
|
|
||||||
## Todo
|
## Setup
|
||||||
- Implement support for Arduino
|
|
||||||
|
First update the necessary software via typing in:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bash ./scripts/library-update.sh
|
||||||
|
bash ./scripts/board-update.sh
|
||||||
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
The ["GNU AFFERO GENERAL PUBLIC LICENSE"](./LICENSE.txt) applies to this project.
|
The ["GNU AFFERO GENERAL PUBLIC LICENSE"](./LICENSE.txt) applies to this project.
|
||||||
|
44
main/config.h.dist
Normal file
44
main/config.h.dist
Normal 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>";
|
@ -6,10 +6,17 @@
|
|||||||
#include <DHT.h>
|
#include <DHT.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
// Setup ritter actor
|
// Setup pins
|
||||||
const int pin_ritter = 13;
|
const int pin_ritter = 13;
|
||||||
|
const int pin_pir = 14;
|
||||||
|
const int pin_tmp = 12;
|
||||||
const unsigned long ritter_group_address = 13043702;
|
const unsigned long ritter_group_address = 13043702;
|
||||||
|
|
||||||
|
// Setup classes
|
||||||
|
ESP8266WebServer server ( 80 );
|
||||||
NewRemoteTransmitter transmitter(ritter_group_address, pin_ritter);
|
NewRemoteTransmitter transmitter(ritter_group_address, pin_ritter);
|
||||||
|
DHT dht(pin_tmp, DHT11);
|
||||||
|
|
||||||
|
|
||||||
// Switchs the whole group on
|
// Switchs the whole group on
|
||||||
void setRitterGroup(int state)
|
void setRitterGroup(int state)
|
||||||
@ -33,32 +40,38 @@ void setRitterSwitch(int unit, int state)
|
|||||||
Serial.println("\".");
|
Serial.println("\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup DHT sensor
|
|
||||||
const int pin_tmp = 12;
|
|
||||||
DHT dht(pin_tmp, DHT11);
|
|
||||||
|
|
||||||
String getJsonDht(void){
|
String getJsonDht(void){
|
||||||
return "{\"temperature\":\""+String(dht.readTemperature())+"\",\"humidity\":\""+String(dht.readHumidity())+"\"}";
|
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){
|
String getJsonPir(void){
|
||||||
return "{\"motion\":\""+String(digitalRead(pin_pir))+"\"";
|
return "{\"motion\":\""+String(digitalRead(pin_pir))+"\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
String getJson(void){
|
String getJson(void){
|
||||||
return "{\"DHT\":"+String(digitalRead(pirPin))+",\"PIR\":"+String(digitalRead(pirPin))+"}";
|
return "{\"DHT\":"+String(getJsonDht())+",\"PIR\":"+String(getJsonPir())+"}";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup webserver
|
void handleRequest(void){
|
||||||
ESP8266WebServer server ( 80 );
|
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
|
//Arduino-Setup
|
||||||
void setup(void)
|
void setup(void)
|
||||||
{
|
{
|
||||||
|
pinMode(pin_pir, INPUT);
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println("Started program.");
|
Serial.println("Started program.");
|
||||||
//WiFi.softAPdisconnect(true);
|
//WiFi.softAPdisconnect(true);
|
||||||
@ -79,17 +92,5 @@ void setup(void)
|
|||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
if(server.arg("switch") && server.arg("value")){
|
server.handleClient();
|
||||||
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);
|
|
||||||
}
|
}
|
@ -3,7 +3,7 @@
|
|||||||
# This script compiles the program
|
# This script compiles the program
|
||||||
|
|
||||||
# set variables
|
# set variables
|
||||||
ARDUINO_PATH="$HOME/.local/share/umake/ide/arduino/arduino";
|
ARDUINO_PATH="/bin/arduino";
|
||||||
|
|
||||||
# test preconditions
|
# test preconditions
|
||||||
if [ ! -f "$ARDUINO_PATH" ]
|
if [ ! -f "$ARDUINO_PATH" ]
|
||||||
|
Loading…
Reference in New Issue
Block a user