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