I am working on a NodeMCU board to post sensor data on my website service. Basically my project is about POST and GET requests both in single code.
I am succeeding in sending GET requests from my website. However, I just can't post data to my website.
To post I have 2 different links (asp services): one will post data and another will be used to get data same as transmitted by first link.
Here is my code, and also how to post 2 variables in http post request?
#include (ESP8266WiFi.h)
#include (ESP8266HTTPClient.h)
const char* ssid = "oppo";
const char* password = "11111111";
int giSwitchNum = 1, buttonPin = 2;
void setup () {
Serial.begin(115200);
WiFi.begin(ssid, password);
pinMode(D1, OUTPUT);
pinMode(D2, INPUT);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print("Connecting..");
}
giSwitchNum = 1;
Serial.print("Connect");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient Post;
Post.begin("http://lemontechnologies.net/Services/Service.svc/SetData");
Post.addHeader("operator", "text/plain");
Post.POST("Key=hi&val=jagrut1");
String payload = Post.getString();
Post.end();
}
delay(500);
}