ropg / heltec_esp32_lora_v3

Proper working Arduino library for the Heltec ESP32 LoRa v3 board, as well as for Wireless Stick v3 and Wireless Stick Lite v3. Uses RadioLib
MIT License
332 stars 16 forks source link

multiple definition #28

Closed jo-ei closed 2 months ago

jo-ei commented 3 months ago

Hi, i go the following error in VSC with platformio:

multiple definition of _Z10heltec_ledi; PlatformIO/Projects/LoRa_Sensor/.pio/libdeps/my-config/Heltec_ESP32_LoRa_v3/src/heltec_unofficial.h:222: first defined here

i got these for: heltec_led, heltec_ve, heltec_vbat, heltec_deep_sleep, heltec_setup

Somehow I'm not sure where that comes from. can anyone give me a tip on where I am include something wrong?

thx

main.cpp

#include "main.h"

void setup() {
  heltec_setup();

  lorawan_init();

}

void loop() {
  heltec_loop();

}

lorawan.cpp

#include "lorawan.h"

void lorawan_init(){

  // initialize radio
  Serial.println("Radio init");
  int16_t state = radio.begin();
  if (state != RADIOLIB_ERR_NONE) {
    Serial.println("Radio did not initialize. We'll try again later.");
    //goToSleep();
  }

  node = persist.manage(&radio);

  if (!node->isActivated()) {
    Serial.println("Could not join network. We'll try again later.");
    //goToSleep();
  }

  // If we're still here, it means we joined, and we can send something

  // Manages uplink intervals to the TTN Fair Use Policy
  node->setDutyCycle(true, 1250);

};

main.h

#ifndef _MAIN_H
#define _MAIN_H

#include "lorawan.h"
#include "sleep.h"

#endif

sleep.h

#ifndef _SLEEP_H
#define _SLEEP_H

// Save LoRaWAN Session an go to deep sleep

void goToSleep() {
  Serial.println("Going to deep sleep now");
  // allows recall of the session after deepsleep
  persist.saveSession(node);
  // Calculate minimum duty cycle delay (per FUP & law!)
  uint32_t interval = node->timeUntilUplink();
  // And then pick it or our MINIMUM_DELAY, whichever is greater
  uint32_t delayMs = max(interval, (uint32_t)MINIMUM_DELAY * 1000);
  Serial.printf("Next TX in %i s\n", delayMs/1000);
  delay(100);  // So message prints
  // and off to bed we go
  heltec_deep_sleep(delayMs/1000);
}

#endif

lorawan.h

#ifndef _LORAWAN_H
#define _LORAWAN_H

#include <heltec_unofficial.h>
#include <LoRaWAN_ESP32.h>

// Pause between sends in seconds, so this is every 15 minutes. (Delay will be
// longer if regulatory or TTN Fair Use Policy requires it.)
#define MINIMUM_DELAY 900 

LoRaWANNode* node;
RTC_DATA_ATTR uint8_t count = 0;

void lorawan_init();

#endif

platformio.ini

[platformio]
default_envs = my-config
description = Firmware for device

[env:my-config]
platform = espressif32

board = heltec_wifi_lora_32_V3
framework = arduino
monitor_speed = 115200
monitor_filters =
    default
    esp32_exception_decoder

platform_packages=
  platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.1
  platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1

lib_deps = 
    ropg/Heltec_ESP32_LoRa_v3@^0.9.1
    ropg/LoRaWAN_ESP32@^1.1.0
    jgromes/RadioLib@^6.6.0

lib_ignore =
    thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays

build_flags = 
    -D Wireless_Stick_V3=1
    -D HELTEC_WIRELESS_STICK_LITE=1
    -D NO_DISPLAY=1
    -D ESP_ARDUINO_VERSION_MAJOR=3
aintgotnoname commented 3 months ago

both "lorawan.cpp" and "main.cpp" directly or indirectly include "heltec_unofficial.h" which contains the definition of the code block for heltec_led() and its siblings. it seems the linker treats each include reference as a duplicate definition of the same block; thus generating an error(s).

imho, you will need to determine a means of declaring these references to a single inclusion of heltec_unofficial.h within your project. this may be performed by littering the code with extern declarations of the functions, or creation of an additional include file with the function prototypes. other workarounds may exist, but are not known to me.

Velocet commented 3 months ago

[env:my-config] board = heltec_wifi_lora_32_V3

build_flags = -D Wireless_Stick_V3=1 -D HELTEC_WIRELESS_STICK_LITE=1

Why are there three different board definitions? Choose one and stick to it or better: don't use build flags you don't know.

If you really have a LoRa32v3 then delete those two build flags.