Advertisement
apl-mhd

gps server

Jul 15th, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.60 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.   HTTPClient http;    //Declare object of class HTTPClient
  59.  
  60.   String ADCData, station, postData;
  61.   int adcvalue=analogRead(A0);  //Read Analog value of LDR
  62.   //ADCData = String(adcvalue);   //String to interger conversion
  63.   ADCData = "456";
  64.   station = "1234";
  65.  
  66.   //Post Data
  67.   postData = "lat=" + ADCData + "&long=" + station +"&submit=enter";
  68.  
  69.   http.begin("https://3e50a5b55040.ngrok.io/insertlatlong.php");              //Specify request destination
  70.   http.addHeader("Content-Type", "application/x-www-form-urlencoded");    //Specify content-type header
  71.  
  72.   //int httpCode = http.POST("logical_id=a&submit=enter");
  73.   int httpCode = http.POST(postData);   //Send the request
  74.   String payload = http.getString();    //Get the response payload
  75.  
  76.   Serial.println(httpCode);   //Print HTTP return code
  77.   Serial.println(payload);    //Print request response payload
  78.  
  79.   http.end();  //Close connection
  80.  
  81.   delay(5000);  //Post Data at every 5 seconds
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement