diff --git a/globoSonda/examples/PruebaGet.ino b/globoSonda/examples/PruebaGet/PruebaGet.ino similarity index 100% rename from globoSonda/examples/PruebaGet.ino rename to globoSonda/examples/PruebaGet/PruebaGet.ino diff --git a/globoSonda/examples/esp8266_PruebaGPS/esp8266_PruebaGPS.ino b/globoSonda/examples/esp8266_PruebaGPS/esp8266_PruebaGPS.ino new file mode 100644 index 0000000..b573257 --- /dev/null +++ b/globoSonda/examples/esp8266_PruebaGPS/esp8266_PruebaGPS.ino @@ -0,0 +1,45 @@ + +//librerias propias-------------------- + +#include +#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); +} diff --git a/globoSonda/examples/esp8266_acelerometro/esp8266_acelerometro.ino b/globoSonda/examples/esp8266_acelerometro/esp8266_acelerometro.ino new file mode 100644 index 0000000..ae30254 --- /dev/null +++ b/globoSonda/examples/esp8266_acelerometro/esp8266_acelerometro.ino @@ -0,0 +1,40 @@ + + +#include "stdio.h" +#include +#include +#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()); + +} diff --git a/globoSonda/examples/esp8266_temperatura/esp8266_temperatura.ino b/globoSonda/examples/esp8266_temperatura/esp8266_temperatura.ino index 6869821..3e77c81 100644 --- a/globoSonda/examples/esp8266_temperatura/esp8266_temperatura.ino +++ b/globoSonda/examples/esp8266_temperatura/esp8266_temperatura.ino @@ -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()); diff --git a/globoSonda/src/SIM808Manager.cpp b/globoSonda/src/SIM808Manager.cpp index 94abfdb..f1e00a6 100644 --- a/globoSonda/src/SIM808Manager.cpp +++ b/globoSonda/src/SIM808Manager.cpp @@ -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,16 +228,35 @@ char* Sim808Manager::recibe() char *buff = buffer; char *buf = buffer; int len = 0; - while (millis() - start < 100) + if (pSerial) { - while (pSeria->available() > 0 && len< (LEN_BUFFER_DATA_SIMMANAGER-3)) - { - start = millis(); - d = pSeria->read(); - *buf = d; - buf++; - len++; - } + while (millis() - start < 100) + { + + while (pSerial->available() > 0 && len < (LEN_BUFFER_DATA_SIMMANAGER - 3)) + { + start = millis(); + 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,16 +271,29 @@ 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) { - for ( int i = 0; i < ndata; i++) - { - pSeria->write(dat[i]); - } + if (pSerial) + { + for (int i = 0; i < ndata; i++) + { + pSerial->write(dat[i]); + } + } + else + { + for (int i = 0; i < ndata; i++) + { + pSSerial->write(dat[i]); + } + } //Utiles::printCOM(dat); } bool Sim808Manager::CheckAt() @@ -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(); } diff --git a/globoSonda/src/SIM808Manager.h b/globoSonda/src/SIM808Manager.h index 1039de4..64f163a 100644 --- a/globoSonda/src/SIM808Manager.h +++ b/globoSonda/src/SIM808Manager.h @@ -2,6 +2,7 @@ #define Sim808Manager_define 1 #include "Utiles.h" +#include #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);