diff --git a/README.md b/README.md index db91c5d..e5dcd0d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # PlantMonitor "Real Plant Book" :chart_with_downwards_trend: :seedling: -Version v0.1-alpha +Version v1.0.0 ### Importante - Este proyecto está financiado 100% por mi mísmo. (Por tal razón crece lentamente). -- Esta es la versión v0.1-alpha. Si bien es completamente funcional, algunas partes del sistema no tienen el mejor diseño ni el código más elegante. +- Esta es la versión v1.0.0. Si bien es completamente funcional, algunas partes del sistema no tienen el mejor diseño ni el código más elegante. - Sientete libre de "forckear" y mejorar. O si crees que puedes ayudarme a mejorar el código, bienvenido seas! - Si crees que es interesante para tu jardín, huerta o invernadero por favor contactame, seguramente podremos hacer algo fantástico juntos! @@ -22,12 +22,13 @@ El sistema también cuenta con una simple API que puede ser consultada públicam ### En el futuro: - Documentar con mayor detalle y traducir a ingles [On going] - - Generar un pequeño invernadero con control de ventilación. [On going] - - Implementar el uso de paneles solares (100% autosustentable). [Pending...] + - Generar un pequeño invernadero con control de ventilación. [Pending] + - Implementar el uso de paneles solares (100% autosustentable). [Investigando...] - Generar el sistema de riego automático. [Pending...] - Generar un Plant Book más completo. [Pending...] - Implementar el uso en Hidroponia. [Pending...] - Implementar desarrollo a una escala mayor. [Pending...] + - Implementar sistema de usuarios para api. [On going...]
diff --git a/infra/API/api.py b/infra/API/api.py index b3b7ece..dc09376 100644 --- a/infra/API/api.py +++ b/infra/API/api.py @@ -44,7 +44,7 @@ def hello(): @app.route('/api/sensor', methods=['GET']) -#@requires_auth +@requires_auth def get_temp(): fields = str(request.args.get('fields')) Qlimit = int(request.args.get('limit')) @@ -52,13 +52,12 @@ def get_temp(): return "Sorry: limit must be less than 20" else: dbClient = InfluxDBClient(host, port, user, password, dbname) - DBquery = dbClient.query('SELECT '+fields+' FROM "IoT" ORDER BY time DESC LIMIT '+str(Qlimit)) + DBquery = dbClient.query('SELECT '+fields+' FROM '+fields+' ORDER BY time DESC LIMIT '+str(Qlimit)) Qoutput = DBquery.raw print(Qoutput) return Qoutput - if __name__ == '__main__': app.run(host='0.0.0.0', port=8080, debug=True) # Open a webserver on port 8090 diff --git a/infra/docker-compose.yml b/infra/docker-compose.yml index d63bbd6..7048646 100644 --- a/infra/docker-compose.yml +++ b/infra/docker-compose.yml @@ -5,18 +5,18 @@ services: image: eclipse-mosquitto:1.5.8 container_name: mosquitto volumes: - - ./srv/mosquitto/:/etc/mosquitto/:ro + - ./srv/mosquitto/:/etc/mosquitto/:rw ports: - "1883:1883" networks: - fullinfra -#----------------- SAVE DATA ----------------------------- +#----------------- INFLUXDB ----------------------------- influxdb: image: influxdb:1.7.10 container_name: influxdb ports: - - "8083" - - "8086" + - "8083:8083" + - "8086:8086" - "8090" volumes: - ./srv/influxdb/data:/var/lib/influxdb:rw @@ -52,7 +52,7 @@ services: - ./grafana/provisioning/:/etc/grafana/provisioning/:ro environment: - GF_SECURITY_ADMIN_USER=admin - - GF_SECURITY_ADMIN_PASSWORD=admin + - GF_SECURITY_ADMIN_PASSWORD=Z4rleng4.Sup3rS3rv3r-1.! - GF_GRAFANA_PLUGIN_LIST="pierosavi-imageit-panel" networks: - fullinfra @@ -83,6 +83,47 @@ services: restart: 'always' networks: - fullinfra +#---------------------- MYSQL ------------------------------ + mysql: + image: mariadb:10.1.19 + container_name: mysql + ports: + - "3306" + restart: 'always' + volumes: + - ./webserver/code/dump.sql:/docker-entrypoint-initdb.d/dump.sql + environment: + MYSQL_DATABASE: 'test' + MYSQL_USER: 'admin' + MYSQL_PASSWORD: 'admin' + MYSQL_ROOT_PASSWORD: 'admin' + networks: + - fullinfra +#---------------------- PHP ------------------------------ + php: + build: + context: php/ + container_name: php + volumes: + - ./webserver/code/:/usr/share/nginx/html:ro + restart: 'always' + networks: + - fullinfra +#---------------------- HTTP ------------------------------ + nginx: + image: nginx + container_name: nginx + ports: + - "80:80" + links: + - mysql + - php + volumes: + - ./webserver/code/:/usr/share/nginx/html:ro + - ./webserver/conf/site.conf:/etc/nginx/conf.d/default.conf:ro + restart: 'always' + networks: + - fullinfra #-------------------- NETWORK ---------------------------- networks: fullinfra: diff --git a/infra/php/Dockerfile b/infra/php/Dockerfile new file mode 100644 index 0000000..c77f04e --- /dev/null +++ b/infra/php/Dockerfile @@ -0,0 +1,2 @@ +FROM php:7.2.7-fpm-alpine3.7 +RUN apk update; apk upgrade; docker-php-ext-install mysqli; docker-php-ext-enable mysqli \ No newline at end of file diff --git a/infra/webserver/code/add.html b/infra/webserver/code/add.html new file mode 100644 index 0000000..2ebf1e7 --- /dev/null +++ b/infra/webserver/code/add.html @@ -0,0 +1,32 @@ + + + Add Data + + + + +

+ +
+ + + + + + + + + + + + + + + + + +
Name
data1
data2
+
+ + + diff --git a/infra/webserver/code/add.php b/infra/webserver/code/add.php new file mode 100644 index 0000000..39ebc99 --- /dev/null +++ b/infra/webserver/code/add.php @@ -0,0 +1,46 @@ + + + Add Data + + + +Name field is empty.
"; + } + + if(empty($data1)) { + echo "Age field is empty.
"; + } + + if(empty($data2)) { + echo "Email field is empty.
"; + } + + //link to the previous pdata1 + echo "
Go Back"; + } else { + // if all the fields are filled (not empty) + + //insert data to database + $result = mysqli_query($mysqli, "INSERT INTO users(name,data1,data2) VALUES('$name','$data1','$data2')"); + + //display success messdata1 + echo "Data added successfully."; + echo "
View Result"; + } +} +?> + + diff --git a/infra/webserver/code/config.php b/infra/webserver/code/config.php new file mode 100644 index 0000000..0adb54e --- /dev/null +++ b/infra/webserver/code/config.php @@ -0,0 +1,11 @@ + diff --git a/infra/webserver/code/delete.php b/infra/webserver/code/delete.php new file mode 100644 index 0000000..c20fef6 --- /dev/null +++ b/infra/webserver/code/delete.php @@ -0,0 +1,14 @@ + + diff --git a/infra/webserver/code/dump.sql b/infra/webserver/code/dump.sql new file mode 100644 index 0000000..3c730af --- /dev/null +++ b/infra/webserver/code/dump.sql @@ -0,0 +1,18 @@ +use test; +DROP TABLE IF EXISTS `users`; +CREATE TABLE `users` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(100) NOT NULL, + `data1` varchar(20) DEFAULT NULL, + `data2` varchar(20) DEFAULT NULL, + `data3` varchar(20) DEFAULT NULL, + `data4` varchar(20) DEFAULT NULL, + `data5` varchar(20) DEFAULT NULL, + `data6` varchar(20) DEFAULT NULL, + `data7` varchar(20) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1; + +LOCK TABLES `users` WRITE; +INSERT INTO `users` VALUES (1,'test01','test01','test01',NULL,NULL,NULL,NULL,NULL),(2,'test02','test02','test02',NULL,NULL,NULL,NULL,NULL); +UNLOCK TABLES; diff --git a/infra/webserver/code/edit.php b/infra/webserver/code/edit.php new file mode 100644 index 0000000..39ac403 --- /dev/null +++ b/infra/webserver/code/edit.php @@ -0,0 +1,81 @@ +Name field is empty.

"; + } + + if(empty($data1)) { + echo "data1 field is empty.
"; + } + + if(empty($data2)) { + echo "data2 field is empty.
"; + } + } else { + //updating the table + $result = mysqli_query($mysqli, "UPDATE users SET name='$name',data1='$data1',data2='$data2' WHERE id=$id"); + + //redirectig to the display pdata1. In our case, it is index.php + header("Location: index.php"); + } +} +?> + + + + Edit Data + + + + Home +

+ +
+ + + + + + + + + + + + + + + + + +
Name
data1
data2
>
+
+ + diff --git a/infra/webserver/code/index.html b/infra/webserver/code/index.html new file mode 100644 index 0000000..df5d106 --- /dev/null +++ b/infra/webserver/code/index.html @@ -0,0 +1 @@ +holaaa :) diff --git a/infra/webserver/code/index.php b/infra/webserver/code/index.php new file mode 100644 index 0000000..7820bab --- /dev/null +++ b/infra/webserver/code/index.php @@ -0,0 +1,36 @@ + + + + + Homepage + + + +



+ + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> +
Namedata1data2Update
".$res['name']."".$res['data1']."".$res['data2']."
+ + diff --git a/infra/webserver/code/info.php b/infra/webserver/code/info.php new file mode 100644 index 0000000..33da5b2 --- /dev/null +++ b/infra/webserver/code/info.php @@ -0,0 +1,2 @@ +\n"; ptr +="\n"; return ptr; -} +} \ No newline at end of file