Ethernet not connecting to cloud

Hi! I have a photon 2 running os 5.8 connected to a poe shield and I can't seem to get it to connect to the cloud. It works perfectly on LAN mode, but when I try to connect to the cloud, Ethernet.ready never returns true even though Ethernet.localIP() returns a valid ip address that I can ping from the local network. For more context, I am also remapping the ethernet pins to A0-A2 because I need D3-5 for another device.
This is the sample code I'm running, and below that I'll put the logs:


// SAMPLE APPLICATION
#include "Particle.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
SerialLogHandler logHandler(115200, LOG_LEVEL_ALL);

uint8_t resetRetry = 0;

void setup() {
#if HAL_PLATFORM_WIFI && !HAL_PLATFORM_WIFI_SCAN_ONLY
    // To force Ethernet only, clear Wi-Fi credentials
    Log.info("Clear Wi-Fi credentionals...");
    WiFi.clearCredentials();
#endif // HAL_PLATFORM_WIFI && !HAL_PLATFORM_WIFI_SCAN_ONLY

    // Disable Listening Mode if not required
    if (System.featureEnabled(FEATURE_DISABLE_LISTENING_MODE)) {
        Log.info("FEATURE_DISABLE_LISTENING_MODE enabled");
    } else {
        Log.info("Disabling Listening Mode...");
        System.enableFeature(FEATURE_DISABLE_LISTENING_MODE);
    }

    Log.info("Checking if Ethernet is on...");
    if (Ethernet.isOn()) {
        Log.info("Ethernet is on");
        uint8_t macAddrBuf[8] = {};
        uint8_t* macAddr = Ethernet.macAddress(macAddrBuf);
        if (macAddr != nullptr) {
            Log.info("Ethernet MAC: %02x %02x %02x %02x %02x %02x",
                    macAddr[0], macAddr[1], macAddr[2], macAddr[3], macAddr[4], macAddr[5]);
        }
        Ethernet.connect();
        waitFor(Ethernet.ready, 30000);
        Log.info("Ethernet.ready: %d", Ethernet.ready());
        resetRetry = 0;
    } else if (++resetRetry <= 3) {
        Log.info("Ethernet is off or not detected, attmpting to remap pins: %d/3", resetRetry);

        if_wiznet_pin_remap remap = {};
        remap.base.type = IF_WIZNET_DRIVER_SPECIFIC_PIN_REMAP;

        remap.cs_pin = A0;
        remap.reset_pin = A2;
        remap.int_pin = A1;

        auto ret = if_request(nullptr, IF_REQ_DRIVER_SPECIFIC, &remap, sizeof(remap), nullptr);
        if (ret != SYSTEM_ERROR_NONE) {
            Log.error("Ethernet GPIO config error: %d", ret);
        } else {
            if (System.featureEnabled(FEATURE_ETHERNET_DETECTION)) {
                Log.info("FEATURE_ETHERNET_DETECTION enabled");
            } else {
                Log.info("Enabling Ethernet...");
                System.enableFeature(FEATURE_ETHERNET_DETECTION);
            }
            delay(500);
            System.reset();
        }
    }

    Particle.connect();
}

void loop() {
    static system_tick_t lastPublish = millis();
    static int count = 0;
    static bool reconnect = false;

    if (Particle.connected()) {
        reconnect = false;
        if (millis() - lastPublish >= 10000UL) {
            //print ethernet ip address
            Log.info("Ethernet IP: %s", Ethernet.localIP().toString().c_str());
            Particle.publish("mytest", String(++count), PRIVATE, WITH_ACK);
            lastPublish = millis();
        }
    }

    // Detect a network dropout and reconnect quickly
    if (!reconnect && !Ethernet.ready()) {
        Log.info("Particle disconnect...");
        Particle.disconnect();
        waitFor(Particle.disconnected, 5000);
        Log.info("Network disconnect...");
        Network.disconnect();
        Particle.connect();
        reconnect = true;
    }
}
0000001123 [system.nm] INFO: State changed: NONE -> DISABLED
0000001139 [system.nm] TRACE: Interface 4 power state: DOWN
0000001153 [system.nm] TRACE: Interface 3 power state: UP
0000001190 [comm] INFO: channel inited
0000001201 [app] INFO: Clear Wi-Fi credentionals...
0000001257 [ncp.mgr] TRACE: Updated file: /sys/wifi_config.bin
0000001488 [system.nm] TRACE: Updated file: /sys/network.dat
0000001672 [app] INFO: FEATURE_DISABLE_LISTENING_MODE enabled
0000001687 [app] INFO: Checking if Ethernet is on...
0000001700 [app] INFO: Ethernet is on
0000001710 [app] INFO: Ethernet MAC: 94 94 4a 04 93 ef
0000001730 [system.nm] INFO: State changed: DISABLED -> IFACE_DOWN
0000001764 [system.nm] INFO: State changed: IFACE_DOWN -> IFACE_REQUEST_UP
0000001800 [net.ifapi] INFO: Netif en2 state UP
0000001816 [net.en] TRACE: Closed MACRAW socket
0000001828 [net.en] TRACE: Opened MACRAW socket, err = 0
0000001843 [system.nm] INFO: State changed: IFACE_REQUEST_UP -> IFACE_UP
0000003096 [net.en] INFO: Link up
0000003097 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0000003100 [net.ifapi] TRACE: Netif en2 ipv4 configuration changed
0000003101 [system.nm] INFO: State changed: IFACE_UP -> IFACE_LINK_UP
0000031729 [app] INFO: Ethernet.ready: 0
0000031740 [app] INFO: Particle disconnect...
0000031751 [app] INFO: Network disconnect...
0000031763 [system.nm] INFO: State changed: IFACE_LINK_UP -> IFACE_REQUEST_DOWN
0000031783 [net.ifapi] INFO: Netif en2 state DOWN
0000031796 [hal] INFO: DNS server list changed
0000031808 [hal] INFO: DNS server list changed
0000031822 [system.nm] INFO: State changed: IFACE_REQUEST_DOWN -> IFACE_DOWN
0000031842 [net.en] TRACE: Closed MACRAW socket
0000031854 [net.ifapi] INFO: Netif en2 link DOWN, profile=NONE
0000031870 [hal] INFO: DNS server list changed
0000031876 [hal] INFO: DNS server list changed
0000031983 [system.nm] INFO: State changed: IFACE_DOWN -> IFACE_REQUEST_UP
0000032016 [net.ifapi] INFO: Netif en2 state UP
0000032040 [net.en] TRACE: Closed MACRAW socket
0000032063 [net.en] TRACE: Opened MACRAW socket, err = 0
0000032076 [system.nm] INFO: State changed: IFACE_REQUEST_UP -> IFACE_UP
0000032520 [net.en] INFO: Link up
0000032521 [net.ifapi] INFO: Netif en2 link UP, profile=NONE
0000032524 [system.nm] INFO: State changed: IFACE_UP -> IFACE_LINK_UP

update: adding in a gateway ip seemed to fix the issue

This is the expected behavior. If the Ethernet LAN gateway is not set, then the Ethernet LAN is assumed to be an isolated Ethernet network and won't be used for the cloud connection.

This is so you can access things on the isolated Ethernet LAN, then upload data to the Particle cloud via the cellular connection. Obviously the P2/Photon 2 don't have a cellular modem, but the behavior is consistent for Wi-Fi devices.

That makes sense, thank you! Is there something I need to include to make a static ip address work with cloud connection? When I use the DHCP config source, the device connects to the cloud, but when I try to use static, it is unable to connect. This is the new config I'm using:

auto conf = NetworkInterfaceConfig()
                     .source(NetworkInterfaceConfigSource::STATIC, AF_INET)
                     .address(IPAddress(172, 22, 21, 5), {255, 255, 0, 0})
                     .gateway(IPAddress(172, 22, 0, 1));

You also need to configure DNS. The Particle cloud servers are retrieved by DNS, not hardcoded into Device OS. This may be the same as the gateway if you have a combined router/firewall, or you can use a public DNS like 8.8.8.8 or 1.1.1.1.