Devices & Components
Arduino Mega 2560 Rev3
Seeed Shield for Mega
GPS Antenna
SMA to uFL/u.FL/IPX/IPEX RF Adapter Cable
Grove Blue Wrapper Pack 1-2
Grove-GPS
Software & Tools
Arduino IDE
Aquabots Client
Project description
Code
TinGPS.h
h
The header files for the TinyGPS module
1#ifndef TinyGPS_h 2#define TinyGPS_h 3 4#define TINY_GPS "TinyGPS" 5#define TINY_GPS_ID "gps.tiny" 6 7#include <SoftwareSerial.h> 8#include <TinyGPS++.h> 9 10class TinyGPS { 11 12 private: 13 bool complete; //general purpose flag for reading nmea sentences 14 String sentence; 15 double bearing; 16 double speed; 17 double latitude; 18 double longitude; 19 TinyGPSPlus gps; 20 21 public: TinyGPS(void); 22 void setup(); 23 double getBearing(); 24 double getLatitude(); 25 double getLongitude(); 26 double getBearing( double latFrom, double lonFrom, double latTo, double lonTo ); 27 double getDistance( double latFrom, double lonFrom, double latTo, double lonTo ); 28 bool wait();//wait for processing of the nmea sentence 29 void loop(); 30}; 31 32#endif
Vessels
c_cpp
This contains the modifications to the main programme, so that the vessel will not only register itself, but also relay its position
1#include <ArduinoJson.h> 2 3#include "WebClient.h" 4#include "Registration.h" 5#include "TinyGPS.h" 6 7#define VESSEL F("AquaBoat") 8#define PASSPHRASE F("AquaPassphrase") 9#define LATITUDE 51.2 10#define LONGITUDE 4.2 11#define TIME_OUT 300 //msec 12 13SoftwareSerial Serial1(2, 3); // RX, TX 14WebClient webClient; 15Registration registration; 16TinyGPS tinyGPS; 17 18void setup() { 19 Serial.begin(9600); 20 Serial.print(F("Setup Vessel: ")); Serial.println( VESSEL ); 21 webClient.setup(); 22 registration.setup(); 23 tinyGPS.setup(); 24} 25 26void loop() { 27 tinyGPS.loop(); 28 long vesselId = registration.registerVessel( VESSEL, PASSPHRASE, tinyGPS.getLatitude(), tinyGPS.getLongitude() ); 29 if ( vesselId >= 0 ) 30 Serial.print(F("VESSEL: ")); Serial.println( vesselId ); 31 delay(1000); 32} 33
Vessels
c_cpp
This contains the modifications to the main programme, so that the vessel will not only register itself, but also relay its position
1#include <ArduinoJson.h> 2 3#include "WebClient.h" 4#include "Registration.h" 5#include "TinyGPS.h" 6 7#define VESSEL F("AquaBoat") 8#define PASSPHRASE F("AquaPassphrase") 9#define LATITUDE 51.2 10#define LONGITUDE 4.2 11#define TIME_OUT 300 //msec 12 13SoftwareSerial Serial1(2, 3); // RX, TX 14WebClient webClient; 15Registration registration; 16TinyGPS tinyGPS; 17 18void setup() { 19 Serial.begin(9600); 20 Serial.print(F("Setup Vessel: ")); Serial.println( VESSEL ); 21 webClient.setup(); 22 registration.setup(); 23 tinyGPS.setup(); 24} 25 26void loop() { 27 tinyGPS.loop(); 28 long vesselId = registration.registerVessel( VESSEL, PASSPHRASE, tinyGPS.getLatitude(), tinyGPS.getLongitude() ); 29 if ( vesselId >= 0 ) 30 Serial.print(F("VESSEL: ")); Serial.println( vesselId ); 31 delay(1000); 32} 33
TinGPS.h
h
The header files for the TinyGPS module
1#ifndef TinyGPS_h 2#define TinyGPS_h 3 4#define TINY_GPS "TinyGPS" 5#define 6 TINY_GPS_ID "gps.tiny" 7 8#include <SoftwareSerial.h> 9#include <TinyGPS++.h> 10 11class 12 TinyGPS { 13 14 private: 15 bool complete; //general purpose flag for reading 16 nmea sentences 17 String sentence; 18 double bearing; 19 double speed; 20 21 double latitude; 22 double longitude; 23 TinyGPSPlus gps; 24 25 public: 26 TinyGPS(void); 27 void setup(); 28 double getBearing(); 29 double getLatitude(); 30 31 double getLongitude(); 32 double getBearing( double latFrom, double lonFrom, 33 double latTo, double lonTo ); 34 double getDistance( double latFrom, double 35 lonFrom, double latTo, double lonTo ); 36 bool wait();//wait for processing 37 of the nmea sentence 38 void loop(); 39}; 40 41#endif
TinyGPS.c
c_cpp
Implementation of the TinyGPS module
1TinyGPS::TinyGPS() {}; 2 3//Repeatedly feed it characters from your 4void TinyGPS::setup( ) { 5 Serial1.begin(9600); 6 Serial.println(F("GPS INITIALISED")); 7 latitude = -1; 8 longitude = -1; 9 bearing = 0; 10 speed = 0; 11 complete = false; 12} 13 14double TinyGPS::getBearing() { 15 return bearing; 16} 17 18double TinyGPS::getLatitude() { 19 return latitude; 20} 21 22double TinyGPS::getLongitude() { 23 return longitude; 24} 25 26bool TinyGPS::wait() { 27 return complete; 28} 29 30double TinyGPS::getBearing( double latFrom, double lonFrom, double latTo, double lonTo ) { 31 return gps.courseTo( latFrom, lonFrom, latTo, lonTo ); 32} 33 34double TinyGPS::getDistance( double latFrom, double lonFrom, double latTo, double lonTo ) { 35 return gps.distanceBetween( latFrom, lonFrom, latTo, lonTo ); 36} 37 38void TinyGPS::loop() { 39 Serial.println(F("CHECKING GPS")); 40 bool updated = false; 41 unsigned long current = millis(); 42 43 while (Serial1.available() && ( millis() < ( current + TIME_OUT ))) { 44 char chr = Serial1.read(); 45 gps.encode( chr ); 46 updated = gps.location.isUpdated(); 47 if ( updated ) { 48 49 latitude = gps.location.lat(); 50 longitude = gps.location.lng(); 51 bearing = gps.course.deg(); 52 speed = gps.speed.mps(); 53 Serial.print(F("\ 54\ 55GPS Location Updated: ")); 56 Serial.print( latitude, 6 ); Serial.print("E "); 57 Serial.print( longitude, 6 ), Serial.println("N\ 58\ 59 "); // bearing, speed ); 60 break; 61 } 62 } 63} 64
Comments
Only logged in users can leave comments