Added Database connection
This commit is contained in:
51
RestServer/humidityserver/src/datatypes.h
Normal file
51
RestServer/humidityserver/src/datatypes.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#ifndef DATATYPES_H
|
||||||
|
#define DATATYPES_H
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <ngrest/common/Nullable.h>
|
||||||
|
|
||||||
|
namespace ngrest {
|
||||||
|
namespace humidityserver {
|
||||||
|
|
||||||
|
// *table: stats
|
||||||
|
struct stat
|
||||||
|
{
|
||||||
|
// *pk: true
|
||||||
|
// *autoincrement: true
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int node_id;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int pin;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float humidity;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float temperature;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int isoutside;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float gm3;
|
||||||
|
|
||||||
|
// *type: timestamp
|
||||||
|
// *default: CURRENT_TIMESTAMP
|
||||||
|
// *ignoreOnInsert: true
|
||||||
|
std::string created_at;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace humidityserver
|
||||||
|
} // namespace ngrest
|
||||||
|
|
||||||
|
#endif
|
@@ -3,12 +3,58 @@
|
|||||||
|
|
||||||
#include "humidityserver.h"
|
#include "humidityserver.h"
|
||||||
#include "calculate.h"
|
#include "calculate.h"
|
||||||
|
#include <ngrest/common/Nullable.h>
|
||||||
|
|
||||||
|
//#include "datatypes.h"
|
||||||
/*std::string humidityserver::echo(const std::string& text)
|
/*std::string humidityserver::echo(const std::string& text)
|
||||||
{
|
{
|
||||||
return "Hi, " + text;
|
return "Hi, " + text;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
float humidityserver::absolutehumidity(float temperature, float humidity) {
|
struct stat
|
||||||
|
{
|
||||||
|
// *pk: true
|
||||||
|
// *autoincrement: true
|
||||||
|
int id;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int node_id;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int pin;
|
||||||
|
|
||||||
return absoluteHumidityFloat(temperature, humidity);
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float humidity;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float temperature;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: int
|
||||||
|
int isoutside;
|
||||||
|
|
||||||
|
// *unique: false
|
||||||
|
// *type: float
|
||||||
|
float gm3;
|
||||||
|
|
||||||
|
// *type: timestamp
|
||||||
|
// *default: CURRENT_TIMESTAMP
|
||||||
|
// *ignoreOnInsert: true
|
||||||
|
std::string created_at;
|
||||||
|
};
|
||||||
|
|
||||||
|
float humidityserver::absolutehumidity(float temperature, float humidity) {
|
||||||
|
ngrest::MySqlDb mysqlDb({"stats", "dhtuser", "raspberry"});
|
||||||
|
ngrest::Table<stat> stats(&mySqlDb);
|
||||||
|
//Format: node_id, pin, humidity, temperature, gm3, isoutside
|
||||||
|
int node_id = 1;
|
||||||
|
int pin = 0;
|
||||||
|
int isoutside = 0;
|
||||||
|
float absHum = absoluteHumidityFloat(temperature, humidity);
|
||||||
|
stats.insert({node_id, pin, humidity, temperature, absHum, isoutside});
|
||||||
|
return absHum;
|
||||||
}
|
}
|
||||||
|
@@ -4,6 +4,8 @@
|
|||||||
#ifndef HUMIDITYSERVER_H
|
#ifndef HUMIDITYSERVER_H
|
||||||
#define HUMIDITYSERVER_H
|
#define HUMIDITYSERVER_H
|
||||||
|
|
||||||
|
#include <ngrest/db/Table.h>
|
||||||
|
#include <ngrest/db/MySqlDb.h>
|
||||||
#include <ngrest/common/Service.h>
|
#include <ngrest/common/Service.h>
|
||||||
|
|
||||||
//! Dummy description for the service
|
//! Dummy description for the service
|
||||||
@@ -16,6 +18,9 @@ public:
|
|||||||
// *method: GET
|
// *method: GET
|
||||||
// *location: /abshum?temperature={temperature}&humidity={humidity}
|
// *location: /abshum?temperature={temperature}&humidity={humidity}
|
||||||
float absolutehumidity(float temperature, float humidity);
|
float absolutehumidity(float temperature, float humidity);
|
||||||
|
private:
|
||||||
|
//Format: Table, User, Password
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user