MQTT with Arduino Nano and ENC2860

Hi there, I’m new here and I have problem with the error message.
I have an Arduino Nano (old Bootloader), and a Ethernetbord 2860. I want to test MQTT, to send a message to the broker, bit I have problems when I compile (compiler message).
I looaded a project from Arduino.cc and started it in PlatfromIO, I created a new “main.cpp” and coopied the content of the “.INO” file in the “main.cpp”. then there are problem with the libraries, to find, but I was able to get it.

But I get an error eith the firmware.
I did this in the code:

#if true

// #include <EthernetENC.h>

// #include <PubSubClient.h>

#include <../../MQTT_Nano/.pio/libdeps/nanoatmega328/PubSubClient/src/PubSubClient.h>
#include <../../MQTT_Nano/.pio/libdeps/nanoatmega328/EthernetENC/src/EthernetENC.h>

//#include <UIPEthernet.h>
#define DEBUG 1 // Debug output to serial console


// #include "DHT.h"
// #include <PZEM004T.h>


// #region  AUSBLENDEN

// #define DHTPIN 8
// #define DHTTYPE DHT11
// DHT dht(DHTPIN, DHTTYPE);
// PZEM004T pzem(2, 3); // (RX,TX) connect to TX,RX of PZEM

// #endregion


// IPAddress i(10, 10, 1, 1);
int sensorPin = A0; // Pin to which the sensor is connected to
unsigned long mytime = 0;
byte mac[] = {0x80, 0x7D, 0x3A, 0x69, 0x20, 0xC8}; // physical mac address
byte ip[] = {192, 168, 178, 100};                     // ip in lan
const char *mqtt_server = "192.168.178.55";
const char *mqttUser = "";
const char *mqttPassword = "";

char buf[4];               // Buffer to store the sensor value
unsigned int updateInterval = 5000; // Interval in milliseconds
EthernetClient espClient;
PubSubClient client(espClient);

void reconnect()
{
  Serial.begin(9600);
  
  // Loop until we're reconnected
  while (!client.connected())
  {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (client.connect("arduinoClientSuperior", mqttUser, mqttPassword))
    {
      Serial.println("connected");
    }
    else
    {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

void sensors()
{
  int sensorValue = analogRead(sensorPin);
  // float h = dht.readHumidity();
  // float t = dht.readTemperature();

  client.publish("home-assistant/sensor01/brightness", itoa(analogRead(sensorPin), buf, 10));
  // client.publish("home-assistant/sensor02/temperature", String(t).c_str(), true);
  // client.publish("home-assistant/sensor02/humidity", String(h).c_str(), true);

#if DEBUG
  Serial.print("Sensor value: ");
  Serial.println(sensorValue);
  // Serial.print("HuM value value: ");
  // Serial.println(h);
  // Serial.print("Temp value value: ");
  // Serial.println(t);
  Serial.println();
#endif

  // float e = pzem.energy(i);  // energia
  // float p = pzem.power(i);   // potenza
  // float c = pzem.current(i); // energia
  // float v = pzem.voltage(i); // potenza

  // client.publish("home-assistant/sensor03/voltage", String(v).c_str(), true);
  // client.publish("home-assistant/sensor03/energy", String(e).c_str(), true);
  // client.publish("home-assistant/sensor03/power", String(p).c_str(), true);
  // client.publish("home-assistant/sensor03/current", String(c).c_str(), true);

#if DEBUG
  // if (e >= 0.0)
  // {
  //   Serial.print(e);
  //   Serial.print("Wh; ");
  // }
  // if (p >= 0.0)
  // {
  //   Serial.print(p);
  //   Serial.print("W; ");
  // }
  // if (c >= 0.0)
  // {
  //   Serial.print(c);
  //   Serial.print("A; ");
  // }
  // if (v >= 0.0)
  // {
  //   Serial.print(v);
  //   Serial.print("V; ");
  // }
  // Serial.println();
#endif
}

void setup()
{
  // pzem.setAddress(i);
  // Serial.begin(115200);
  // delay(100);
  // dht.begin();
  Ethernet.begin(mac, ip);
  client.setServer(mqtt_server, 1883);
}

void loop()
{
  if (!client.connected())
  {
    reconnect();
  }
  client.loop();
  if (millis() - mytime > updateInterval)
  {
    mytime = millis();
    sensors();
  }
}
#endif

If i compile this, i get this messages:

Task wird ausgeführt: C:\Users\markus\.platformio\penv\Scripts\platformio.exe run 

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION:  "https:/ /docs.platformio.org/page/boards/atmelavr/nanoatmega328.html"
PLATFORM: Atmel AVR (3.4.0) > Arduino Nano ATmega328 
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash      
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)       
LDF: Library Dependency Finder -> https: / /bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
Dependency Graph
|-- SPI @ 1.0
Building in release mode
Compiling .pio\build\nanoatmega328\src\main.cpp.o
Compiling .pio\build\nanoatmega328\lib606\SPI\SPI.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\CDC.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial.cpp.o
Archiving .pio\build\nanoatmega328\lib606\libSPI.a
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial0.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial3.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\PluggableUSB.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\Print.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\Stream.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\Tone.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\USBCore.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\WInterrupts.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\WMath.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\WString.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\abi.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\hooks.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\main.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\new.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_analog.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_digital.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_pulse.S.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\nanoatmega328\libFrameworkArduino.a
Linking .pio\build\nanoatmega328\firmware.elf
C:\Users\markus\AppData\Local\Temp\ccO38mBa.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_main.cpp.o.1894':
<artificial>:(.text.startup+0x70): undefined reference to `EthernetClient::EthernetClient()'
<artificial>:(.text.startup+0x7c): undefined reference to `PubSubClient::PubSubClient(Client&)'
C:\Users\markus\AppData\Local\Temp\ccO38mBa.ltrans0.ltrans.o: In function `main':
<artificial>:(.text.startup+0x13e): undefined reference to `Ethernet'
<artificial>:(.text.startup+0x140): undefined reference to `Ethernet'
<artificial>:(.text.startup+0x142): undefined reference to `UIPEthernetClass::begin(unsigned char const*, IPAddress)'
<artificial>:(.text.startup+0x152): undefined reference to `PubSubClient::setServer(char const*, unsigned int)'
<artificial>:(.text.startup+0x16e): undefined reference to `PubSubClient::connected()'
<artificial>:(.text.startup+0x1de): undefined reference to `PubSubClient::connected()'
<artificial>:(.text.startup+0x200): undefined reference to `PubSubClient::connect(char const*, char const*, char const*)'
<artificial>:(.text.startup+0x232): undefined reference to `PubSubClient::state()'
<artificial>:(.text.startup+0x2be): undefined reference to `PubSubClient::loop()'
<artificial>:(.text.startup+0x344): undefined reference to `PubSubClient::publish(char const*, char const*)'
C:\Users\markus\AppData\Local\Temp\ccO38mBa.ltrans0.ltrans.o: In function `_GLOBAL__sub_D_sensorPin':
<artificial>:(.text.exit+0x4): undefined reference to `PubSubClient::~PubSubClient()'
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\nanoatmega328\firmware.elf] Error 1
==================================================================================== [FAILED] Took 8.47 seconds ====================================================================================

Are there problems with the fimware ==> [.pio\build\nanoatmega328\firmware.elf] Error 1

Could someone help me or give me an idea

No, that’s really wrong. This has to be

If that isn’t working although you have the libraries in lib_deps, it’s an issue with the library dependency finder. Since you wrap the include in #if ... statements, you’ll have to use a different lib_ldf_mode, which means e.g. adding

lib_ldf_mode = deep+

in your platformio.ini, or pulling the includes out of the `#if block.

Hi, I included the headerfiles you said.
But the system can’t find the two headerfiles
==> #include <PubSubClient.h>
==> #include <EthernetENC.h>

I think anywhere I can see where the headerfiles should be there (the place, where they have to be normally).

The two headerfiles I have on hard disk in an arduino project.

Here are the compilermessage:

==>
Task wird ausgeführt: C:\Users\markus.platformio\penv\Scripts\platformio.exe run

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via -v, --verbose option
CONFIGURATION: https:/ /docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:

  • framework-arduino-avr @ 5.1.0
  • toolchain-atmelavr @ 1.70300.191015 (7.3.0)
    LDF: Library Dependency Finder → https:/ /bit.ly/configure-pio-ldf
    LDF Modes: Finder ~ chain, Compatibility ~ soft
    Found 5 compatible libraries
    Scanning dependencies…
    Dependency Graph
    |-- SPI @ 1.0
    Building in release mode
    Compiling .pio\build\nanoatmega328\src\main.cpp.o
    src\main.cpp:90:10: fatal error: PubSubClient.h: No such file or directory

  • Looking for PubSubClient.h dependency? Check our library registry!
  • CLI > platformio lib search “header:PubSubClient.h”
  • Web > PlatformIO Registry

#include <PubSubClient.h>
^~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1
============================================================================================= [FAILED] Took 2.32 seconds =============================================================================================

  • Der Terminalprozess “C:\Users\markus.platformio\penv\Scripts\platformio.exe ‘run’” wurde mit folgendem Exitcode beendet: 1.
  • Das Terminal wird von Aufgaben wiederverwendet, drücken Sie zum Schließen eine beliebige Taste.

Waht should I do to implement the headerfile “PubSubClient.h” ??

What’s your full platformio.ini? Have you tried my lib_ldf_mode suggestions?

I insert the line in the platformio.ini:

[env:nanoatmega328]
platform = atmelavr
board = nanoatmega328
framework = arduino
lib_ldf_mode = deep+

Then I compiled it, without success.
==>

Task wird ausgeführt: C:\Users\markus\.platformio\penv\Scripts\platformio.exe run 

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Nano ATmega328 
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash      
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)       
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 5 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Compiling .pio\build\nanoatmega328\src\main.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial1.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial2.cpp.o
Compiling .pio\build\nanoatmega328\FrameworkArduino\HardwareSerial3.cpp.o
src\main.cpp:90:10: fatal error: PubSubClient.h: No such file or directory

**********************************************************************
* Looking for PubSubClient.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:PubSubClient.h"
* Web  > https:/ /registry.platformio.org/search?q=header:PubSubClient.h
*
**********************************************************************

 #include <PubSubClient.h>
          ^~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\nanoatmega328\src\main.cpp.o] Error 1
============================================================================================= [FAILED] Took 3.24 seconds =============================================================================================

 *  Der Terminalprozess "C:\Users\markus\.platformio\penv\Scripts\platformio.exe 'run'" wurde mit folgendem Exitcode beendet: 1. 
 *  Das Terminal wird von Aufgaben wiederverwendet, drücken Sie zum Schließen eine beliebige Taste. 

The headerfiles included as follow:

#include <PubSubClient.h>
#include <EthernetENC.h>

But there are no lib_deps lins in this platformio.ini at all? Please use the library dependency management like the documentation says. Try to come up with the correct expression yourself using the docs and the registry.

You should arrive at.

lib_deps =
   jandrassy/EthernetENC@^2.0.3
   knolleary/PubSubClient@^2.8

Hi maxgerhardt, thank you for your help, now the problem with the headerfiles is solved.

Upload-Message:

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https:/ /docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR (3.4.0) > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (avr-stub) On-board (avr-stub, simavr)
PACKAGES:
 - framework-arduino-avr @ 5.1.0
 - tool-avrdude @ 1.60300.200527 (6.3.0)
 - toolchain-atmelavr @ 1.70300.191015 (7.3.0)
LDF: Library Dependency Finder -> https:/ /bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Found 8 compatible libraries
Scanning dependencies...
Dependency Graph
|-- EthernetENC @ 2.0.3
|-- PubSubClient @ 2.8.0
Building in release mode
Compiling .pio\build\nanoatmega328\src\main.cpp.o
src\main.cpp: In function 'void loop()':
src\main.cpp:76:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (millis() - mytime > updateInterval)
         ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
Linking .pio\build\nanoatmega328\firmware.elf
Checking size .pio\build\nanoatmega328\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [======    ]  57.7% (used 1182 bytes from 2048 bytes)
Flash: [=======   ]  68.5% (used 21050 bytes from 30720 bytes)
Building .pio\build\nanoatmega328\firmware.hex
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Using manually specified: COM7
Uploading .pio\build\nanoatmega328\firmware.hex

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file ".pio\build\nanoatmega328\firmware.hex"
avrdude: writing flash (21050 bytes):

Writing | ################################################## | 100% 5.94s

avrdude: 21050 bytes of flash written
avrdude: verifying flash memory against .pio\build\nanoatmega328\firmware.hex:
avrdude: load data flash data from input file .pio\build\nanoatmega328\firmware.hex:
avrdude: input file .pio\build\nanoatmega328\firmware.hex contains 21050 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 4.51s

avrdude: verifying ...
avrdude: 21050 bytes of flash verified

avrdude: safemode: Fuses OK (E:00, H:00, L:00)

avrdude done.  Thank you.

But I don’t know, maybe you can say why the system don’t publish the data.
I use MOSQUITTO on my pc, I’ve installed, its working. I testes wit MQTT-FX.
But if I subscribe there with “#” to get all messages, nothing happens.

In first step, the controller could not connect to the broker:

Task wird ausgeführt: C:\Users\markus\.platformio\penv\Scripts\platformio.exe device monitor --port COM7 

--- Terminal on COM7 | 9600 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...failed, rc=-2 try again in 5 seconds

The problem is the controller. the controller is connected over a switch with my pc, and I can see, that the protocol-LED (orange) on the switch is not blinking. If i make the same test with an arduino uno with ethernetshield w5100, this LED is blinking.

Here the code at the moment:

#include <EthernetENC.h>
#include <PubSubClient.h>
// #include <UIPEthernet.h>
#define DEBUG 0 // Debug output to serial console




// IPAddress i(10, 10, 1, 1);

unsigned long mytime = 0;
byte mac[] = {0x80, 0x7D, 0x3A, 0x69, 0x20, 0xC8}; // physical mac address
byte ip[] = {192, 168, 178, 199};                   // ip in lan
const char *mqtt_server = "192.168.178.55";         // => Localhost, MOSQUITTO on own PC
const char *mqttUser = "";                          // => I have no password ans id !!!
const char *mqttPassword = "";

char buf[4];               // Buffer to store the sensor value
int updateInterval = 5000; // Interval in milliseconds
EthernetClient espClient;
PubSubClient client(espClient);

void reconnect()
{
    // Loop until we're reconnected
    while (!client.connected())
    {
        Serial.print("Attempting MQTT connection...");
        // Attempt to connect
        if (client.connect("arduinoClientSuperior", mqttUser, mqttPassword))
        {
            Serial.println("connected");
        }
        else
        {
            Serial.print("failed, rc=");
            Serial.print(client.state());
            Serial.println(" try again in 5 seconds");
            // Wait 5 seconds before retrying
            delay(5000);
        }
    }
}

void sensors()
{
    

    //// TEST-Message
    client.publish("AtHome/Testarea", "very wet !!!");



    


}

void setup()
{
    // pzem.setAddress(i);
     Serial.begin(9600);
     delay(100);
    // dht.begin();
    Ethernet.begin(mac, ip);
    client.setServer(mqtt_server, 1883);
}

void loop()
{
    if (!client.connected())
    {
        reconnect();
    }
    client.loop();
    if (millis() - mytime > updateInterval)
    {
        mytime = millis();
        sensors();
    }
}

Is there a problem with TCP / UDP, how can I change it.

You’re not configuring the Chip-Select pin at all? The EthernetENC.h library has (same as the Ethernet.h library) this member method.

Please for a moment don’t try and get your sketch working but copy-paste the WebClientRepeating.ino example first and take care to 1. change the #include <Ethernet.h> to #include <EthernetENC.h> and 2. do the right init call. How do you exactly connect the ENC2860 to your Arduino Nano?

Hi, I looked in the socumentation of the board:

It is pin 10, I tried also the WebClient.ino with “Ethernet.h” and “EhternetENC.h”, both was running, with DHCP, it runs into the DCHP-control structure.

So, the i tried the MQTT again, also with

=> Ethernet.init(10);

But the state is there the same as before …

==> — Terminal on COM10 | 9600 8-N-1
— Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
— More details at Redirecting...
— Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
Attempting MQTT connection…failed, rc=-2 try again in 5 seconds
Attempting MQTT connection…

Here the code I changed …

Blockquote
void setup()
{

 Serial.begin(9600);
 delay(100);

//// CS with Pin 10
Ethernet.init(10);

Ethernet.begin(mac, ip);
client.setServer(mqtt_server, 1883);

}

Blockquote

Well you’re not checking the return value of this function at all, so this might have already returned “failure”. You should check it like in the examples.

The EthernetENC library has some debug flags you can activate that may point to where the error is: Whether no Ethernet connection exists at all, or whether MQTT conenct fails for other reasons.

So, you can add

build_flags =
   -DUIPETHERNET_DEBUG
   -DUIPETHERNET_DEBUG_CHKSUM
   -DUIPETHERNET_DEBUG_UDP
   -DUIPETHERNET_DEBUG_CLIENT

to the platformio.iniand reupload your sketch for more output.

Hi, I completed the code with the necessary information about hte state, also the debugstates in the platoformio.ini.

My impression:

  • I see in the outputs, that the system work with DHCP, but why?
  • the protocol is UDP, maybe this is a problem?
    -There is no coming forward in the MQTT-connect method, there the controller coould not connect

Here are the output information:

 *  Task wird ausgeführt: C:\Users\markus\.platformio\penv\Scripts\platformio.exe device monitor --port COM7 

--- Terminal on COM7 | 9600 8-N-1
--- Available filters and text transformations: colorize, debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https:/ /bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
��␀�CS on Ethernetboard with PIN 10 
Initialize Ethernet with DHCP:
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
chksum uip_buf[34-42]: CE02
chksum uip_packet(1)[42-317]: 4FA8
Enc28J60Network_send uip_packet: 1, hdrlen: 42
udp, uip_packet to send: 0
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 10000
chksum uip_buf[34-42]: ABF7
chksum uip_packet(255)[42-50]: FFFF
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 10000
chksum uip_buf[34-42]: ABF7
chksum uip_packet(255)[42-50]: FFFF
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 10000
chksum uip_buf[34-42]: ABF7
chksum uip_packet(255)[42-50]: FFFF
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 10000
chksum uip_buf[34-42]: ABF7
chksum uip_packet(255)[42-50]: FFFF
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 325
chksum uip_buf[34-42]: CE02
chksum uip_packet(1)[42-317]: 54A8
Enc28J60Network_send uip_packet: 1, hdrlen: 42
udp, uip_packet to send: 0
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 590, bits: 0
chksum uip_buf[34-42]: 1DC
chksum uip_packet(255)[42-590]: FFFF
udp, uip_newdata received packet: 1, size: 548
freeing received packet
udp parsePacket received packet: 1, size: 548
udp beginPacket, rip: 255.255.255.255, port: 67
udp, uip_poll preparing packet to send: 1, size: 337
chksum uip_buf[34-42]: E602
chksum uip_packet(1)[42-329]: E2F7
Enc28J60Network_send uip_packet: 1, hdrlen: 42
udp, uip_packet to send: 0
--------------
packet received
readPacket type IP, uip_len: 590, bits: 0
chksum uip_buf[34-42]: 1D9
chksum uip_packet(255)[42-590]: FFFF
udp, uip_newdata received packet: 1, size: 548
freeing received packet
udp parsePacket received packet: 1, size: 548
--------------
packet received
freeing received packet
  DHCP assigned IP 192.168.178.26
Attempting MQTT connection...stop(), data: NULL
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 8DDD
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 8DDD
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
chksum uip_buf[34-58]: 8DDD
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 8DDD
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...stop(), data: NULL
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 56DE
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 56DE
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
chksum uip_buf[34-58]: 56DE
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
readPacket type ARP, uip_len: 60
freeing received packet
chksum uip_buf[34-58]: 56DE
Enc28J60Network_send uip_buf (uip_len): 58, packet: 1, bits: 10
--------------
packet received
readPacket type IP, uip_len: 60, bits: 0
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
--------------
packet received
freeing received packet
failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...sto

Strange, RetrunCode at connecting is “-2” ==> MQTT_CONNECT_FAILED

I want to connect without credentials, UserID and PAssWord are NULL.

Nobody has an idea? One thing what could be possible, maybe the firewall für port 1883 is denied ??

If you have the board connected to a switch or hub, does that mean your PC’s Ethernet connection also gets to see all the data received and sent to the board? Can you then not install + execute Wireshark and listen to all the packets sent by the board’s MAC address to see what’s going in the connect process? If TCP SYN is sent, how it is answered, etc., to establish the TCP connection.

I will test it, at first:

  • I will be sure that no port is denied
  • connect only my pc with Mosquitto-broker and the controller togehter with the switch (without fritzbox)

Wireshark, I heard of them, but never used.

Where can I adjust the static IP-adress, could someone give me advice.

Then one other question. Is it possible to debug the Arduino Uno / Nano with an online debugtool / hardware to see the variables / bits … ?

Wireshark has powerful filter expressions. You can just say ip.adr == 192.168.1.199 for example and it’ll filter packets for that. See https://linuxhint.com/filter_by_ip_wireshark/.

Yes, that’s called avr-stub, it’s usage is documented here, however that will use the Serial port for itself, so you’ll have to disable every single print Serial object usage in your application and in the libraries (that were e.g. enabled through build_flags). See e.g. https://www.youtube.com/watch?v=7wx27FcluMg.