Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Testing
- */
- // Libraries
- #include <ESP8266HTTPClient.h>
- #include<ESP8266WiFi.h>
- void setup()
- {
- Serial.begin(9600);
- WiFi.begin("Fast Lock","fastlock"); // add ssid and password here
- while(WiFi.status() !=WL_CONNECTED)
- {
- delay(500);
- Serial.println("Waiting for connection");
- }
- Serial.println("Connected...");
- delay(1000);
- if (WiFi.status() ==WL_CONNECTED)
- {
- Serial.println("Wi-Fi Connected!");
- }
- delay(2000);
- Serial.println("Sending message to server espcomm");
- delay(5000);
- int res=sendmessage("Hi,Server");
- delay(1000);
- if (res==1)
- {
- Serial.println("Send Successfully");
- }
- else
- {
- Serial.println("Error on Server side or client side.");
- }
- }
- void loop()
- {
- delay(5000);
- sendmessage("aa");
- }
- int sendmessage(String d)
- {
- int sres;
- int net;
- if (WiFi.status()==WL_CONNECTED)
- {
- HTTPClient http;
- // http://localhost:8080/buskoi/insertlatlong.php.php?lat=1&long=1
- String lat = "2";
- String longi = "3";
- postData = "lat=" + lat + "&long=" + longi +"&submit=enter";
- http.begin("http://3e50a5b55040.ngrok.io/insertlatlong.php"); //https not wokr here
- http.addHeader("Content-Type", "application/x-www-form-urlencoded"); //Specify content-type header
- 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
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement