Arduino Mega: [0] MAC: FE-63-38-9-E2-27 [561] DHCP failed, retrying

I am trying to bring up an Arduino Mega on Cayenne. I have a working project with an UNO working fine for months…

  • Arduino MEGA with W5100 interface (Same as working on UNO project)
  • WEB dashboard
  • After going through usual Add a Device (Mega) and getting code downloaded and compiled and uploaded, and wired Ethernet to know good switch, All I get is:
    [0] MAC: FE-63-38-9-E2-27
    [561] DHCP failed, retrying
    [1221] DHCP failed, retrying etc etc
  • Wiring rechecked. Mega different than UNO… Pin 10 set as output as required.
    The code: ---------------------( COPY )---------------------
    This example shows how to connect to Cayenne using an Ethernet W5100 shield and send/receive sample data.

The CayenneMQTT Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.


  1. Set the Cayenne authentication info to match the authentication info from the Dashboard.
  2. Compile and upload the sketch.
  3. A temporary widget will be automatically generated in the Cayenne Dashboard. To make the widget permanent click the plus sign on the widget.

#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneMQTTEthernet.h>

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “6f8ac6f0-e355-11e6-a446-0d180dc59d42”;
char password = “39f26ec085433f46d13de612b2a5f241cb7a9f0d”;
char clientID = “cef0d990-0ae9-11ea-b49d-5f4b6757b1bf”;
//Setup for MEGA
#define OLD_SS_PIN 10
void setup()
digitalWrite(OLD_SS_PIN, LOW);
Cayenne.begin(username, password, clientID);

void loop() {

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_LOG(“Channel %u, value %s”,, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
-----------------( END COPY )----------------------
I defined DEBUG but no other messages.

ANYONE else using a Mega successfully?? Any pointers?
Regards, Terry King
…In The Woods in Vermont, USA

try this code Cayenne-MQTT-Arduino/ManualConnection.ino at master · myDevicesIoT/Cayenne-MQTT-Arduino · GitHub

Hi Shramik,
Thanks, I will make another setup with a MEga to test that…

Other: I changed my hardware back to an UNO with the example code and it immediately connected. I changed back to my original code (with a lot of I/O like temperature sensors and relays) using the UNO and it immediately worked. So this is UNO vs Mega issue.

BUT I am at 90+ % code space and I REALLY want to use a Mega. I’ll try your suggested variation code.

ANYONE successfully running a Mega?? Any examples??


Regards, Terry King
…In The Woods in Vermont, USA

the code I gave you is setting the IP address and other network configuration parameters as the DHCP failed to assign them. The code is almost the same.

Hi Shramik,
OK, I will set up a Mega and Ethernet later today and try that.

I do not understand how Cayenne KNOWS that the Ethernet interface will use different I/O pins when the controller is a Mega. Does that somehow get passed to the library when you pick “Mega” at the initial online configuration? I’m used to be able to check that kind of thing, but The Magic of Cayenne is hiding it right now. Hmmm…

The Host Configuration Protocol won’t work unless the Ethernet interface actually is found and initialized by the Cayenne library. I was trying to look at the 7 LEDs on the Ethernet interface to see what looked like normal activity. On the working UNO setup right now the TX led flashes once about every 10-15 seconds which I suspect is the data moving TO Cayenne.

OK, I’ll let you know.

I am documenting this project and will publish it on ArduinoInfo.Info when it’s working.

Regards, Terry King
…In The Woods in Vermont, USA

it is not about cayenne. this is what the docs say:
Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On both boards, pin 10 is used to select the W5100 and pin 4 for the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5100 or the SD card, but it must be kept as an output or the SPI interface won't work.

Thanks, Shramik!
I think I know what I did wrong. Sigh…

I have this kind of Ethernet interface:

I didn’t read my own site carefully enough. There is a table with the UNO and Mega connections. I forgot that the typical Ethernet SHIELD uses the ICSP connector and that is how the wiring is correct for both UNO and Mega. I’m 79 years old and sometimes I need to relearn things :slight_smile:

I’ll be putting the Cayenne information up on that page soon!

Regards, Terry King
…In The Woods in Vermont, USA

1 Like

thank you, would love to see more stuff from you related to cayenne.

YEAH… That’s what I did wrong… Tried to use Mega pin 53 as SS. Brought up a Mega with SS wired to 10 as it should be and it came right up.

Sorry to waste your time on this!

I will put up info on this project: Home monitor/control with 5 temperature sensors, 4 relays etc. Soon.

Regards, Terry

1 Like

glad to hear that it is working now.