1
  • The wifi client returns no data when I add in print statements on the library.
  • The issue happens right after I add this line to the loop. success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);
  • I am not sure if its a memory issue either, I can see quite a bit of heap memory left on the logs.
#include "Arduino.h"
#include "WiFiMulti.h"
#include "Audio.h"
#include <Adafruit_PN532.h>

#define PN532_IRQ (2)
#define PN532_RESET (3)
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

#define I2S_DOUT 19
#define I2S_BCLK 5
#define I2S_LRC 18

Audio audio;
WiFiMulti wifiMulti;
String ssid = "VODAFONE-794F";
String password = "7kgnyKP2sPKLpA4K";

String getRadioURLFromUID(uint32_t cardid)
{
  switch (cardid)
  {
  case 0x56761F03: // Another UID
    return "http://mp3.ffh.de/radioffh/hqlivestream.mp3";
  case 0x4E3E0C01: // Another UID
    return "http://mp3.ffh.de/radioffh/hqlivestream.mp3";
  default:
    return ""; // No station mapped to this UID
  }
}

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

  WiFi.mode(WIFI_STA);
  wifiMulti.addAP(ssid.c_str(), password.c_str());
  wifiMulti.run();
  if (WiFi.status() != WL_CONNECTED)
  {
    WiFi.disconnect(true);
    wifiMulti.run();
  }
  Serial.println("WiFi connected.");

  audio.setPinout(I2S_BCLK, I2S_LRC, I2S_DOUT);
  audio.setVolume(1);
  audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3");

  nfc.begin();
  // uint32_t versiondata = nfc.getFirmwareVersion();
  // if (!versiondata)
  // {
  //   Serial.println("No PN53x board detected.");
  //   while (1)
  //     ;
  // }
  nfc.SAMConfig();
  // Serial.println("NFC initialized. Waiting for a tag...");
}

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

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

  if (success)
  {
    uint32_t cardid = 0;
    for (int i = 0; i < uidLength; i++)
    {
      cardid <<= 8;
      cardid |= uid[i];
    }
    Serial.print("Card ID: ");
    Serial.println(cardid, HEX);

    String radioURL = getRadioURLFromUID(cardid);
    if (radioURL != "")
    {
      Serial.print("Playing station: ");
      Serial.println(radioURL);
      audio.stopSong(); // Stop current playback
      if (audio.connecttohost("http://mp3.ffh.de/radioffh/hqlivestream.mp3"))
      {
        log_i("free heap=%i", ESP.getFreeHeap());
        Serial.println("Stream started successfully!");
      }
      else
      {
        Serial.println("Failed to start stream!");
      }
    }
    else
    {
      Serial.println("No station mapped to this card.");
    }
    // delay(2000); // Prevent spamming reads
  }
  audio.loop(); // Keep audio running
}

void audio_error(const char *info)
{
  Serial.print("Audio Error: ");
  Serial.println(info);
  audio.stopSong();
  delay(1000); // Short wait before retry
  audio.connecttohost("http://icecast.omroep.nl/radio2-bb-mp3");
}

// optional
void audio_info(const char *info)
{
  Serial.print("info        ");
  Serial.println(info);
}
void audio_id3data(const char *info)
{ // id3 metadata
  Serial.print("id3data     ");
  Serial.println(info);
}
void audio_eof_mp3(const char *info)
{ // end of file
  Serial.print("eof_mp3     ");
  Serial.println(info);
}
void audio_showstation(const char *info)
{
  Serial.print("station     ");
  Serial.println(info);
}
void audio_showstreamtitle(const char *info)
{
  Serial.print("streamtitle ");
  Serial.println(info);
}
void audio_bitrate(const char *info)
{
  Serial.print("bitrate     ");
  Serial.println(info);
}
void audio_commercial(const char *info)
{ // duration in sec
  Serial.print("commercial  ");
  Serial.println(info);
}
void audio_icyurl(const char *info)
{ // homepage
  Serial.print("icyurl      ");
  Serial.println(info);
}
void audio_lasthost(const char *info)
{ // stream URL played
  Serial.print("lasthost    ");
  Serial.println(info);
}
2
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Jan 17 at 5:43
  • How do you wire the PN532 with ESP32? Pin 19, 5 and 18 happened to be the SPI's MISO, SCK and SS pin, does your PN532 use SPI or I2C? Commented Jan 17 at 12:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.