develop
Elena 2023-03-09 13:06:18 +01:00
commit 5240f79a3a
6 changed files with 164 additions and 22 deletions

View File

@ -0,0 +1,45 @@
//librerias propias--------------------
#include <GloboSonda.h>
#define PIN_POWERKEY_SIM808 48
#define PIN_RX_SIM808 4
#define PIN_TX_SIM808 5
Sim808Manager sim808;
SoftwareSerial sserial=SoftwareSerial(PIN_RX_SIM808, PIN_TX_SIM808,false);
char buf[1024];
void setup() {
Serial.begin(9600);
Serial.println("Iniciando");
if(!sim808.inicia(&sserial, PIN_POWERKEY_SIM808, 9600))
{
Serial.println("Sim808 join network error");
}
Serial.println("GPS iniciado...");
DataGPSSimManager* coor=sim808.GetGPSValid();
Serial.println("gps iniciado...");
}
void loop(){
char strFecha[24];
char precision[32];
DataGPSSimManager* coor=sim808.GetGPS();
coor->getFecha(strFecha);
Serial.print(strFecha);
Serial.print(" lon: ");
Serial.print(coor->lon);
Serial.print("lat: ");
Serial.println(coor->lat);
Serial.print(" altitud: ");
Serial.print(coor->altitude);
Serial.print("velocidad: ");
Serial.print(coor->speed_kmh);
Serial.print("precision: ");
Serial.print(coor->getPrecision(precision));
delay(20000);
}

View File

@ -0,0 +1,40 @@
#include "stdio.h"
#include <Wire.h>
#include <GloboSonda.h>
#define PIN_DHT22 16
#define TIMER_LOG 3000
//contect d1 -> scl d2->sda
SensorAcelerometro acele;
unsigned long Timer=0;
#define SDA_PIN 4
#define SCL_PIN 5
const int16_t I2C_MASTER = 0x42;
void setup() {
Serial.begin(9600);
Wire.begin(SDA_PIN, SCL_PIN);
acele.Init(&Wire);
}
void loop() {
if(!Utiles::isTime(&Timer,TIMER_LOG))
return;
Serial.print("aceleracion x: ");
Serial.print(acele.GetAx());
Serial.print(" aceleracion y: ");
Serial.print(acele.GetAy());
Serial.print(" aceleracion z: ");
Serial.println(acele.GetAz());
Serial.print("mag x: ");
Serial.print(acele.GetMx());
Serial.print(" mag y: ");
Serial.print(acele.GetMy());
Serial.print(" mag z: ");
Serial.println(acele.GetMz());
}

View File

@ -13,7 +13,7 @@ void setup() {
void loop() {
if(!Utiles::isTime(&Timer,TIMER_LOG))
if(!Utiles::isTime(&Timer,(unsigned long)TIMER_LOG))
return;
Serial.print("Temperatura: ");
Serial.println(dht.GetT());

View File

@ -63,11 +63,25 @@ Sim808Manager::Sim808Manager()
simIniciada = false;
gpsIniciada = false;
AjusteHora = 1;
pSSerial = 0;
pSerial = 0;
}
bool Sim808Manager::inicia(SoftwareSerial* mySerial, int powerKey = -1, int baud = 0)
{
pSSerial = mySerial;
pk = powerKey;
if (pk >= 0)
pinMode(pk, OUTPUT);
if (baud)
return checkeaConfig(baud);
return checkea();
/* if (!CheckAt())
enciende();
return CheckAt();*/
}
bool Sim808Manager::inicia(HardwareSerial *mySerial, int powerKey = -1, int baud=0)
{
pSeria = mySerial;
pSerial = mySerial;
pk = powerKey;
if (pk >= 0)
pinMode(pk, OUTPUT);
@ -214,17 +228,36 @@ char* Sim808Manager::recibe()
char *buff = buffer;
char *buf = buffer;
int len = 0;
if (pSerial)
{
while (millis() - start < 100)
{
while (pSeria->available() > 0 && len< (LEN_BUFFER_DATA_SIMMANAGER-3))
while (pSerial->available() > 0 && len < (LEN_BUFFER_DATA_SIMMANAGER - 3))
{
start = millis();
d = pSeria->read();
d = pSerial->read();
*buf = d;
buf++;
len++;
}
}
}
else
{
while (millis() - start < 100)
{
while (pSSerial->available() > 0 && len < (LEN_BUFFER_DATA_SIMMANAGER - 3))
{
start = millis();
d = pSSerial->read();
*buf = d;
buf++;
len++;
}
}
}
*buf = 0;
@ -238,15 +271,28 @@ char* Sim808Manager::recibe()
void Sim808Manager::envia(const char* dat)
{
pSeria->println(dat);
if(pSerial)
pSerial->println(dat);
else
pSSerial->println(dat);
//Utiles::printCOM(dat);
}
void Sim808Manager::enviaSolo(const char* dat, int ndata)
{
if (pSerial)
{
for (int i = 0; i < ndata; i++)
{
pSeria->write(dat[i]);
pSerial->write(dat[i]);
}
}
else
{
for (int i = 0; i < ndata; i++)
{
pSSerial->write(dat[i]);
}
}
//Utiles::printCOM(dat);
}
@ -515,7 +561,10 @@ bool Sim808Manager::configBaud(int baud)
Utiles::printCOM("configBaud");
pSeria->begin(baud);
if (pSerial)
pSerial->begin(baud);
else
pSSerial->begin(baud);
Utiles::printCOM("configurado p serial");
//envia("AT+GMR");
//reciveOK();
@ -530,7 +579,10 @@ bool Sim808Manager::configBaud(int baud)
uint32_t baudTest = baudSIM808[i];
sprintf(auxbuf, "prueba: %u", baudTest );
Utiles::printCOM(auxbuf);
pSeria->begin(baudTest);
if (pSerial)
pSerial->begin(baud);
else
pSSerial->begin(baud);
if (CheckAt())
{
Utiles::printCOM("Conseguido");
@ -541,7 +593,10 @@ bool Sim808Manager::configBaud(int baud)
}
Utiles::printCOM("fail");
}
pSeria->begin(baud);
if (pSerial)
pSerial->begin(baud);
else
pSSerial->begin(baud);
return CheckAt();
}

View File

@ -2,6 +2,7 @@
#define Sim808Manager_define 1
#include "Utiles.h"
#include <SoftwareSerial.h>
#define LEN_BUFFER_DATA_SIMMANAGER 1024
enum ProtocolSimManager {
@ -46,11 +47,12 @@ class Sim808Manager
bool gpsIniciada;
int pk;
DataGPSSimManager dataGPS;
HardwareSerial *pSeria;
HardwareSerial *pSerial;
SoftwareSerial* pSSerial;
int AjusteHora;
public:
Sim808Manager();
bool inicia(SoftwareSerial* mySerial, int powerKey, int baud);//int powerKey = -1, int baud=0
bool inicia(HardwareSerial *mySerial, int powerKey, int baud);//int powerKey = -1, int baud=0
bool EnviaSMS(char* tlf, char *sms);