#include <ArduinoHttpClient.h>
#include <WiFi.h>
const char serverName[] = "eo1buddftcclsc6.m.pipedream.net";
const char serverPath[] = "/";
const int port = 443;
int status = WL_IDLE_STATUS;
String contentType = "application/json";
const char SSID[] = "Wokwi-GUEST"; // Network SSID (name)
const char PASS[] = ""; // Network password
#define BTN_UP 26
#define BTN_DN 27
void setup() {
delay(3000); // sanity delay
Serial.begin(115200);
pinMode(BTN_UP, INPUT_PULLUP);
pinMode(BTN_DN, INPUT_PULLUP);
WiFi.begin("Wokwi-GUEST", "", 6);
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println(" Connected!");
}
bool ReadDebounce(unsigned char InpPin);
long int Counter = 0,LastCnt = -1;
EthernetClient client;
char server[] = "https://enx588yxqr4at.x.pipedream.net"; // name address for Google (using DNS)
void loop() {
// digitalWrite(BTN_PIN, HIGH);
if (ReadDebounce(BTN_UP))
{
Counter++;
Serial.println("up pressed" + String(Counter, 5));
}
else if (ReadDebounce(BTN_DN))
{
Counter--;
Serial.println("down pressed" + String(Counter, 5));
}
delay(1000);
// if you get a connection, report back via serial:
if (WiFi.status() == WL_CONNECTED && Counter != LastCnt)
{
String data = "{\"value1\": \"" + String(Counter, 4) + "\"}";
Serial.println("Sending data");
client.beginRequest();
client.post(serverPath);
client.sendHeader("Content-Type", contentType);
client.sendHeader("Content-Length", contentType.length());
client.beginBody();
client.print(data);
client.endRequest();
int statusCode = client.responseStatusCode();
String response = client.responseBody();
Serial.print("Status code: ");
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);
Serial.println("Update Sent");
LastCnt = Counter;
} else {
// if you didn't get a connection to the server:
}
//https://enx588yxqr4at.x.pipedream.net/
}
bool ReadDebounce(unsigned char InpPin)
{
bool State = false;
if (digitalRead(InpPin) == 0)
{
delay(100);
if (digitalRead(InpPin) == 0)
{
while((digitalRead(InpPin) == 0));
State = true;
return State;
}
}
return State;
}