Advertisement
apl-mhd

cn

Dec 8th, 2019
947
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 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. //asdfghjkl
  54. //OnePlus 7
  55. //http://192.168.43.51/
  56.  
  57.  
  58. int sendmessage(String d)
  59. {
  60.   int sres;
  61.   int net;
  62.   if (WiFi.status()==WL_CONNECTED)
  63.   {
  64.     HTTPClient http;
  65.     http://localhost:8080/buskoi/insert-lat-long.php?logical_id=2&lat=1&long=1
  66.  
  67.     String logical = "1";
  68.     String lat = "2";
  69.     String longi = "3";
  70.    
  71.     //String url="http://xyz.000webhostapp.com/writefile.php?data="+d;
  72.   // String url="http://localhost:8080/buskoi/insert-lat-long.php?logical_id="+logical+"&"+"lat="+lat+"&"+"long="+longi;
  73.  //  String url="http://localhost:8080/buskoi/insert-lat-long.php?logical_id="+logical;
  74.  
  75.  
  76.  http.begin("http://localhost:8080/buskoi/insert-lat-long.php");
  77.      http.begin("http://ce9a72ce.ngrok.io/buskoi/insert-lat-long.php");      //Specify request destination
  78.    http.addHeader("Content-Type", "application/x-www-form-urlencoded");  //Specify content-type header
  79.  
  80.    int httpCode = http.POST("logical_id=a&submit=enter");   //Send the request
  81.    String payload = http.getString();                  //Get the response payload
  82.  
  83.    Serial.println(httpCode);   //Print HTTP return code
  84.    Serial.println(payload);    //Print request response payload
  85.  
  86.    http.end();  //Close connection
  87.   }
  88.  
  89.   return 0;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement