blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.83k stars 1.39k forks source link

Add example for Map widget and GPS trigger from hardware side. #347

Closed ErfanDL closed 7 years ago

ErfanDL commented 7 years ago

Hi. please add example for NodeMCU and GPS module to connect to Blynk map widget and GPS trigger from hardware side

vshymanskyy commented 7 years ago

Sorry - you can contribute the example yourself (as a PR), and we will review it. Thanks!

ErfanDL commented 7 years ago

@vshymanskyy I have a sketch for ESP8266 and generic GPS module it can report lon and lat on OLED display but I dont know how to port this sketch to Blynk sketch to work with map widget. here the code

include <TinyGPS++.h> // Tiny GPS Plus Library

include // Software Serial Library so we can use other Pins for communication with the GPS module

include // Adafruit oled library for display

Adafruit_ssd1306syp display(4,5); // OLED display (SDA to Pin 4), (SCL to Pin 5)

static const int RXPin = 12, TXPin = 13; // Ublox 6m GPS module to pins 12 and 13 static const uint32_t GPSBaud = 9600; // Ublox GPS default Baud Rate is 9600

const double Home_LAT = 32.38686; // Your Home Latitude const double Home_LNG = 51.40899; // Your Home Longitude

TinyGPSPlus gps; // Create an Instance of the TinyGPS++ object called gps SoftwareSerial ss(RXPin, TXPin); // The serial connection to the GPS device

void setup() {
display.initialize(); // Initialize OLED display
display.clear(); // Clear OLED display display.setTextSize(1); // Set OLED text size to small display.setTextColor(WHITE); // Set OLED color to White display.setCursor(0,0); // Set cursor to 0,0 display.println("GPS example");
display.println(TinyGPSPlus::libraryVersion()); display.update(); // Update display delay(1500); // Pause 1.5 seconds
ss.begin(GPSBaud); // Set Software Serial Comm Speed to 9600
}

void loop() {
display.clear(); display.setCursor(0,0); display.print("Latitude : "); display.println(gps.location.lat(), 5); display.print("Longitude : "); display.println(gps.location.lng(), 4); display.print("Satellites: "); display.println(gps.satellites.value()); display.print("Elevation : "); display.print(gps.altitude.feet()); display.println("ft"); display.print("Time UTC : "); display.print(gps.time.hour()); // GPS time UTC display.print(":"); display.print(gps.time.minute()); // Minutes display.print(":"); display.println(gps.time.second()); // Seconds display.print("Heading : "); display.println(gps.course.deg()); display.print("Speed : "); display.println(gps.speed.mph());

unsigned long Distance_To_Home = (unsigned long)TinyGPSPlus::distanceBetween(gps.location.lat(),gps.location.lng(),Home_LAT, Home_LNG); display.print("KM to Home: "); // Have TinyGPS Calculate distance to home and display it display.print(Distance_To_Home); display.update(); // Update display delay(200);

smartDelay(500); // Run Procedure smartDelay

if (millis() > 5000 && gps.charsProcessed() < 10) display.println(F("No GPS data received: check wiring")); }

static void smartDelay(unsigned long ms) // This custom version of delay() ensures that the gps object is being "fed". { unsigned long start = millis(); do { while (ss.available()) gps.encode(ss.read()); } while (millis() - start < ms); }

if you can please help me. I need this for grand mother tracking :(

vshymanskyy commented 7 years ago

In this case, you should read our docs and discuss it on community forum, if needed.