#include <SoftwareSerial.h>
// The serial connection to the GPS module
SoftwareSerial air(4, 3);
SoftwareSerial gps(10, 11);
#include <TinyGPS++.h> //到github上下载tinygps这个库
char gpsData;
TinyGPSPlus gpsCls;
void setup() {
Serial.begin(9600);
air.begin(9600);
gps.begin(9600);
Serial.println("started");
}
void loop() {
while (Serial.available() > 0) {
air.write(Serial.read());
// byte gpsData = Serial.read();
// Serial.println(Serial.read());
}
while (gps.available() > 0) {
// get the byte data from the GPS
if (gpsCls.encode(gps.read())) // encode gps data
{
displayInfo();
}
}
while (air.available() > 0) {
byte airData = air.read();
Serial.write(airData);
// Serial.println(airData);
}
}
String lastString;
void displayInfo()
{
if (gpsCls.location.isValid())
{
// 读取到gps数据 通过4G发给服务器
Serial.print("Latitude: ");
Serial.println(gpsCls.location.lat(), 6);
Serial.print("Longitude: ");
Serial.println(gpsCls.location.lng(), 6);
Serial.print("Altitude: ");
Serial.println(gpsCls.altitude.meters());
String latitude = String(gpsCls.location.lat(), 6);
String longitude = String(gpsCls.location.lng(), 6);
String themeters = String(gpsCls.altitude.meters());
if (latitude + ";" + longitude + ";" + longitude != lastString) {
lastString = String(latitude + ";" + longitude + ";" + longitude);
air.println(latitude + ";" + longitude + ";" + longitude);
}
} else
{
Serial.println("Location: Not Available");
lastString = String("searching");
air.println(lastString);
}
delay(1000);
}
arduino_gps's Introduction
arduino_gps's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.