Advertisement
apl-mhd

latlong

Dec 7th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. /*
  2.  * Testing
  3.  */
  4.  
  5. // Libraries
  6. #include <ESP8266HTTPClient.h>
  7. #include<ESP8266WiFi.h>
  8.  
  9. void setup()
  10. {
  11.   Serial.begin(9600);
  12.   WiFi.begin("orko","12345678");  // add ssid and password here
  13.  
  14.   while(WiFi.status() !=WL_CONNECTED)
  15.   {
  16.     delay(500);
  17.    
  18.     Serial.println("Waiting for connection");
  19.   }
  20.  
  21.   Serial.println("Connected...");
  22.   delay(1000);
  23.   if (WiFi.status() ==WL_CONNECTED)
  24.   {
  25.     Serial.println("Wi-Fi Connected!");
  26.   }
  27.  
  28.   delay(2000);
  29.   Serial.println("Sending message to server espcomm");
  30.   delay(5000);
  31.   int res=sendmessage("Hi,Server");
  32.   delay(1000);
  33.   if (res==1)
  34.   {
  35.    
  36.     Serial.println("Send Successfully");
  37.   }
  38.   else
  39.   {
  40.    
  41.     Serial.println("Error on Server side or client side.");
  42.   }
  43.  
  44. }
  45.  
  46. void loop()
  47. {
  48.  
  49.   delay(5000);
  50.   sendmessage("aa");
  51.  
  52. }
  53.  
  54.  
  55.  
  56.  
  57. int sendmessage(String d)
  58. {
  59.   int sres;
  60.   int net;
  61.   if (WiFi.status()==WL_CONNECTED)
  62.   {
  63.     HTTPClient http;
  64.     http://localhost:8080/buskoi/insert-lat-long.php?logical_id=2&lat=1&long=1
  65.  
  66.     String logical = "1";
  67.     String lat = "2";
  68.     String longi = "3";
  69.    
  70.     //String url="http://xyz.000webhostapp.com/writefile.php?data="+d;
  71.   // String url="http://localhost:8080/buskoi/insert-lat-long.php?logical_id="+logical+"&"+"lat="+lat+"&"+"long="+longi;
  72.  //  String url="http://localhost:8080/buskoi/insert-lat-long.php?logical_id="+logical;
  73.  
  74.  
  75.  http.begin("http://localhost:8080/buskoi/insert-lat-long.php");
  76.      http.begin("http://ce9a72ce.ngrok.io/buskoi/insert-lat-long.php");      //Specify request destination
  77.    http.addHeader("Content-Type", "application/x-www-form-urlencoded");  //Specify content-type header
  78.  
  79.    int httpCode = http.POST("logical_id=a&submit=enter");   //Send the request
  80.    String payload = http.getString();                  //Get the response payload
  81.  
  82.    Serial.println(httpCode);   //Print HTTP return code
  83.    Serial.println(payload);    //Print request response payload
  84.  
  85.    http.end();  //Close connection
  86.   }
  87.  
  88.   return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement