#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
#include <OneWire.h>
#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {
192,168,178,49 };
byte ip1[] = {
192,168,178,48 };
unsigned int localPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
long previousMillis = 0;
long previousMillis1 = 0;
long interval = 5000;
int rfid_status = 0;
int DS18S20_Pin = 2;
int karte_gefunden = false;
OneWire ds(DS18S20_Pin);
int erste_mal_fuenf = false;
EthernetUDP Udp;
PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);
float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius
byte data[12];
byte addr[8];
if ( !ds.search(addr)) {
//no more sensors on chain, reset search
ds.reset_search();
return -1000;
}
if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;
}
if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
byte present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for (int i = 0; i < 9; i++) { // we need 9 bytes
data = ds.read();
- }*
- ds.reset_search();*
- byte MSB = data[1];*
- byte LSB = data[0];*
- float tempRead = ((MSB << 8) | LSB); //using two's compliment*
- float TemperatureSum = tempRead / 16;*
- TemperatureSum = TemperatureSum - 1;*
- return TemperatureSum;*
}
void buzzer(void)
{
- for(int i = 0; i<80;i++)*
- {*
- digitalWrite(7,HIGH);*
- delay(1);*
- digitalWrite(7,LOW);*
- delay(1);*
- }*
}
void card_reader()
{
- boolean success;*
- uint8_t uid[] = {*
- 0, 0, 0, 0, 0, 0, 0 };*
- uint8_t uidLength;*
- success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);*
- if (success)*
- {*
- Serial.println("Found a card!");*
- Serial.print("UID Length: ");*
- Serial.print(uidLength, DEC);*
- Serial.println(" bytes");*
- Serial.print("UID Value: ");*
- for (uint8_t i=0; i < uidLength; i++)*
- {*
- Serial.print(" 0x");*
_ Serial.print(uid*, HEX);_
_ }_
_ Serial.println("");_
_ if( uid[0]==0xFD && uid[1]==0x62 && uid[2]==0x92 && uid[3]==0xCC )_
_ {_
_ Serial.println("Hello Tom!");_
_ buzzer();_
if(rfid_status == 1)
_ {_
rfid_status = 0;
_ }_
_ else*_
* {*
* rfid_status = 1;
_ }_
_ }_
_ else if(uid[0]==0x25 && uid[1]==0xD1 && uid[2]==0x62 && uid[3]==0xE4)_
_ {_
_ Serial.println("Hello Gast!");_
_ buzzer();_
if(rfid_status == 3 || rfid_status == 0)
_ {_
rfid_status = 2;
_ }_
else if(rfid_status == 1)
_ {_
_ }_
_ else*_
* {*
* rfid_status = 0;
_ }_
_ }_
_ else*_
* {*
* Serial.println("Hello unkown guy");*
* buzzer();*
* buzzer();*
* if(rfid_status != 1 || rfid_status != 2)
_ {_
rfid_status == 3;
_ }_
else if(rfid_status == 3)
_ {_
rfid_status = 0;
_ }_
_ }_
karte_gefunden = true;
_ }_
_ else*_
* {*
* // PN532 probably timed out waiting for a card*
* Serial.println("Timed out waiting for a card");*
* }*
}
void setup()
{
* Ethernet.begin(mac,ip);*
* Udp.begin(localPort);*
* Serial.begin(9600);*
* nfc.begin();*
* uint32_t versiondata = nfc.getFirmwareVersion();
_ if (! versiondata)_
_ {_
_ Serial.println("Didn't find PN53x board");_
rfid_status = 5;
_ }_
_ nfc.setPassiveActivationRetries(0xFF);_
_ nfc.SAMConfig();_
_ Serial.println("Waiting for an ISO14443A card");_
_}_
void loop()
_{_
_ if(millis() - previousMillis > 5000)_
_ {_
_ previousMillis = millis();_
_ //Sende informationen*_
* int temp = getTemp();*
* char test = (char)(((int)'0')+temp);*
* Serial.println(test);*
* Udp.beginPacket(ip1, 8888);*
* Udp.write("informationen");*
* Udp.endPacket(); *
* Serial.println("Infos gesendet");*
* }*
* if((rfid_status != 5) && (millis() - previousMillis1 > 2000))
_ {_
card_reader();
if(karte_gefunden)
_ {_
_ Udp.beginPacket(ip1, 8888);_
char dig = (char)(((int)'0')+rfid_status);
_ Udp.write(dig);_
_ Udp.endPacket(); _
_ Serial.println("Karte gelesen");_
_ previousMillis1 = millis();_
_ }_
karte_gefunden = false;
_ }_
if((rfid_status == 5) && (erste_mal_fuenf == false))
_ {_
_ Udp.beginPacket(ip1, 8888);_
char dig = (char)(((int)'0')+rfid_status);
_ Udp.write(dig);_
_ Udp.endPacket(); _
_ Serial.println("Karte gfesen"); _
erste_mal_fuenf = true;
_ }_
_ // send a reply, to the IP address and port that sent us the packet we received*_
* //Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());*
* //Udp.write("blablabla");*
* //Udp.endPacket();*
}
[/quote]