/*
Sources :
-https://forum.arduino.cc/t/how-does-http-status-work-in-arduino-httpclient-lib-or-in-some-other-related-lib/1036183/3
-https://wiki-content.arduino.cc/en/Tutorial/LibraryExamples/HttpClient
-https://techtutorialsx.com/2017/05/19/esp32-http-get-requests/
-https://docs.wokwi.com/guides/esp32-wifi
*/
#include <WiFi.h>
#include <HTTPClient.h>
int Code = 0;
String response,nbr = "6";
void setup() {
Serial.begin(115200);
pinMode(14,INPUT_PULLUP);
pinMode(35,INPUT_PULLUP);
WiFi.begin("Wokwi-GUEST","");
while (WiFi.status() != WL_CONNECTED) {
delay(100);
Serial.print(".");
}
Serial.println("Connected to Wokwi-GUEST !");
}
void loop() {
if (digitalRead(14) == LOW || digitalRead(35) == HIGH){
if (digitalRead(35) == HIGH){
nbr = "20";
}
Serial.println("Rolling a " + nbr + " sided dice... ");
delay(200);
HTTPClient http;
http.begin("https://guardia-dice.glitch.me/" + nbr);
Code = http.GET();
if (Code > 0 && Code != 500){
response = http.getString();
Serial.println("You got a " + response + " !");
}
else{
Serial.println("[Erreur incorrect response from api !]");
}
http.end();
}
nbr = "6";
delay(10); // this speeds up the simulation
}