Bonjour tout le monde
Je débute également avec l'ESP et souhaiterais pouvoir utiliser un ESP pour envoyer une requète HTTP a un serveur lorsque j'appuie sur un bouton poussoir.
J'ai donc utiliser la librairie simplebouton.h mais je n'arrive pas a la faire fonctionner.
Lorsque je met en contact le PIN 3 (D3) et le GND il ne se passe rien.
Voici mon code:
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include "simpleBouton.h"
const char* ssid = "VINCENT_PRIVE";
const char* password = "***************";
const uint8_t pin_bouton = 3;//cablage pin---BP---GND
//Your Domain name with URL path or IP address with path
String serverName = "http://192.168.0.36/poussoir_bureau.php";
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastTime = 0;
// Timer set to 10 minutes (600000)
//unsigned long timerDelay = 600000;
// Set timer to 5 seconds (5000)
unsigned long timerDelay = 5000;
boutonAction bouton(pin_bouton);
void simpleClic() {
Serial.println("simple clic");
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
String serverPath = serverName + "?bouton=simple";
// Your Domain name with URL path or IP address with path
http.begin(client, serverPath.c_str());
// Send HTTP GET request
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);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
}
void doubleClic() {
Serial.println("double clic");
if(WiFi.status()== WL_CONNECTED){
WiFiClient client;
HTTPClient http;
String serverPath = serverName + "?bouton=double";
// Your Domain name with URL path or IP address with path
http.begin(client, serverPath.c_str());
// Send HTTP GET request
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);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
}
void setup() {
Serial.begin(115200);
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());
Serial.println("Timer set to 5 seconds (timerDelay variable), it will take 5 seconds before publishing the first reading.");
bouton.attacher(simpleClic, doubleClic);
}
void loop() {
bouton.actualiser();
}
Est-ce qu'une ame charitable sait me dire d'ou vient mon problème ?