ใครมีโค้ด neo 6m gps ที่เชื่อมด้วย firebase ด้วย NodeMcu บ้างคะ ที่สามารถแสดงค่า ละติจูดและลองจิจูด
ตอนนี้ทำ neo 6m gps อ่านค่าได้หรือยังครับ
พอจะมีโค้ดตัวอย่างให้ดูไหมคะ
#include "TinyGPS++.h"
#include "SoftwareSerial.h"
SoftwareSerial serial_connection(10, 11); //RX=pin 10, TX=pin 11
TinyGPSPlus gps;//This is the GPS object that will pretty much do all the grunt work with the NMEA data
void setup()
{
Serial.begin(9600);//This opens up communications to the Serial monitor in the Arduino IDE
serial_connection.begin(9600);//This opens up communications to the GPS
Serial.println("GPS Start");//Just show to the monitor that the sketch has started
}
void loop()
{
while(serial_connection.available())//While there are characters to come from the GPS
{
gps.encode(serial_connection.read());//This feeds the serial NMEA data into the library one char at a time
}
if(gps.location.isUpdated())//This will pretty much be fired all the time anyway but will at least reduce it to only after a package of NMEA data comes in
{
//Get the latest info from the gps object which it derived from the data sent by the GPS unit
Serial.println("Satellite Count:");
Serial.println(gps.satellites.value());
Serial.println("Latitude:");
Serial.println(gps.location.lat(), 6);
Serial.println("Longitude:");
Serial.println(gps.location.lng(), 6);
Serial.println("Speed MPH:");
Serial.println(gps.speed.mph());
Serial.println("Altitude Feet:");
Serial.println(gps.altitude.feet());
Serial.println("");
}
}
/*
* $GPRMC,183729,A,3907.356,N,12102.482,W,000.0,360.0,080301,015.5,E*6F
$GPRMB,A,,,,,,,,,,,,V*71
$GPGGA,183730,3907.356,N,12102.482,W,1,05,1.6,646.4,M,-24.1,M,,*75
$GPGSA,A,3,02,,,07,,09,24,26,,,,,1.6,1.6,1.0*3D
$GPGSV,2,1,08,02,43,088,38,04,42,145,00,05,11,291,00,07,60,043,35*71
$GPGSV,2,2,08,08,02,145,00,09,46,303,47,24,16,178,32,26,18,231,43*77
$PGRME,22.0,M,52.9,M,51.0,M*14
$GPGLL,3907.360,N,12102.481,W,183730,A*33
$PGRMZ,2062,f,3*2D
$PGRMM,WGS 84*06
$GPBOD,,T,,M,,*47
$GPRTE,1,1,c,0*07
$GPRMC,183731,A,3907.482,N,12102.436,W,000.0,360.0,080301,015.5,E*67
$GPRMB,A,,,,,,,,,,,,V*71
*/
หนูต้องการให้มันเชื่อมกับ firebase ด้วยคะ รบกวนช่วยดูตรง loop ให้หน่อยได้ไหมคะ
#include <TinyGPS++t.h> // Tiny GPS Plus Library
#include <SoftwareSerial.h> // Software Serial Library so we can use other Pins for communication with the GPS module
#include <FirebaseArduino.h>
#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
//#include <ESP8266WiFiMulti.h>
//ESP8266WiFiMulti wifiMulti;
//
//#include <time.h>
// Set these to run example.
#define FIREBASE_HOST "xxxx"
#define FIREBASE_AUTH "xxxxx"
#define WIFI_SSID "xxxx"
#define WIFI_PASSWORD "xxxx"
static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
ss.begin(GPSBaud);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
// put your main code here, to run repeatedly:
// This sketch displays information every time a new sentence is correctly encoded.
//Serial.println("hh");
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
}
}
}
หนูจะดัดเเปลง ให้มันส่งข้อมูลไปเก็บยังฐานข้อมูล firebase ไม่ได้คะ พี่ช่วยดูให้หน่อยนะคะ
#include <TinyGPS++.h> // Tiny GPS Plus Library
#include <SoftwareSerial.h> // Software Serial Library so we can use other Pins for communication with the GPS module
#include <FirebaseArduino.h>
#include <ESP8266WiFi.h>
//#include <ESP8266HTTPClient.h>
//#include <ESP8266WiFiMulti.h>
//ESP8266WiFiMulti wifiMulti;
//
//#include <time.h>
// Set these to run example.
#define FIREBASE_HOST “xxxx”
#define FIREBASE_AUTH “xxxxx”
#define WIFI_SSID “xxxx”
#define WIFI_PASSWORD “xxxx”
static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13
static const uint32_t GPSBaud = 9600;
TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps
SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
ss.begin(GPSBaud);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“connecting”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop() {
// put your main code here, to run repeatedly:
// This sketch displays information every time a new sentence is correctly encoded.
[//Serial.println](https://serial.println/)(“hh”);
while (ss.available() > 0){
gps.encode(ss.read());
if (gps.location.isUpdated()){
Serial.print("Latitude= ");
Serial.print(gps.location.lat(), 6);
Serial.print(" Longitude= ");
Serial.println(gps.location.lng(), 6);
}
}
}
อ่านค่าได้หรือยังครับ พิกัด
อ่านค่าได้เเล้วคะ ตรง serial monitor แต่ว่าตรงฐานข้อมูลของ firebase ยังไม่ได้อีกคะ ไม่รู้ว่าจะประกาศยังไงให้ข้อมูลไปอยู่บนฐานข้อมูล firebase คะ
ตอนนี้ได้หรือยังครับ