Advertisement
apl-mhd

Tanvir capstone

Jul 15th, 2021
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.07 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. #include <WiFiClient.h>
  3. #include <ESP8266WebServer.h>
  4. #include <ESP8266HTTPClient.h>
  5. #include <TinyGPS++.h> // library for GPS module
  6. #include <SoftwareSerial.h>
  7. TinyGPSPlus gps;  // The TinyGPS++ object
  8.  
  9. SoftwareSerial ss(4, 5); // The serial connection to the GPS device
  10.  
  11. float latitude , longitude;
  12. String date_str , time_str , lat_str , lng_str;
  13.  
  14.  
  15.  
  16. /* Set these to your desired credentials. */
  17. const char *ssid = "Tanvir";  //ENTER YOUR WIFI SETTINGS
  18. const char *password = "tanvir4321";
  19.  
  20.  
  21.  
  22. //=======================================================================
  23. //                    Power on setup
  24. //=======================================================================
  25.  
  26. void setup() {
  27.   delay(1000);
  28.   Serial.begin(9600);
  29.   WiFi.mode(WIFI_OFF);        //Prevents reconnection issue (taking too long to connect)
  30.   delay(1000);
  31.   WiFi.mode(WIFI_STA);        //This line hides the viewing of ESP as wifi hotspot
  32.  
  33.   WiFi.begin(ssid, password);     //Connect to your WiFi router
  34.   Serial.println("");
  35.  
  36.   Serial.print("Connecting");
  37.   // Wait for connection
  38.   while (WiFi.status() != WL_CONNECTED) {
  39.     delay(500);
  40.     Serial.print(".");
  41.   }
  42.  
  43.   //If connection successful show IP address in serial monitor
  44.   Serial.println("");
  45.   Serial.print("Connected to ");
  46.   Serial.println(ssid);
  47.   Serial.print("IP address: ");
  48.   Serial.println(WiFi.localIP());  //IP address assigned to your ESP
  49. }
  50.  
  51. //=======================================================================
  52. //                    Main Program Loop
  53. //=======================================================================
  54. void loop() {
  55.  
  56.  
  57.  
  58.  
  59.   while (ss.available() > 0){ //while data is available
  60.     if (gps.encode(ss.read())) //read gps data
  61.     {
  62.       if (gps.location.isValid()) //check whether gps location is valid
  63.       {
  64.         latitude = gps.location.lat();
  65.         lat_str = String(latitude , 6); // latitude location is stored in a string
  66.         longitude = gps.location.lng();
  67.         lng_str = String(longitude , 6); //longitude location is stored in a string
  68.  
  69.         Serial.println(latitude);
  70.  
  71.  
  72.      HTTPClient http;    //Declare object of class HTTPClient
  73.  
  74.      String ADCData, station, postData;
  75.      int adcvalue=analogRead(A0);  //Read Analog value of LDR
  76.      
  77.      
  78.  
  79.     //Post Data
  80.       postData = "lat=" + lat_str + "&long=" + lng_str +"&submit=enter";
  81.  
  82.      http.begin("https://3e50a5b55040.ngrok.io/insertlatlong.php");              //Specify request destination
  83.      http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
  84.  
  85.      //int httpCode = http.POST("logical_id=a&submit=enter");
  86.      int httpCode = http.POST(postData);   //Send the request
  87.      String payload = http.getString();    //Get the response payload
  88.  
  89.      Serial.println(httpCode);   //Print HTTP return code
  90.      Serial.println(payload);    //Print request response payload
  91.  
  92.      http.end();  //Close connection
  93.  
  94.      delay(5000);  //Post Data at every 5 seconds
  95.          
  96.       }
  97.  
  98. }
  99.    } //end while
  100.  
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement