Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266WebServer.h>
- #include <ESP8266HTTPClient.h>
- #include <TinyGPS++.h> // library for GPS module
- #include <SoftwareSerial.h>
- TinyGPSPlus gps; // The TinyGPS++ object
- SoftwareSerial ss(4, 5); // The serial connection to the GPS device
- float latitude , longitude;
- String date_str , time_str , lat_str , lng_str;
- /* Set these to your desired credentials. */
- const char *ssid = "Tanvir"; //ENTER YOUR WIFI SETTINGS
- const char *password = "tanvir4321";
- //=======================================================================
- // Power on setup
- //=======================================================================
- void setup() {
- delay(1000);
- Serial.begin(9600);
- WiFi.mode(WIFI_OFF); //Prevents reconnection issue (taking too long to connect)
- delay(1000);
- WiFi.mode(WIFI_STA); //This line hides the viewing of ESP as wifi hotspot
- WiFi.begin(ssid, password); //Connect to your WiFi router
- Serial.println("");
- Serial.print("Connecting");
- // Wait for connection
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- //If connection successful show IP address in serial monitor
- Serial.println("");
- Serial.print("Connected to ");
- Serial.println(ssid);
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP()); //IP address assigned to your ESP
- }
- //=======================================================================
- // Main Program Loop
- //=======================================================================
- void loop() {
- HTTPClient http; //Declare object of class HTTPClient
- String ADCData, station, postData;
- int adcvalue=analogRead(A0); //Read Analog value of LDR
- //ADCData = String(adcvalue); //String to interger conversion
- ADCData = "456";
- station = "1234";
- //Post Data
- postData = "lat=" + ADCData + "&long=" + station +"&submit=enter";
- http.begin("https://3e50a5b55040.ngrok.io/insertlatlong.php"); //Specify request destination
- http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
- //int httpCode = http.POST("logical_id=a&submit=enter");
- int httpCode = http.POST(postData); //Send the request
- String payload = http.getString(); //Get the response payload
- Serial.println(httpCode); //Print HTTP return code
- Serial.println(payload); //Print request response payload
- http.end(); //Close connection
- delay(5000); //Post Data at every 5 seconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement