void ICACHE_FLASH_ATTR pn532_send_read_cmd_cb() {
	os_timer_disarm(&pn532readID);
	uint8 uid[4];
	uint8 *uidlen;
	bool a = readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid, &uidlen, 20);
	uint8 i;
	if (a) {
#ifdef MENJINDEBUG
		os_printf("\nUID:");
		for (i = 0; i < 4; i++) {
			os_printf("0x%x ", uid[i]);
		}
		os_printf("\n");
#endif
		char *id = "ID:";
		hextochar(uidstr, uid, 4);
		uidstr[8] = '\0';
		char *json_buf = NULL;
		json_buf = (char *) os_zalloc(jsonSize);
		json_ws_send((struct jsontree_value *) &cardid_info_tree, "cardID",
				json_buf);
		MQTT_Publish(&mqttClient, "/tc503/onCardRead", json_buf,
				strlen(json_buf), 0, 0);
		os_free(json_buf);
		json_buf = NULL;
	}
	os_timer_arm(&pn532readID, PN532_SEND_READ_CMD_DELAY, 1);
}
PROCESS_THREAD(test_adc, ev, data)
{
  static struct etimer et;
  PROCESS_BEGIN();  


	uint8_t status;
	status=SAMConfig();
	if(status){ 
		leds_toggle(LEDS_BLUE);
	}
	//uint32_t versiondata=getFirmwareVersion();
  //printf("Found chip PN532"); 
  //setPassiveActivationRetries(0xFF);
  uint8_t success;                          // Flag to check if there was an error with the PN532
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength=0;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
  
	if(readPassiveTargetID(0x00, uid, &uidLength)){
		leds_toggle(LEDS_RED);
		etimer_set(&et, CLOCK_SECOND/20);
		PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
	}

	if(success){
		leds_toggle(LEDS_RED);
		uint8_t i;
		printf("\nCard detected uid:");
		for(i=0;i<uidLength;i++){
			printf(" 0x%02x", uid[i]);
		}
	}


  while(1) {
    etimer_set(&et, CLOCK_SECOND/50);
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
		leds_toggle(LEDS_GREEN);
  }
  PROCESS_END();
}
int main(void)
{
	uint32_t versiondata;
    uint32_t id;

#ifdef NFC_DEMO_DEBUG
    printf("Hello!\n");
#endif
begin();
        versiondata = getFirmwareVersion();
        if (! versiondata) 
        {
                #ifdef NFC_DEMO_DEBUG
                        printf("Didn't find PN53x board\n");
                #endif
                while (1); // halt
        }
        #ifdef NFC_DEMO_DEBUG
        // Got ok data, print it out!
        printf("Found chip PN5"); 
        printf("%x\n",((versiondata>>24) & 0xFF));
        printf("Firmware ver. "); 
        printf("%d",((versiondata>>16) & 0xFF));
        printf("."); 
        printf("%d\n",((versiondata>>8) & 0xFF));
        printf("Supports "); 
        printf("%x\n",(versiondata & 0xFF));
        #endif
        // configure board to read RFID tags and cards
        SAMConfig();
        
        while(1)
        {
                // look for MiFare type cards
                id = readPassiveTargetID(PN532_MIFARE_ISO14443A);
                if (id != 0) 
                {
                #ifdef NFC_DEMO_DEBUG
                        printf("Read card #%d\n",id); 
                        CURL *curl;
				  CURLcode res;
 
				  /* In windows, this will init the winsock stuff */ 
				  curl_global_init(CURL_GLOBAL_ALL);
 
				  /* get a curl handle */ 
				  curl = curl_easy_init();
				  if(curl) {
					/* First set the URL that is about to receive our POST. This URL can
					   just as well be a https:// URL if that is what should receive the
					   data. */ 
					curl_easy_setopt(curl, CURLOPT_URL, "http://203.42.134.77/api/rfid");
					/* Now specify the POST data */ 
					curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "userID=123&rfid=2345123");
 
					/* Perform the request, res will get the return code */ 
					res = curl_easy_perform(curl);
					/* Check for errors */ 
					if(res != CURLE_OK)
					  fprintf(stderr, "curl_easy_perform() failed: %s\n",
							  curl_easy_strerror(res));
 
					/* always cleanup */ 
					curl_easy_cleanup(curl);
				  }
				  curl_global_cleanup();
                        
                #endif
                }
        }
  
  return 0;
}
Exemple #4
0
/**
    @brief    calls the right function to read the tag UID, according to type (cardbaudrate)

    @param    cardbaudrate  Baud rate of the card
    @param    uid     the var to write the uid
    @param    uidLen  the var to write the uid

    @returns  1 if the UID was correctly read, 0 if reading failed
*/
uint8_t KeyDuino::readTargetID(uint8_t cardbaudrate, uint8_t *uid, uint8_t *uidLength){
    if(cardbaudrate == PN532_ISO14443B)
        return readPassiveTargetID_B(uid, uidLength);
    return readPassiveTargetID(cardbaudrate, uid, uidLength);
}