diff --git a/README.md b/README.md index 8277b96..e1cd6ac 100644 --- a/README.md +++ b/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. -## 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. diff --git a/config.h.dist b/config.h.dist deleted file mode 100644 index e69de29..0000000 diff --git a/main/config.h.dist b/main/config.h.dist new file mode 100644 index 0000000..72780d4 --- /dev/null +++ b/main/config.h.dist @@ -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 = +"" +"" + "" + ""+String(titel)+"" + "" + "" + "" + "" + "" + "
" + "

"+String(titel)+"

" + "

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

" + "

Actors

" + "

Remote Plug Interface

" + "
" + "
" + "" + "" + "
" + "
" + "" + "" + "
" + "" + "
" + "

Sensors

" + "

The sensor datas can be reached here.

" + "
" + "

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

" + "
" + "" +""; diff --git a/main.ino b/main/main.ino similarity index 71% rename from main.ino rename to main/main.ino index ff0c784..3f6312f 100644 --- a/main.ino +++ b/main/main.ino @@ -6,10 +6,17 @@ #include #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", "Physical InterfacePlease check out the git-repository to get more information about this software."); - } - delay(100); + server.handleClient(); } diff --git a/scripts/compile.sh b/scripts/compile.sh index d9a0d1a..4c1a7ad 100644 --- a/scripts/compile.sh +++ b/scripts/compile.sh @@ -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" ]