Skip to content

Commit

Permalink
created service to getData from greenhouse
Browse files Browse the repository at this point in the history
  • Loading branch information
potier97 committed Sep 9, 2020
1 parent 0a29650 commit a7bcfbc
Show file tree
Hide file tree
Showing 24 changed files with 649 additions and 27 deletions.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
4 changes: 0 additions & 4 deletions comandos.txt

This file was deleted.

4 changes: 0 additions & 4 deletions main.py

This file was deleted.

Empty file modified notas.txt
100644 → 100755
Empty file.
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

53 changes: 53 additions & 0 deletions rf24/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#############################################################################
#
# Makefile for librf24 examples on Raspberry Pi
#
# License: GPL (General Public License)
# Author: gnulnulf <[email protected]>
# Date: 2013/02/07 (version 1.0)
#
# Description:
# ------------
# use make all and make install to install the examples
# You can change the install directory by editing the prefix line
#
prefix := /usr/local

ARCH=armv6zk
ifeq "$(shell uname -m)" "armv7l"
ARCH=armv7-a
endif

# Detect the Raspberry Pi from cpuinfo
#Count the matches for BCM2708 or BCM2709 in cpuinfo
RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2708)
ifneq "${RPI}" "1"
RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2709)
endif

ifeq "$(RPI)" "1"
# The recommended compiler flags for the Raspberry Pi
CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=$(ARCH) -mtune=arm1176jzf-s -std=c++0x
endif


# define all programs
PROGRAMS = createFile addFile telemetryNetwork
SOURCES = ${PROGRAMS:=.cpp}

all: ${PROGRAMS}

${PROGRAMS}: ${SOURCES}
g++ ${CCFLAGS} -Wall -I../ $@.cpp -lrf24-bcm -lrf24network -lsqlite3 -o $@

clean:
rm -rf $(PROGRAMS)

install: all
test -d $(prefix) || mkdir $(prefix)
test -d $(prefix)/bin || mkdir $(prefix)/bin
for prog in $(PROGRAMS); do \
install -m 0755 $$prog $(prefix)/bin; \
done

.PHONY: install
Empty file modified rf24/README.md
100644 → 100755
Empty file.
Binary file added rf24/addFile
Binary file not shown.
88 changes: 88 additions & 0 deletions rf24/addFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <ctime>

using namespace std;



int main()
{

time_t ttime = time(0);
tm* gmt_time = localtime(&ttime);

//time_t ttime = time(0);
/*//tm* gmt_time = localtime(&ttime);
cout << gmt_time->tm_mday << "/"
<< 1 + gmt_time->tm_mon << "/"
<< 1900 + gmt_time->tm_year << " "
<< gmt_time->tm_hour << ":"
<< gmt_time->tm_min << ":"
<< gmt_time->tm_sec << endl;*/

//Date
int day = gmt_time->tm_mday;
int month = 1 + gmt_time->tm_mon;
int year = 1900 + gmt_time->tm_year;
//Hour
int hour = gmt_time->tm_hour;
int min = gmt_time->tm_min;
int second = gmt_time->tm_sec;
string space = " ";
string slash = "/"; string points = ":"; string fecha = to_string(day) + slash + to_string(month) + slash + to_string(year) + space + to_string(hour) + points + to_string(min) + points + to_string(second);
printf("%s\n",fecha.c_str());

/*
// file pointer
std::fstream fout;
// opens an existing csv file or creates a new file.
fout.open("weatherData.csv", ios::out | ios::app);
//Header Doc
fout << << ", "
<< 11 << ", "
<< 11 << ", "
<< 11 << ", "
<< 11 << ", "
<< 11 << ", "
<< 11 << ", "
<< 11 << ", "
<< 22 << ", "
<< 22 << ", "
<< 22 << ", "
<< 22 << ", "
<< 22 << ", "
<< 22 << ", "
<< 22 << ", "
<< 33 << ", "
<< 33 << ", "
<< 33 << ", "
<< 33 << ", "
<< 33 << ", "
<< 33 << ", "
<< 33 << ", "
<< 44 << ", "
<< 44 << ", "
<< 44 << ", "
<< 44 << ", "
<< 44 << ", "
<< 44 << ", "
<< 44 << ", "
<< 55 << ", "
<< 55 << ", "
<< 55 << ", "
<< 55 << ", "
<< 55 << ", "
<< 55 << ", "
<< 55 <<"\n";
fout.close();
*/
}
Binary file added rf24/createFile
Binary file not shown.
60 changes: 60 additions & 0 deletions rf24/createFile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include <iostream>
#include <stdio.h>
#include <fstream>

using namespace std;


int main()
{
// file pointer
std::fstream fout;
// opens an existing csv file or creates a new file.
fout.open("weatherData.csv", ios::out | ios::app);

//Header Doc
fout << "dateCaptured" << ", "
<< "airTempSensationOne" << ", "
<< "airHumSensationOne" << ", "
<< "airTempOne" << ", "
<< "airHumOne" << ", "
<< "earthTempOne" << ", "
<< "earthHumOne" << ", "
<< "lightOne" << ", "

<< "airTempSensationTwo" << ", "
<< "airHumSensationTwo" << ", "
<< "airTempTwo" << ", "
<< "airHumTwo" << ", "
<< "earthTempTwo" << ", "
<< "earthHumTwo" << ", "
<< "lightTwo" << ", "

<< "airTempSensationThree" << ", "
<< "airHumSensationThree" << ", "
<< "airTempThree" << ", "
<< "airHumThree" << ", "
<< "earthTempThree" << ", "
<< "earthHumThree" << ", "
<< "lightThree" << ", "

<< "airTempSensationFour" << ", "
<< "airHumSensationFour" << ", "
<< "airTempFour" << ", "
<< "airHumFour" << ", "
<< "earthTempFour" << ", "
<< "earthHumFour" << ", "
<< "lightFour" << ", "

<< "airTempSensationFive" << ", "
<< "airHumSensationFive" << ", "
<< "airTempFive" << ", "
<< "airHumFive" << ", "
<< "earthTempFive" << ", "
<< "earthHumFive" << ", "
<< "lightFive" << ", "
<< "statusCloud" << ", "
<< "timeSent" << "\n";

fout.close();
}
1 change: 0 additions & 1 deletion rf24/main.py

This file was deleted.

48 changes: 48 additions & 0 deletions rf24/notas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//crear base de dados desde terminal
sqlite3 sensordata.db

//Iniciar a crear tablas dentro de db sensordata
BEGIN;

//crear tablas
CREATE TABLE greenhouseData (id INTEGER PRIMARY KEY AUTOINCREMENT, currentdate DATE, airTempSensationOne REAL, airHumSensationOne REAL, airTempOne REAL, airHumOne REAL, earthTempOne REAL, earthHumOne REAL, lightOne INTEGER, airTempSensationTwo REAL, airHumSensationTwo REAL, airTempTwo REAL, airHumTwo REAL, earthTempTwo REAL, earthHumTwo REAL, lightTwo INTEGER, airTempSensationThree REAL, airHumSensationThree REAL, airTempThree REAL, airHumThree REAL, earthTempThree REAL, earthHumThree REAL, lightThree INTEGER, airTempSensationFour REAL, airHumSensationFour REAL, airTempFour REAL, airHumFour REAL, earthTempFour REAL, earthHumFour REAL, lightFour INTEGER, airTempSensationFive REAL, airHumSensationFive REAL, airTempFive REAL, airHumFive REAL, earthTempFive REAL, earthHumFive REAL, lightFive INTEGER);


//EJECUTAR TODOS LOS DATOS
COMMIT;



//VER LAS TABLAS CREADAS
.tables


//ver el esquema de la tablas
.fullschema


//INSERT
sqlite> BEGIN;
sqlite> INSERT INTO dhtreadings (temperatura , humedad , fecha actual, hora actual , dispositivo) valores (22.4, 48, fecha ('ahora'), hora ('ahora'), "manual");
sqlite> COMMIT;


MAKEFILE SE DEBE MODIFICAR PARA AGREGAR SQLITE
${PROGRAMS}: ${SOURCES}
g++ ${CCFLAGS} -Wall -I../ [email protected] -lrf24-bcm -lrf24network -lsqlite3 -o $@



//Modificar tabla desde el cli de SQLITE

sqlite> SELECT * FROM greenhouseData;
1|2020-08-09 08:26:05|1.95|1.06|1.0|13.1|19.3|8.9|12.6|1.95|1.06|1.0|13.1|19.3|8.9|12.6|1.95|1.06|1.0|13.1|19.3|8.9|12.6|1.95|1.06|1.0|13.1|19.3|8.9|12.6|1.95|1.06|1.0|13.1|19.3|8.9|12.6
2|2020-08-09 08:26:09|1.67|1.68|17.3|3.7|3.7|16.2|2.7|1.67|1.68|17.3|3.7|3.7|16.2|2.7|1.67|1.68|17.3|3.7|3.7|16.2|2.7|1.67|1.68|17.3|3.7|3.7|16.2|2.7|1.67|1.68|17.3|3.7|3.7|16.2|2.7

//BORRA TODOS LOS REGUISTROS DE LA TABLA
sqlite> DELETE FROM greenhouseData;
//REINICIA EL CONTADOR DE LA TABLA
sqlite> UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='greenhouseData';
//SALE DEL CLI
sqlite> .quit

File renamed without changes.
15 changes: 15 additions & 0 deletions rf24/telemetryData.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=Service cron to get data of Nodes in greenhouse and save in csv and sqliteDB
After=multi-user.target

[Service]
Type=idle
ExecStart=/home/pi/iot/rf24/telemetryNetwork
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

Binary file added rf24/telemetryNetwork
Binary file not shown.
Loading

0 comments on commit a7bcfbc

Please sign in to comment.