Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
253f9a43fa |
@@ -5,12 +5,6 @@
|
|||||||
#include <IRremote.hpp>
|
#include <IRremote.hpp>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
#include <Wire.h>
|
|
||||||
#include <Adafruit_PN532.h>
|
|
||||||
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
#include <WakeOnLan.h>
|
|
||||||
|
|
||||||
const char* ssid PROGMEM = "paradicsom";
|
const char* ssid PROGMEM = "paradicsom";
|
||||||
const char* password PROGMEM = "19700318";
|
const char* password PROGMEM = "19700318";
|
||||||
|
|
||||||
@@ -19,21 +13,16 @@ const char* githubFileURL PROGMEM = "https://raw.githubusercontent.com/htamas121
|
|||||||
const String githubToken PROGMEM = "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";
|
const String githubToken PROGMEM = "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";
|
||||||
String gitwebpage = "";
|
String gitwebpage = "";
|
||||||
|
|
||||||
const char* wakeUrl PROGMEM = "http://192.168.50.69:5000/wake";
|
|
||||||
|
|
||||||
const char* ntpServer PROGMEM = "hu.pool.ntp.org";
|
const char* ntpServer PROGMEM = "hu.pool.ntp.org";
|
||||||
const long gmtOffset_sec PROGMEM = 3600;
|
const long gmtOffset_sec PROGMEM = 3600;
|
||||||
const int daylightOffset PROGMEM = 3600;
|
const int daylightOffset PROGMEM = 3600;
|
||||||
|
|
||||||
unsigned long lastRunTime = 0;
|
unsigned long lastRunTime = 0;
|
||||||
const unsigned long interval PROGMEM = 5 * 60;
|
const unsigned long interval PROGMEM = 24 * 60 * 60;
|
||||||
|
|
||||||
WebServer server(80);
|
WebServer server(80);
|
||||||
HTTPClient httpClient;
|
HTTPClient httpClient;
|
||||||
|
|
||||||
WiFiUDP UDP;
|
|
||||||
WakeOnLan WOL(UDP);
|
|
||||||
|
|
||||||
//#define DECODE_NEC // Includes Apple and Onkyo. To enable all protocols , just comment/disable this line.
|
//#define DECODE_NEC // Includes Apple and Onkyo. To enable all protocols , just comment/disable this line.
|
||||||
#define NEC_PROTOCOL 8
|
#define NEC_PROTOCOL 8
|
||||||
|
|
||||||
@@ -44,39 +33,12 @@ WakeOnLan WOL(UDP);
|
|||||||
#define DELAY_AFTER_SEND 1000
|
#define DELAY_AFTER_SEND 1000
|
||||||
#define DELAY_AFTER_LOOP 5000
|
#define DELAY_AFTER_LOOP 5000
|
||||||
|
|
||||||
#define SDA A4
|
|
||||||
#define SCL A5
|
|
||||||
|
|
||||||
Adafruit_PN532 nfc(SDA, SCL);
|
|
||||||
|
|
||||||
// Known NFC card UID (replace with your specific card UID)
|
|
||||||
const uint8_t knownUID[] PROGMEM = { 0x23, 0xD8, 0x4F, 0x15 }; // Replace with your card UID
|
|
||||||
const int uidLength PROGMEM = sizeof(knownUID) / sizeof(knownUID[0]);
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.flush();
|
|
||||||
delay(2000);
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
pinMode(LED, OUTPUT);
|
pinMode(LED, OUTPUT);
|
||||||
digitalWrite(LED, HIGH);
|
digitalWrite(LED, HIGH);
|
||||||
|
|
||||||
//nfc
|
|
||||||
Serial.println("Initializing nfc board...");
|
|
||||||
nfc.begin();
|
|
||||||
uint32_t versionData = nfc.getFirmwareVersion();
|
|
||||||
|
|
||||||
if(!versionData){
|
|
||||||
Serial.println("Did not find pn532 compatible board!");
|
|
||||||
while(true){
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nfc.SAMConfig();
|
|
||||||
Serial.println("NFC is initialized");
|
|
||||||
|
|
||||||
//wifi
|
|
||||||
WiFi.begin(ssid, password);
|
WiFi.begin(ssid, password);
|
||||||
Serial.println("connecting to wifi");
|
Serial.println("connecting to wifi");
|
||||||
|
|
||||||
@@ -136,20 +98,6 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//check every time if wifi is active
|
|
||||||
/*if(!WiFi.isConnected()) {
|
|
||||||
WiFi.disconnect();
|
|
||||||
WiFi.begin(ssid, password);
|
|
||||||
|
|
||||||
Serial.print("Reconnecting to wifi");
|
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
delay(250);
|
|
||||||
Serial.print(".");
|
|
||||||
}
|
|
||||||
|
|
||||||
Serial.println("\n\n");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//calculates time to run webpage pull function
|
//calculates time to run webpage pull function
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
if(now - lastRunTime >= interval){
|
if(now - lastRunTime >= interval){
|
||||||
@@ -158,36 +106,6 @@ void loop() {
|
|||||||
printTime();
|
printTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
//nfc
|
|
||||||
uint8_t success;
|
|
||||||
uint8_t uid[7]; // Buffer to hold the UID
|
|
||||||
uint8_t uidLength; // Length of the UID
|
|
||||||
|
|
||||||
// Look for an NFC card
|
|
||||||
Serial.println("Waiting for an NFC card...");
|
|
||||||
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength, 500);
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
Serial.println("NFC Card detected!");
|
|
||||||
Serial.print("UID Length: "); Serial.println(uidLength);
|
|
||||||
Serial.print("UID Value: ");
|
|
||||||
for (uint8_t i = 0; i < uidLength; i++) {
|
|
||||||
Serial.print(" 0x"); Serial.print(uid[i], HEX);
|
|
||||||
}
|
|
||||||
Serial.println();
|
|
||||||
|
|
||||||
// Check if the detected card matches the known UID
|
|
||||||
if (uidLength == sizeof(knownUID) && memcmp(uid, knownUID, uidLength) == 0) {
|
|
||||||
Serial.println("Known NFC card detected! Sending HTTP request...");
|
|
||||||
wakePc();
|
|
||||||
} else {
|
|
||||||
Serial.println("Unknown NFC card.");
|
|
||||||
}
|
|
||||||
|
|
||||||
//delay(2000); // Debounce delay
|
|
||||||
}
|
|
||||||
//nfc end
|
|
||||||
|
|
||||||
server.handleClient(); // Handle incoming client requests
|
server.handleClient(); // Handle incoming client requests
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +130,7 @@ void pullWebpageData(){
|
|||||||
if(httpResponse > 0){
|
if(httpResponse > 0){
|
||||||
gitwebpage = httpClient.getString();
|
gitwebpage = httpClient.getString();
|
||||||
Serial.println("File content: ");
|
Serial.println("File content: ");
|
||||||
//Serial.println(gitwebpage);
|
Serial.println(gitwebpage);
|
||||||
Serial.println("Pulled web data");
|
Serial.println("Pulled web data");
|
||||||
}else{
|
}else{
|
||||||
Serial.printf("Error code: %d\n", httpResponse);
|
Serial.printf("Error code: %d\n", httpResponse);
|
||||||
@@ -236,9 +154,3 @@ void printTime(){
|
|||||||
Serial.println("Failed to obtain time");
|
Serial.println("Failed to obtain time");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wakePc(){
|
|
||||||
Serial.println("waking pc");
|
|
||||||
const char* MacAddress PROGMEM = "70:85:C2:94:14:33";
|
|
||||||
WOL.sendMagicPacket(MacAddress);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user