Skip to content

SnapProcessor Socket connect to server failed when using Ethernet #39

Closed
@Wardstein

Description

@Wardstein

Hi,
thanks first for the awesome lib. Just trying to get started with the snapclient. With WiFi on the ESP32 it works, but I cannot get the audio 100% glitch and crack free. Thats why I now want to move to Ethernet.
I have a W5500 board, connected via SPI. That works fine, I can ping my board.

First thing I noticed when moving to Ethernet instead of wifi, is that mDNS does not work (prints an error on the serial at startup). So I disabled it (via #define CONFIG_SNAPCLIENT_USE_MDNS false) after reading that it only supports WiFi in the current implementation?

After calling client.begin() the SnapClient cannot connect to my snapcast server. All I get on the Serial output is

[   628][E][SnapProcessor.h:296] connectClient(): [SnapProcessor] Socket connect to 192.168.10.18:1704 failed (errno = 0)

Do you have any hints? I looked at the other Ethernet related issues here, but cannot find any significant difference in the code.

This is my code:

#include <Arduino.h>
#include <SPI.h>
#include <Ethernet.h>
#include "config.h"         // Must be above "SnapClient.h" include, as here are some defines, which are otherwise defaulted in "SnapClient.h/SnapConfig.h"
#include "AudioTools.h"
#include "SnapClient.h"
#include "AudioTools/AudioCodecs/CodecOpus.h"


EthernetClient eth;
byte mac[] = {0xC0, 0x49, 0xEF, 0xCE, 0x14, 0xD4};

AudioInfo infoOut(48000, 2, 16); 
OpusAudioDecoder codec;
I2SStream out;
SnapTimeSyncDynamic synch(172, 10); 
SnapClient client(eth, out, codec);

IPAddress ip(192, 168, 10, 99);
IPAddress gateway(192, 168, 10, 1);
IPAddress dns(192, 168, 10, 1);


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

    Serial.println("Start SPI ...");
    SPI.begin(18, 19, 23, 5);

    // start the Ethernet connection:
    Serial.println("Start Ethernet ...");
    Ethernet.init(5);
    // Ethernet.begin(mac);
    Ethernet.begin(mac, ip, dns, gateway);

    // Check for Ethernet hardware present
    if (Ethernet.hardwareStatus() == EthernetNoHardware)
    {
        Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
        while (true);
    }
    Serial.print("Hardware type found: ");
    Serial.println(Ethernet.hardwareStatus());

    // Check link status
    if (Ethernet.linkStatus() == LinkOFF)
    {
        Serial.println("Ethernet cable is not connected.");
    }

    // wait for link
    Serial.println("waiting for link...");
    while(Ethernet.linkStatus() != LinkON)
    {
        delay(1000);
    }
    Serial.println("Ethernet link Up");

    Serial.print("local IP: ");
    Serial.println(Ethernet.localIP());

    Serial.println("starting I2S...");
    // setup I2S to define custom pins
    auto cfg = out.defaultConfig();
    cfg.copyFrom(infoOut);
    cfg.pin_data = 19;
    cfg.pin_bck = 18;
    cfg.pin_ws = 5;
    // cfg.pin_mck = 0;
    cfg.i2s_format = I2S_STD_FORMAT;
    cfg.buffer_size = 1024;
    cfg.buffer_count = 10;
    out.begin(cfg);

    Serial.println("starting SnapClient...");
    client.setWiFi(false);
    client.setServerIP(IPAddress(192, 168, 10, 18));
    client.begin(synch);

    Serial.println("started...");
}


void loop()
{
    client.doLoop();
}

I'm using PlatformIO, so for completeness this is my platformio.ini with the libs and versions:

[platformio]
description = ESP32 Snapclient test
default_envs = nodemcu-32s

[env:nodemcu-32s]
platform = espressif32
; platform = https://github.com/platformio/platform-espressif32.git#develop			; TEST TEST TEST
board = nodemcu-32s
framework = arduino
; platform_packages =
;     platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#2.0.14			; TEST TEST TEST
lib_deps = 
	https://github.com/pschatzmann/arduino-audio-tools.git#v1.0.0
	https://github.com/pschatzmann/arduino-snapclient#v.0.2.0
	https://github.com/pschatzmann/arduino-libopus#a1.1.0
	arduino-libraries/Ethernet@^2.0.2
build_flags = -DCORE_DEBUG_LEVEL=2 -Wno-unused-variable -Wno-unused-but-set-variable -Wno-unused-function -Wno-format-extra-args		; CORE_DEBUG_LEVEL=2 stands for Warning; debug = 5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions