Desculpe não entendi o que quer dizer por filtragem se é em código ou hardware,
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include <HTTPClient.h>
#define boardId 1
#define ssid "EMELTEC"
#define password "xxxxx$"
const int pinSensorIn = GPIO_NUM_35;
const int pinSensorOut = GPIO_NUM_34;
int counterIn = 0;
int counterOut = 0;
bool counterIsSend = false;
bool counterOverflow = false;
int wifiConnected = 0;
hw_timer_t *timer = NULL;
void cb_timer()
{
if (counterIn > 99)
{
counterOverflow = true;
}
if (counterOut > 99)
{
counterOverflow = true;
}
}
void startTimer()
{
/* 0 - seleção do timer a ser usado, de 0 a 3.
80 - prescaler. O clock principal do ESP32 é 80MHz. Dividimos por 80 para ter 1us por tick.
true - true para contador progressivo, false para regressivo
*/
timer = timerBegin(0, 80, true);
/*conecta à interrupção do timer
- timer é a instância do hw_timer
- endereço da função a ser chamada pelo timer
- edge=true gera uma interrupção
*/
timerAttachInterrupt(timer, &cb_timer, true);
/* - o timer instanciado no inicio
- o valor em us para 1s
- auto-reload. true para repetir o alarme
*/
timerAlarmWrite(timer, 1000000 * 10, true);
//ativa o alarme
timerAlarmEnable(timer);
}
void stopTimer()
{
timerEnd(timer);
timer = NULL;
}
void sendData()
{
stopTimer();
counterIsSend = true;
WiFi.begin(ssid, password);
int countRetry = 0;
// Aguardando conexão completar
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
if (countRetry >= 20)
{
ESP.restart();
}
wifiConnected = 0;
Serial.println("Aguardando WIFI!");
countRetry++;
}
Serial.println('\n');
Serial.println("Connection established");
Serial.print("IP address:\t");
Serial.println(WiFi.localIP());
// Checar wifi conectou realmente ?
if (WiFi.status() == WL_CONNECTED)
{
wifiConnected = 1;
HTTPClient http;
http.begin("http://xxxxx.2labs.com.br/api.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int code = http.POST("data=" + String(boardId) + "#" + String(counterIn) + "#" + String(counterOut));
Serial.println(code);
Serial.println(http.getString());
http.end();
WiFi.disconnect(true, false);
}
counterIn = 0;
counterOut = 0;
counterIsSend = false;
counterOverflow = false;
startTimer();
}
void setup()
{
Serial.begin(115200);
pinMode(pinSensorIn, INPUT_PULLUP);
pinMode(pinSensorOut, INPUT_PULLUP);
startTimer();
Serial.println("Iniciando!");
}
bool sensorInBlocked = false;
bool sensorOutBlocked = false;
void loop()
{
// Serial.println(analogRead(34));
if (counterIsSend == false)
{
if (sensorInBlocked == false)
{
if (digitalRead(pinSensorIn) == HIGH)
{
sensorInBlocked = true;
counterIn++;
Serial.println("ALGUEM ENTROU");
Serial.print("Contagem IN: ");
Serial.print(counterIn);
Serial.println(" ");
}
}
if (digitalRead(pinSensorIn) == LOW)
{
sensorInBlocked = false;
}
if (sensorOutBlocked == false)
{
if (digitalRead(pinSensorOut) == HIGH)
{
//alguem saiu
sensorOutBlocked = true;
counterOut++;
Serial.println("ALGUEM SAIU");
Serial.print("Contagem OUT: ");
Serial.print(counterOut);
Serial.println(" ");
}
}
if (digitalRead(pinSensorOut) == LOW)
{
sensorOutBlocked = false;
}
}
if (counterOverflow)
{
sendData();
}
delay(300);
}
esse é o código que criei.