Hallo mede gebruikers,
Had deze vraag ook al in het Engels geplaatst maar misschien fijn om hier ook in het Nederlands over te praten.
Ik heb de volgende code:
#include <SoftwareSerial.h>
#include <EtherCard.h>
#include <TextFinder.h>
//Ethernet needs this
#define REQUEST_RATE 5000 // milliseconds
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
char website[] PROGMEM = "jecom.nl";
byte Ethernet::buffer[400];
static long timer;
void Beep(){
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(300);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
}
// called when the client request is complete
static void my_result_cb (byte status, word off, word len) {
Serial.print("<<< reply ");
Serial.print(millis() - timer);
Serial.println(" ms");
Serial.println((const char*) Ethernet::buffer + off);
Beep();
}
//Parallax RFID Reader
#define RFIDEnablePin 2 //Pin that enables reading. Set as OUTPUT and LOW to read an RFID tag
#define RFIDSerialRate 2400 //Parallax RFID Reader Serial Port Speed
//Using SoftwareSerial Library to locate the serial pins off the default set
//This allows the Arduino to be updated via USB with no conflict
#define RxPin 5 //Pin to read data from Reader
#define TxPin 4 //Pin to write data to the Reader NOTE: The reader doesn't get written to, don't connect this line.
SoftwareSerial RFIDReader(RxPin,TxPin);
String RFIDTAG=""; //Holds the RFID Code read from a tag
String DisplayTAG = ""; //Holds the last displayed RFID Tag
void setup()
{
// RFID reader SOUT pin connected to Serial RX pin at 2400bps
RFIDReader.begin(RFIDSerialRate);
// Set Enable pin as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(RFIDEnablePin,OUTPUT);
pinMode(7, OUTPUT);
// Activate the RFID reader
// Setting the RFIDEnablePin HIGH will deactivate the reader
// which could be usefull if you wanted to save battery life for
// example.
digitalWrite(RFIDEnablePin, LOW);
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("\n[getDHCPandDNS]");
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
ether.printIp("My IP: ", ether.myip);
// ether.printIp("Netmask: ", ether.mymask);
ether.printIp("GW IP: ", ether.gwip);
ether.printIp("DNS IP: ", ether.dnsip);
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("Server: ", ether.hisip);
Beep();
timer = - REQUEST_RATE; // start timing out right away
}
void loop()
{
ether.packetLoop(ether.packetReceive());
if(RFIDReader.available() > 0) // If data available from reader
{
ReadSerial(RFIDTAG); //Read the tag number from the reader. Should return a 10 digit serial number
}
//This only displays a tag once, unless another tag is scanned
if(DisplayTAG!=RFIDTAG)
{
DisplayTAG=RFIDTAG;
Serial.println(RFIDTAG);
delay(1000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
if (millis() > timer + REQUEST_RATE) {
timer = millis();
Serial.println("\n>>> REQ");
char RFT[25];
DisplayTAG.toCharArray(RFT,25);
ether.browseUrl(PSTR("/frizzbar.php?tag="), RFT, website, my_result_cb);
delay(1000);
}
}
}
// Magical stuff below
void ReadSerial(String &ReadTagString)
{
int bytesread = 0;
int val = 0;
char code[10];
String TagCode="";
if(RFIDReader.available() > 0) { // If data available from reader
if((val = RFIDReader.read()) == 10) { // Check for header
bytesread = 0;
while(bytesread<10) { // Read 10 digit code
if( RFIDReader.available() > 0) {
val = RFIDReader.read();
if((val == 10)||(val == 13)) { // If header or stop bytes before the 10 digit reading
break; // Stop reading
}
code[bytesread] = val; // Add the digit
bytesread++; // Ready to read next digit
}
}
if(bytesread == 10) { // If 10 digit read is complete
for(int x=0;x<10;x++) //Copy the Chars to a String
{
TagCode += code[x];
}
ReadTagString = TagCode; //Update the caller
while(RFIDReader.available() > 0) //Burn off any characters still in the buffer
{
RFIDReader.read();
}
}
bytesread = 0;
TagCode="";
}
}
}
Bij elkaar geschraapt.
Zoals jullie kunnen zien wacht hij op een RFID tag die hij dan in een URL zet en naar een pagina transporteert.
Ik krijg dan van die pagina een inhoud terug met de volgende waardes:
hier nu nog kopie van de TAG
Met TextFinder wil ik die code in een integer zetten of iets anders dat ik kan vergelijken of gebruiken. Alleen weet ik niet hoe ik dit precies kan doen en welke stream ik moet gebruiken om dit waar te maken.