-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspot_pedale.ino
48 lines (43 loc) · 1.06 KB
/
spot_pedale.ino
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
// Spot welder pedal v 0.1
#include <Button2.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
const char* ssid = "SPOT";
const char* password = "";
String command = "http://192.168.4.22/spot";
Button2 button;
WiFiClient client;
HTTPClient http;
void setup() {
Serial.begin(115200);
button.begin(2);
button.setPressedHandler(pressed);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
}
void loop() {
button.loop();
}
void pressed(Button2& btn) {
Serial.println("pressed");
http.begin(client, command.c_str());
int httpResponseCode = http.GET();
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
String payload = http.getString();
Serial.println(payload);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
}