manhoosbilli1

post value to server from esp32

Nov 16th, 2019
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <WiFi.h>
  3. #include <HTTPClient.h>
  4. int ph_value = 20;
  5. const char* ssid = "Shoaib";
  6. const char* password = "A01234567890";
  7. void setup() {
  8.   // put your setup code here, to run once:
  9.   Serial.begin(115200);
  10.   WiFi.begin(ssid, password);
  11.   while (WiFi.status() != WL_CONNECTED) {
  12.     delay(500);
  13.     Serial.print(".");
  14.   }
  15.   Serial.println("");
  16.   Serial.println("WiFi connected");
  17.   Serial.println("IP Address");
  18.   Serial.println(WiFi.localIP());
  19.  
  20. }
  21.  
  22.  
  23. void loop() {
  24.   HTTPClient http;
  25.   http.begin("https://finalyearprojectnuml.000webhostapp.com/fyp.php");
  26.   http.addHeader("Content-Type", "application/x-www-form-urlencoded");
  27.   int httpResponseCode = http.POST(ph_value);
  28.   if (httpResponseCode > 0) {
  29.     String response = http.getString();
  30.     Serial.println(httpResponseCode);
  31.     Serial.println(response);
  32.   }
  33.   else {
  34.     Serial.print("Error on sending post");
  35.     Serial.println(httpResponseCode);
  36.   }
  37.   http.end();
  38.   delay(2000);
  39. }
Add Comment
Please, Sign In to add comment