Robin2:
If you still have problems post your code.
...R
Hi, i have tried but not getting anywhere, i just cant get my head around the constant loops and doing little bits at a time so that the RFID reader stays available.
I will paste my code but cutout the sections not required.
LOOP
void loop () {
byte i = 0;
byte val = 0;
byte code[6];
byte checksumX = 0;
byte bytesread = 0;
byte tempbyte = 0;
if (Serial1.available() > 0) {
Serial.println("Got serial");
if ((val = Serial1.read()) == 2) { // check for header
Serial.println("Got serial read");
getID(); // Get the ID, sets readCard = to the read ID
if ( findID(readCard) ) // If not, see if the card is in the EEPROM
{
digitalWrite(relay, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(passPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(relay, LOW); // turn the LED off by making the voltage LOW
digitalWrite(passPin, LOW); // turn the LED off by making the voltage LOW
Serial.println("Open door");
openDoor(0);
}
else
{
digitalWrite(failPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(failPin, LOW); // turn the LED off by making the voltage LOW
Serial.println("Go away!");
}
}
bytesread = 0;
}
if ((unsigned long)(millis() - gsmPreviousMillis) >= gsmInterval) {
gsmPreviousMillis = millis();
digitalWrite(failPin, HIGH);
Serial.println("*** START GPRS ***");
connectGPRS();
digitalWrite(failPin, LOW);
}
}
CODE SECTION THAT CAN TAKE A WHILE AND STOPS THE RFID READER FROM WORKING.
void connectGPRS()
{
Serial.println("Attach to GPRS network - APN setting");
while (!LGPRS.attachGPRS("general.t-mobile.uk ", "user", "wap")) { //attachGPRS(const char *apn, const char *username, const char *password);
delay(500);
}
//blinkerGsm();
// if you get a connection, report back via serial:
Serial.print("Connect to ");
Serial.println(server);
if (client.connect(server, port))
{
Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
pollServer();
//blinkerGsm();
gsmPreviousMillis = millis();
}
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void pollServer()
{
// if there are incoming bytes available
// from the server, read them and print them:
//const char split[2] = "-";
bool startRead = false;
char buf[2048];
int count = 0;
while (client.connected())
{
if (client.available())
{
while (int i = client.read()) {
if (i != -1) {
buf[++count] = ((char)i);
} else {
buf[++count] = '\0';
break;
}
}
char* ch = strtok(buf, "\n");
bool reading = false;
while (ch != NULL) {
if (strcmp(ch, "END") == 0) reading = false;
if (strcmp(ch, "START") == 0) {
reading = true;
} else if (reading) {
bool active = startsWith("A:", ch);
bool disabled = startsWith("D:", ch);
String line(ch);
if (active) {
int rfidLength = 10;
String rfid = line.substring(2, sizeof(line));
Serial.print("Active: ");
Serial.println(rfid);
char rfidBuf[sizeof(rfid) + 1];
rfid.toCharArray(rfidBuf, sizeof(rfid));
byte val[sizeof(rfid) / 2];
size_t count = 0;
for (count = 0; count < sizeof(val); count++) {
char buf[5] = {'0', 'x', rfidBuf[count * 2], rfidBuf[count * 2 + 1], 0};
val[count] = byte(strtol(buf, NULL, 0));
}
writeID(val);
}
if (disabled) {
int rfidLength = 10;
String rfid = line.substring(2, sizeof(line));
Serial.print("Disabled: ");
Serial.println(rfid);
char rfidBuf[sizeof(rfid) + 1];
rfid.toCharArray(rfidBuf, sizeof(rfid));
byte val[sizeof(rfid) / 2];
size_t count = 0;
for (count = 0; count < sizeof(val); count++) {
char buf[5] = {'0', 'x', rfidBuf[count * 2], rfidBuf[count * 2 + 1], 0};
val[count] = byte(strtol(buf, NULL, 0));
}
deleteID(val);
}
}
ch = strtok(NULL, "\n");
}
Serial.println("Disconnecting.");
client.stop();
}
}
return;
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("Disconnecting.");
client.stop();
}
}
Any help with trying to make this efficient so that the RFID reader has priority would be great.
Mark