HELP ME! Probably syntax error

re.ino (2.0 KB

#include <SPI.h>
#include <WiFiNINA.h>
#include <Adafruit_PN532.h>
#include <ArduinoHttpClient.h> // include the 4D Systems display library

#define PN532_SCK  (13)
#define PN532_MOSI (11)
#define PN532_SS   (10)
#define PN532_MISO (12)

Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

char ssid[] = "Redmi";     // your network SSID (name)
char password[] = "****"; // your network password

char serverAddress[] = "192.168.214.97"; // server address
int port = 80;

WiFiClient wifi;
HttpClient client = HttpClient(wifi, serverAddress, port);
int status = WL_IDLE_STATUS;
uint8_t card;

void setup() {
  Serial.begin(9600);

  nfc.begin();

  // attempt to connect to Wifi network
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, password);
    delay(5000);  // wait 5 seconds for connection
  }
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

   // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

}

void loop() {
  boolean success;
  uint8_t uid[] = {0, 0, 0, 0, 0, 0, 0};
  uint8_t uidLength;

  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  if (success) {
    Serial.print("UID Value: ");
    for (uint8_t i = 0; i < uidLength; i++) {
      card = uid[i];
      Serial.print(card);
    }
    Serial.println("");
    delay(500);
  
  }

  Serial.println("making a POST request");
    String contentType = "application/x-www-form-urlencoded";
    String postData = "uid=" + String(card);
    client.beginRequest();
    client.post("/NFC/addd.php", contentType, postData);

    // read the status code and body of the response
    int statusCode = client.responseStatusCode();
    String response = client.responseBody();

    Serial.print("Status code: ");
    Serial.println(statusCode);
    Serial.print("Response: ");
    Serial.println(response);

    Serial.println("Wait five seconds");
    delay(5000);
}

looks like LOOP function isn't running, anytime i scan a card it just hang

If it compiles, there aren't any syntax errors!

Does this last printing in setup() come out correctly?

   // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

a7

1 Like

yep, it just like the loop fuction makes it hangs

add this just under nfc.begin();


  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

see if it's not finding the device..

and yeah, should probably move the posting code to only happen when it has a good read..

good luck.. ~q

after debugging, i realise the program dosen't run past this line

success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

i tried this but tells me it dosen't find the PN532 board meanwhile, i tried it with another program that just read the unique id number and it works perfectly

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.