Implement GPS module: add GPS_Init, GPS_Read, and GPS_Data functions; update includes and fix MQ7 references
This commit is contained in:
4
hardware/.vscode/settings.json
vendored
4
hardware/.vscode/settings.json
vendored
@@ -7,7 +7,9 @@
|
|||||||
"functional": "cpp",
|
"functional": "cpp",
|
||||||
"tuple": "cpp",
|
"tuple": "cpp",
|
||||||
"utility": "cpp",
|
"utility": "cpp",
|
||||||
"bmp280.h": "c"
|
"bmp280.h": "c",
|
||||||
|
"random": "cpp",
|
||||||
|
"sstream": "cpp"
|
||||||
},
|
},
|
||||||
"github.copilot.enable": {
|
"github.copilot.enable": {
|
||||||
"*": false,
|
"*": false,
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#define RX 4
|
#define RX 4
|
||||||
#define TX 5
|
#define TX 5
|
||||||
|
|
||||||
#include <SoftwareSerial.h>
|
#include "SoftwareSerial.h"
|
||||||
|
|
||||||
void GPS_Init();
|
void GPS_Init();
|
||||||
|
void GPS_Read();
|
||||||
|
String GPS_Data();
|
||||||
@@ -1,23 +1,15 @@
|
|||||||
<<<<<<< HEAD
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include "json.hpp"
|
|
||||||
#include "rest.hpp"
|
|
||||||
#include "wifi.hpp"
|
|
||||||
#include "test.hpp"
|
|
||||||
#include "mqtt.hpp"
|
|
||||||
|
|
||||||
#define LED 2
|
|
||||||
#define SERVER_IP "192.168.1.178"
|
|
||||||
#define REST_PORT 80
|
|
||||||
#define MQTT_PORT 1883
|
|
||||||
=======
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
|
||||||
#include "JsonTools.hpp"
|
#include "JsonTools.hpp"
|
||||||
#include "RestClient.hpp"
|
#include "RestClient.hpp"
|
||||||
#include "WifiConnection.hpp"
|
#include "WifiConnection.hpp"
|
||||||
#include "MqttClient.hpp"
|
#include "MqttClient.hpp"
|
||||||
|
#include "MQ7.hpp"
|
||||||
|
#include "BMP280.hpp"
|
||||||
|
//#include "test.hpp"
|
||||||
|
|
||||||
uint32_t getChipID();
|
|
||||||
>>>>>>> main
|
#define LED 2
|
||||||
|
#define SERVER_IP "192.168.1.178"
|
||||||
|
#define REST_PORT 80
|
||||||
|
#define MQTT_PORT 1883
|
||||||
|
|||||||
51
hardware/lib/GPS.cpp
Normal file
51
hardware/lib/GPS.cpp
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "GPS.hpp"
|
||||||
|
char c;
|
||||||
|
SoftwareSerial gps(RX, TX);
|
||||||
|
|
||||||
|
void GPS_Init(){
|
||||||
|
// RX, TX
|
||||||
|
|
||||||
|
Serial.begin(115500);
|
||||||
|
gps.begin(9600);
|
||||||
|
Serial.println("GPS Initialized");
|
||||||
|
}
|
||||||
|
|
||||||
|
void GPS_Read(){
|
||||||
|
|
||||||
|
if (gps.available()) {
|
||||||
|
c = gps.read();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//$GPRMC,044235.000,A,4322.0289,N,00824.5210,W,0.39,65.46,020615,,,A*44
|
||||||
|
|
||||||
|
void GPS_Data(const char* data) {
|
||||||
|
char buffer[100];
|
||||||
|
strncpy(buffer, data, sizeof(buffer)); // Copia segura de la cadena
|
||||||
|
buffer[sizeof(buffer) - 1] = '\0'; // Asegura que la cadena termine en '\0'
|
||||||
|
|
||||||
|
char* token = strtok(buffer, ","); // Divide la cadena por comas
|
||||||
|
int index = 0;
|
||||||
|
String check;
|
||||||
|
float lon = 0.0, lat = 0.0;
|
||||||
|
|
||||||
|
while (token != nullptr) {
|
||||||
|
if (index == 2) {
|
||||||
|
check = String(token); // Elemento en la posición 2
|
||||||
|
} else if (index == 3) {
|
||||||
|
lon = atof(token); // Elemento en la posición 3 convertido a float
|
||||||
|
} else if (index == 5) {
|
||||||
|
lat = atof(token); // Elemento en la posición 5 convertido a float
|
||||||
|
}
|
||||||
|
token = strtok(nullptr, ","); // Avanza al siguiente token
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Imprime los resultados
|
||||||
|
Serial.print("Check: ");
|
||||||
|
Serial.println(check);
|
||||||
|
Serial.print("Longitude: ");
|
||||||
|
Serial.println(lon, 6); // 6 decimales para precisión
|
||||||
|
Serial.print("Latitude: ");
|
||||||
|
Serial.println(lat, 6);
|
||||||
|
}
|
||||||
@@ -1,20 +1,20 @@
|
|||||||
#include "MQ7.h"
|
#include "MQ7.hpp"
|
||||||
|
|
||||||
void MQ7_Init()
|
void MQ7_Init()
|
||||||
{
|
{
|
||||||
pinMode(digitalMQ7, INPUT);
|
pinMode(DIGITAL_MQ7, INPUT);
|
||||||
pinMode(analogMQ7, INPUT);
|
pinMode(ANALOG_MQ7, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
void MQ7_Read(float &sensorVolt, float &RSAir, float &R0, float &sensorValue)
|
||||||
{
|
{
|
||||||
analogWrite(analogMQ7, 1023);
|
analogWrite(ANALOG_MQ7, 1023);
|
||||||
delay(60000);
|
delay(60000);
|
||||||
analogWrite(analogMQ7, (1023/5)*1.4 );
|
analogWrite(ANALOG_MQ7, (1023/5)*1.4 );
|
||||||
|
|
||||||
for(int i = 0; i<100; i++)
|
for(int i = 0; i<100; i++)
|
||||||
{
|
{
|
||||||
sensorValue = sensorValue + analogRead(analogMQ7);
|
sensorValue = sensorValue + analogRead(ANALOG_MQ7);
|
||||||
delay(90000);
|
delay(90000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,3 +17,4 @@ lib_deps =
|
|||||||
mikalhart/TinyGPSPlus@^1.0.2
|
mikalhart/TinyGPSPlus@^1.0.2
|
||||||
bblanchon/ArduinoJson@^6.17.3
|
bblanchon/ArduinoJson@^6.17.3
|
||||||
martinl1/BMP280_DEV@^1.0.21
|
martinl1/BMP280_DEV@^1.0.21
|
||||||
|
plerup/EspSoftwareSerial@^8.2.0
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
#include "GPS.h"
|
|
||||||
char c = "";
|
|
||||||
|
|
||||||
|
|
||||||
void GPS_Init(){
|
|
||||||
SoftwareSerial gps(RX, TX); // RX, TX
|
|
||||||
|
|
||||||
Serial.begin(9600);
|
|
||||||
gps.begin(9600);
|
|
||||||
Serial.println("GPS Initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
void GPS_Read(){
|
|
||||||
|
|
||||||
if (gps.available()) {
|
|
||||||
c = gps.read();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
String GPS_Data(char data){
|
|
||||||
char[] c = data.split(",");
|
|
||||||
float lon = c[2];
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -15,6 +15,11 @@ float sensorVolt, sensorValue, RSAir, R0;
|
|||||||
// BMP280
|
// BMP280
|
||||||
float temperature, humidity, pressure, altitude;
|
float temperature, humidity, pressure, altitude;
|
||||||
|
|
||||||
|
// GPS
|
||||||
|
String check;
|
||||||
|
float lon;
|
||||||
|
float lat;
|
||||||
|
|
||||||
uint32_t getChipID()
|
uint32_t getChipID()
|
||||||
{
|
{
|
||||||
uint32_t chipId;
|
uint32_t chipId;
|
||||||
|
|||||||
Reference in New Issue
Block a user