Skip to content

Commit

Permalink
gps sketch adapted to D-pins
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwe committed Apr 23, 2016
1 parent 586ce82 commit 58ff3fc
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
2 changes: 2 additions & 0 deletions esp8266-arduino/gps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ http://arduiniana.org/libraries/tinygpsplus/

ESP Software Serial (should be built in)
https://github.com/plerup/espsoftwareserial

do not connect GPS to 3v3 of esp board, it might not be able to provide enough power, use a DC-DC voltage regulator
6 changes: 5 additions & 1 deletion esp8266-arduino/gps/gps.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
// TODO implement
// #define PUSHTO_MQTT

// GPIO PINSs <-> nodemcu PINs (Dx) mapping
// 0 1 2 3 4 5 6 7 8 9 10 11 12
int D[13]={16, 5, 4, 0, 2, 14, 12, 13, 15, 3, 1, 9, 10};

#define GPS_ACTIVE
#ifdef GPS_ACTIVE
/* config, move later to sensorconfig.h */
// wiring: GPS6MV2-RX->GPSRXPin
static const int GPSRXPin = 5, GPSTXPin = 0;
static const int GPSRXPin = D[7];
static const int GPSTXPin = D[8];
static const uint32_t GPSBaud = 9600;
unsigned long gpsmaxtime_ms=2100;

Expand Down
35 changes: 32 additions & 3 deletions esp8266-arduino/gps/gpsfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ Serial.print(gps.location.lng(),6);
Serial.print("\t");
Serial.println(gps.altitude.meters());
#endif
#ifdef PUSHTO_MQTT
mqtt_publish_subtopic("GPS/lat",gps.location.lat());
mqtt_publish_subtopic("GPS/lon",gps.location.lng());
mqtt_publish_subtopic("GPS/height",gps.altitude.meters());
#endif
}

bool push_gps_datetime(){
Expand All @@ -51,24 +56,40 @@ bool push_gps_datetime(){
if (!d.isValid()){
return false;
}else{
sprintf(sz, "DateTimeAge\t%02d-%02d-%02d", d.year(), d.month(), d.day());
sprintf(sz, "%02d-%02d-%02d", d.year(), d.month(), d.day());
#ifdef PUSHTO_SERIAL
Serial.print("DateTimeAge\t");
Serial.print(sz);
#endif
#ifdef PUSHTO_MQTT
mqtt_publish_subtopic("GPS/date",gps.hdop.value());
#endif
}
if (!t.isValid()){
Serial.println("");
return false;
}else{
sprintf(sz, " %02d:%02d:%02d\t%02d", t.hour(), t.minute(), t.second(),gps.location.age());
sprintf(sz, "%02d:%02d:%02d", t.hour(), t.minute(), t.second(),gps.location.age());
#ifdef PUSHTO_SERIAL
Serial.print(" ");
Serial.println(sz);
#endif
#ifdef PUSHTO_MQTT
mqtt_publish_subtopic("GPS/time",sz);
#endif
sprintf(sz, "%02d", gps.location.age());
#ifdef PUSHTO_SERIAL
Serial.print("\t");
Serial.println(sz);
#endif
#ifdef PUSHTO_MQTT
mqtt_publish_subtopic("GPS/locationage",sz);
#endif
}
return true;
}
bool push_gps_info(){
bool retval = ( gps.hdop.isValid() & gps.satellites.isValid() );
bool retval = (gps.hdop.isValid() & gps.satellites.isValid());
#ifdef PUSHTO_SERIAL
Serial.print("HdopSat\t");
if(gps.hdop.isValid()){
Expand All @@ -80,6 +101,14 @@ bool push_gps_info(){
}
Serial.println("");
#endif
#ifdef PUSHTO_MQTT
if(gps.hdop.isValid()){
mqtt_publish_subtopic("GPS/HDOP",gps.hdop.value());
}
if(gps.satellites.isValid()){
mqtt_publish_subtopic("GPS/satellites",gps.satellites.value());
}
#endif
return retval;
}
bool gps_read(){
Expand Down

0 comments on commit 58ff3fc

Please sign in to comment.