#include <WiegandMega2560.h>
#include <SPI.h>
#include <Ethernet.h>
#define FALSE 0
#define TRUE 1
int in = 22;
int out = 24;
int but = 31;
int count = 0;
unsigned long timenow;
WIEGAND wg;
// replace the MAC address below by the MAC address printed on a sticker on the Arduino Shield 2
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
EthernetClient client;
int HTTP_PORT = 8000;
String HTTP_METHOD = "GET";
char HOST_NAME[] = "192.168.55.251"; // change to your PC's IP address
String PATH_NAME = "/send/";
String rfidin = "?rfidin=";
String rfidout = "?rfidout=";
boolean bol = false;
void setup() {
Serial.begin(9600);
pinMode(in, OUTPUT);
pinMode(out, OUTPUT);
pinMode(but, INPUT);
digitalWrite(in, LOW);
digitalWrite(out, LOW);
wg.begin(TRUE, TRUE, FALSE);
// initialize the Ethernet shield using DHCP:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to obtaining an IP address using DHCP");
while (true);
}
// connect to web server on port 80:
}
void loop() {
if (wg.available())
{
String data = String(wg.getCode());
String gate = String(wg.getGateActive());
Serial.println(data);
Serial.println(gate);
if (gate == "1") {
if (client.connect(HOST_NAME, HTTP_PORT)) {
// if connected:
Serial.println("Connected to server");
// make a HTTP request:
// send HTTP header
client.println(HTTP_METHOD + " " + PATH_NAME + rfidin + data + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println(); // end HTTP header
while (client.connected()) {
if (client.available()) {
// read an incoming byte from the server and print it to serial monitor:
char c = client.read();
Serial.print(c);
if (c == '1') {
timenow = millis();
bol = true;
while (millis() - timenow < 3000 && bol == true) {
digitalWrite(in, HIGH);
if (digitalRead(but) == HIGH) {
digitalWrite(in, LOW);
bol = false;
}
}
digitalWrite(in, LOW);
}
}
}
// the server's disconnected, stop the client:
client.stop();
Serial.println();
Serial.println("disconnected");
count = 0;
} else {// if not connected:
Serial.println("connection failed");
}
}
else if (gate == "2") {
if (client.connect(HOST_NAME, HTTP_PORT)) {
// if connected:
Serial.println("Connected to server");
// make a HTTP request:
// send HTTP header
client.println(HTTP_METHOD + " " + PATH_NAME + rfidout + data + " HTTP/1.1");
client.println("Host: " + String(HOST_NAME));
client.println("Connection: close");
client.println(); // end HTTP header
while (client.connected()) {
if (client.available()) {
// read an incoming byte from the server and print it to serial monitor:
char c = client.read();
Serial.print(c);
if (c == '1') {
timenow = millis();
bol = true;
while (millis() - timenow < 3000 && bol == true) {
timenow = millis();
digitalWrite(out, HIGH);
if (digitalRead(but) == HIGH) {
digitalWrite(out, LOW);
bol = false;
}
}
digitalWrite(out, LOW);
}
}
}
// the server's disconnected, stop the client:
client.stop();
Serial.println();
Serial.println("disconnected");
count = 0;
} else {// if not connected:
Serial.println("connection failed");
}
}
}
}
Суть такова, эта ардуино программка считывает со считывателя и отправляет данные на веб сервер, скрипт на python проверяет есть ли она в базе, если есть отправляет ответ 1 если нет 0, но когда я считываю карту реле включается и при нажатии на кнопку выключатся и больше не подключается к серверу