Compare commits
5 Commits
main
...
feature/GP
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a1972441b | ||
|
|
2e425a04f9 | ||
|
|
9da30e9e79 | ||
|
|
42ad7f7ac9 | ||
|
|
63fda936bb |
5
hardware/.vscode/settings.json
vendored
5
hardware/.vscode/settings.json
vendored
@@ -7,7 +7,10 @@
|
||||
"functional": "cpp",
|
||||
"tuple": "cpp",
|
||||
"utility": "cpp",
|
||||
"bmp280.h": "c"
|
||||
"bmp280.h": "c",
|
||||
"random": "cpp",
|
||||
"sstream": "cpp",
|
||||
"cmath": "cpp"
|
||||
},
|
||||
"github.copilot.enable": {
|
||||
"*": false,
|
||||
|
||||
9
hardware/include/GPS.hpp
Normal file
9
hardware/include/GPS.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#define RX 4
|
||||
#define TX 5
|
||||
|
||||
#include "TinyGPSPlus.h"
|
||||
|
||||
void GPS_Init();
|
||||
void GPS_Read();
|
||||
float GPS_longitud();
|
||||
float GPS_latitud();
|
||||
@@ -1,23 +1,16 @@
|
||||
<<<<<<< HEAD
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "json.hpp"
|
||||
#include "rest.hpp"
|
||||
#include "wifi.hpp"
|
||||
#include "test.hpp"
|
||||
#include "mqtt.hpp"
|
||||
#include "JsonTools.hpp"
|
||||
#include "RestClient.hpp"
|
||||
#include "WifiConnection.hpp"
|
||||
#include "MqttClient.hpp"
|
||||
#include "MQ7.hpp"
|
||||
#include "BMP280.hpp"
|
||||
#include "GPS.hpp"
|
||||
//#include "test.hpp"
|
||||
|
||||
|
||||
#define LED 2
|
||||
#define SERVER_IP "192.168.1.178"
|
||||
#define REST_PORT 80
|
||||
#define MQTT_PORT 1883
|
||||
=======
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "JsonTools.hpp"
|
||||
#include "RestClient.hpp"
|
||||
#include "WifiConnection.hpp"
|
||||
#include "MqttClient.hpp"
|
||||
|
||||
uint32_t getChipID();
|
||||
>>>>>>> main
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "BMP280.h"
|
||||
#include "BMP280.hpp"
|
||||
|
||||
|
||||
void BMP280_Init()
|
||||
|
||||
100
hardware/lib/GPS.cpp
Normal file
100
hardware/lib/GPS.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "GPS.hpp"
|
||||
|
||||
// A sample NMEA stream.
|
||||
const char *gpsStream =
|
||||
"$GPRMC,045103.000,A,3014.1984,N,09749.2872,W,0.67,161.46,030913,,,A*7C\r\n"
|
||||
"$GPGGA,045104.000,3014.1985,N,09749.2873,W,1,09,1.2,211.6,M,-22.5,M,,0000*62\r\n"
|
||||
"$GPRMC,045200.000,A,3014.3820,N,09748.9514,W,36.88,65.02,030913,,,A*77\r\n"
|
||||
"$GPGGA,045201.000,3014.3864,N,09748.9411,W,1,10,1.2,200.8,M,-22.5,M,,0000*6C\r\n"
|
||||
"$GPRMC,045251.000,A,3014.4275,N,09749.0626,W,0.51,217.94,030913,,,A*7D\r\n"
|
||||
"$GPGGA,045252.000,3014.4273,N,09749.0628,W,1,09,1.3,206.9,M,-22.5,M,,0000*6F\r\n";
|
||||
|
||||
// The TinyGPSPlus object
|
||||
TinyGPSPlus gps;
|
||||
|
||||
void GPS_Init()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println(F("BasicExample.ino"));
|
||||
Serial.println(F("Basic demonstration of TinyGPSPlus (no device needed)"));
|
||||
Serial.print(F("Testing TinyGPSPlus library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
|
||||
Serial.println(F("by Mikal Hart"));
|
||||
Serial.println();
|
||||
|
||||
while (*gpsStream)
|
||||
if (gps.encode(*gpsStream++))
|
||||
GPS_Read();
|
||||
|
||||
Serial.println();
|
||||
Serial.println(F("Done."));
|
||||
}
|
||||
|
||||
void GPS_Read()
|
||||
{
|
||||
Serial.print(F("Location: "));
|
||||
if (gps.location.isValid())
|
||||
{
|
||||
Serial.print(gps.location.lat(), 6);
|
||||
Serial.print(F(","));
|
||||
Serial.print(gps.location.lng(), 6);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("INVALID"));
|
||||
}
|
||||
|
||||
Serial.print(F(" Date/Time: "));
|
||||
if (gps.date.isValid())
|
||||
{
|
||||
Serial.print(gps.date.month());
|
||||
Serial.print(F("/"));
|
||||
Serial.print(gps.date.day());
|
||||
Serial.print(F("/"));
|
||||
Serial.print(gps.date.year());
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("INVALID"));
|
||||
}
|
||||
|
||||
Serial.print(F(" "));
|
||||
if (gps.time.isValid())
|
||||
{
|
||||
if (gps.time.hour() < 10) Serial.print(F("0"));
|
||||
Serial.print(gps.time.hour());
|
||||
Serial.print(F(":"));
|
||||
if (gps.time.minute() < 10) Serial.print(F("0"));
|
||||
Serial.print(gps.time.minute());
|
||||
Serial.print(F(":"));
|
||||
if (gps.time.second() < 10) Serial.print(F("0"));
|
||||
Serial.print(gps.time.second());
|
||||
Serial.print(F("."));
|
||||
if (gps.time.centisecond() < 10) Serial.print(F("0"));
|
||||
Serial.print(gps.time.centisecond());
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.print(F("INVALID"));
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
float GPS_longitud(){
|
||||
float log;
|
||||
if (gps.location.isValid())
|
||||
{
|
||||
log = gps.location.lng();
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
float GPS_latitud(){
|
||||
float lat;
|
||||
if (gps.location.isValid())
|
||||
{
|
||||
lat = gps.location.lat();
|
||||
}
|
||||
return lat;
|
||||
}
|
||||
@@ -1,30 +1,40 @@
|
||||
#include "MQ7.h"
|
||||
#include "MQ7.hpp"
|
||||
|
||||
unsigned long tiempoAnterior = 0;
|
||||
const long intervalo1 = 60000;
|
||||
const long intervalo2 = 3000;
|
||||
|
||||
void MQ7_Init()
|
||||
{
|
||||
pinMode(digitalMQ7, INPUT);
|
||||
pinMode(analogMQ7, INPUT);
|
||||
pinMode(DIGITAL_MQ7, INPUT);
|
||||
pinMode(ANALOG_MQ7, INPUT);
|
||||
}
|
||||
|
||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
||||
{
|
||||
analogWrite(analogMQ7, 1023);
|
||||
delay(60000);
|
||||
analogWrite(analogMQ7, (1023/5)*1.4 );
|
||||
unsigned long tiempoActual = millis();
|
||||
|
||||
for(int i = 0; i<100; i++)
|
||||
{
|
||||
sensorValue = sensorValue + analogRead(analogMQ7);
|
||||
delay(90000);
|
||||
if (tiempoActual - tiempoAnterior >= intervalo1){
|
||||
tiempoAnterior = tiempoActual;
|
||||
analogWrite(ANALOG_MQ7, 1023);
|
||||
analogWrite(ANALOG_MQ7, (1023/5)*1.4);
|
||||
}
|
||||
for(int i = 0; i<50; i++)
|
||||
{
|
||||
if (tiempoActual - tiempoAnterior >= intervalo1){
|
||||
tiempoAnterior = tiempoActual;
|
||||
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
||||
}
|
||||
}
|
||||
|
||||
if (tiempoActual - tiempoAnterior >= intervalo1){
|
||||
tiempoAnterior = tiempoActual;
|
||||
sensorValue = sensorValue/100.0;
|
||||
sensorVolt = sensorValue/1024*5.0;
|
||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
||||
R0 = RSAir/(26+(1/3));
|
||||
|
||||
Serial.print("R0 = ");
|
||||
Serial.println(R0);
|
||||
}
|
||||
|
||||
sensorValue = sensorValue/100.0;
|
||||
sensorVolt = sensorValue/1024*5.0;
|
||||
RSAir = (5.0-sensorVolt)/sensorVolt;
|
||||
R0 = RSAir/(26+(1/3));
|
||||
|
||||
Serial.print("R0 = ");
|
||||
Serial.println(R0);
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
@@ -14,6 +14,6 @@ board = esp32dev
|
||||
framework = arduino
|
||||
lib_deps =
|
||||
knolleary/PubSubClient@^2.8
|
||||
mikalhart/TinyGPSPlus@^1.0.2
|
||||
bblanchon/ArduinoJson@^6.17.3
|
||||
martinl1/BMP280_DEV@^1.0.21
|
||||
mikalhart/TinyGPSPlus@^1.1.0
|
||||
|
||||
@@ -8,6 +8,9 @@ BMP280_DEV bme;
|
||||
|
||||
// HTTP Request
|
||||
String response;
|
||||
String payload;
|
||||
const String url = "/api/v1/sensors/:sensorId/values";
|
||||
|
||||
|
||||
// MQ7
|
||||
float sensorVolt, sensorValue, RSAir, R0;
|
||||
@@ -15,6 +18,11 @@ float sensorVolt, sensorValue, RSAir, R0;
|
||||
// BMP280
|
||||
float temperature, humidity, pressure, altitude;
|
||||
|
||||
// GPS
|
||||
String check;
|
||||
float lon;
|
||||
float lat;
|
||||
|
||||
uint32_t getChipID()
|
||||
{
|
||||
uint32_t chipId;
|
||||
@@ -36,8 +44,18 @@ void setup() {
|
||||
// test get
|
||||
getRequest(httpClient, "http://172.20.10.7:8082/api/v1/sensors/1/values", response);
|
||||
deserializeSensorValue(httpClient, httpClient.GET());
|
||||
|
||||
// test gps
|
||||
GPS_Init();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
GPS_Read();
|
||||
lon = GPS_longitud();
|
||||
lat = GPS_latitud();
|
||||
//postRequest(HTTPClient &httpClient, const String url, String &payload, String &response)
|
||||
//String serializeSensorValue(int sensorId, int deviceId, String sensorType, String unit, int sensorStatus, float temperature, float humidity, float carbonMonoxide, float lat, float lon, long timestamp)
|
||||
|
||||
postRequest(httpClient, url, payload, response);
|
||||
}
|
||||
Reference in New Issue
Block a user