-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathesp32_to_Server.ino
More file actions
67 lines (48 loc) · 1.59 KB
/
esp32_to_Server.ino
File metadata and controls
67 lines (48 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "Marcelo TV ";
const char* password = "asm@05666600099";
const char* serverName = "https://unpardoning-baselin9.000webhostapp.com/post-data.php";
String apiKeyValue = "4TOc7~@b";
String sensorName = "Touch";
String sensorLocation = "HomeOffice";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting to the Wifi Network");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("WiFi is Connected at this IP Address : ");
Serial.println(WiFi.localIP());
}
void loop() {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
HTTPClient http;
http.begin(serverName);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&sensor=" + sensorName
+ "&location=" + sensorLocation + "&value1=" + touchRead(2)
+ "&value2=" + touchRead(4) + "&value3=" + touchRead(15) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
int httpResponseCode = http.POST(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
delay(30000);
}