Example #1
0
void process(void *context)
{
    uint8 l = 0;
    if (SerialUSB.available()) {
        l = SerialUSB.read();
        if (l == 'S') {
            debug("\'S\' stop Kaa client\r\n");
            if (kaa_client)
                kaa_client_stop(kaa_client);
        }
    }

    if (light_blink_counter >= 0) {
        if ((millis() - light_blink_time) >= LIGHT_BLINK_TIME) {
            light_blink_counter++;
            light_blink_time = millis();
            if ((light_blink_counter % 2) == 0) {
                lightOn(true, true);
            } else {
                lightOff(true, true);
            }
        }
        if (light_blink_counter > LIGHT_BLINK_NUMBER) {
            lightOff(true, true);
            light_blink_counter = -1;
        }
    }

    readRFID();
}
Example #2
0
int main(void){
	
	char searchstring[55];
	char *rfid_number;
	char *uid;

	rfid_number=readRFID();

	if(DATABASE == 1) {
		snprintf(searchstring,55,"(pager=%s)",rfid_number);
		uid = ldap_search(searchstring,"uid");
	
		if(!strcmp(uid,"failed")){
			printf("Fehlgeschlagen!\r\n");
			return 0;
		}
	}else if(DATABASE == 2) {
		snprintf(searchstring,55,"SELECT uid FROM account WHERE rfid='%s';",rfid_number);
		if(sql_search(searchstring)){
			printf("Something was wrong");
		}
	}
	
	//free(uid);
	free(rfid_number);
	
	return 0;
}
void loop()
{
	if (timing) {
		timerTime += millis() - lastTime;
		lastTime = millis();
	}

	if (state == WAITING || state == TIMER_COUNTDOWN) {
		if (state == WAITING && timing) disableTiming();
		if (readRFID()) {
			//Serial.print("RFID: ");
			//Serial.println(rfidNum);

			convertRFID();
			if (serverRequest()) {
				state = SERVER_WAIT;
				enableTiming();
			}
			else state = WAITING;
		}
	}
	else if (state == SERVER_WAIT){
		//Serial.println(timerTime);
		if (timerTime < TIMEOUT) {
			if (readServerResponse()) {
				disableTiming();
				parseResponse();
				if (authorized) {
					state = TIMER_COUNTDOWN;
					turnOn();
				}
				else state = DENIED;
			}
		}
		else {
			state = WAITING;
		}
	}
	else if (state == DENIED) {
		Serial.println("DENIED");
		state = WAITING;
	}

	if (state == TIMER_COUNTDOWN && timing && currentOn()) {
		disableTiming();
	}
	else if (state == TIMER_COUNTDOWN && (!timing && !currentOn())) {
		enableTiming();
	}

	if (state == TIMER_COUNTDOWN) {
		if ((timing && (timerTime > authorizedTime)) || checkButton()) {
			state = WAITING;
			disableTiming();
			turnOff();
		}
	}

	/*if (timerTime > 0)
		Serial.println(timerTime);*/
}