Collect2: error: ld returned 1 exit status

Hi

I am trying to build my code but I get an error saying:

collect2: error: ld returned 1 exit status

*** [.pioenvs/esp01_1m/firmware.elf] Error 1

I have update the platform arduinoespressif8266 to latest one but still get the same error.

my main.ino file is :

 
/*
 * IRremoteESP8266: IRServer - MQTT IR server
 * An IR LED must be connected to ESP8266 RX port (GPIO-3)
 * An IR receiver to GPIO 0
 * used library:
 * https://github.com/markszabo/IRremoteESP8266
 */

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <IRremoteESP8266.h>
#include <PubSubClient.h>

int RECV_PIN = 0; //an IR detector/demodulator is connected to GPIO pin 0

IRrecv irrecv(RECV_PIN);

const char* ssid = “XXXX";
const char* password = “XXXX";

const char* topicRaportPrefix = "esp8266/02/info/";
const char* topicSubscribe = "esp8266/02/sender/#";
const char* topicPrefix = "esp8266/02/";

const char* mqtt_server = “XXXX";
const char* mqtt_user = “XXXX";
const char* mqtt_pass = “XXXX";

String clientName; // MQTT client name
char message_buff[100];



// Pin of IR sender
IRsend irsend(3); // rx port z RS232

WiFiClient wifiClient;


void callback(char* topic, byte* payload, unsigned int length);
void connect_to_MQTT();

PubSubClient client(mqtt_server, 1883, callback, wifiClient);

// -----------------------------------------------------------------

void callback(char* topic, byte* payload, unsigned int length) {
  int i = 0;

  Serial.println("Message arrived:  topic: " + String(topic));
  Serial.println("Length: " + String(length,DEC));

  // create character buffer with ending null terminator (string)
  for(i=0; i<length; i++) {
    message_buff[i] = payload[i];
  }
  message_buff[i] = '\0';

  unsigned int freq=38;
  String msgString = String(message_buff);
  String msgTopic = String(topic);
  unsigned long msgInt = msgString.toInt();

  Serial.println("Payload String: " + msgString);

  // structure "esp8266/02/sender/type[/bits[/panasonic_address]]"
  int endOfBits;
  String irTypStr = "";
  String irBitsStr = "";
  int irBitsInt=-1;
  String irPanasAddrStr = "";

  int endOfTyp = msgTopic.indexOf("/",20);
  if (endOfTyp == -1)
  {
    // One element - only irTyp
    irTypStr  = msgTopic.substring(18);
  } else {
    // irTyp exists and something more
    irTypStr  = msgTopic.substring(18, endOfTyp);
    endOfBits = msgTopic.indexOf("/",endOfTyp+1);
    if (endOfBits== -1)
    {
      // irBits is last
      irBitsStr = msgTopic.substring(endOfTyp+1);
    } else {
      // irBits and something more
      irBitsStr = msgTopic.substring(endOfTyp+1, endOfBits);
      irPanasAddrStr = msgTopic.substring(endOfBits+1);
    }
    irBitsInt = irBitsStr.toInt();
  }


  Serial.println(irTypStr);
  Serial.println(irBitsStr);
  Serial.println(irPanasAddrStr);
  if (irTypStr=="NEC") {

    Serial.print("Send NEC:");
    Serial.println(msgInt);
    irsend.sendNEC(msgInt, 36);
  } else if (irTypStr=="RC5") {
    Serial.print("Send RC5:");
    Serial.print(msgInt);
    Serial.print(" (");
    Serial.print(irBitsInt);
    Serial.println("-bits)");
    irsend.sendRC5(msgInt, irBitsInt);
  }

}

// -----------------------------------------------------------------
String macToStr(const uint8_t* mac)
{
  String result;
  for (int i = 0; i < 6; ++i) {
    result += String(mac[i], 16);
    if (i < 5)
      result += ':';
  }
  return result;
}

// -----------------------------------------------------------------
void setup(void){
  irsend.begin();
  irrecv.enableIRIn();  // Start the receiver

  Serial.begin(115200,SERIAL_8N1,SERIAL_TX_ONLY);

  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());

  clientName += "esp8266-";
  uint8_t mac[6];
  WiFi.macAddress(mac);
  clientName += macToStr(mac);
  clientName += "-";
  clientName += String(micros() & 0xff, 16);

  connect_to_MQTT();

}

// -----------------------------------------------------------------
void connect_to_MQTT() {
  Serial.print("Connecting to ");
  Serial.print(mqtt_server);
  Serial.print(" as ");
  Serial.println(clientName);
  char myTopic[100];

  int is_conn = 0;
  while (is_conn == 0) {
    if (client.connect((char*) clientName.c_str(), mqtt_user, mqtt_pass)) {
      Serial.println("Connected to MQTT broker");
      sprintf(myTopic, "%sclient", topicRaportPrefix);
      client.publish((char*)myTopic, (char*) clientName.c_str());
      IPAddress myIp = WiFi.localIP();
      char myIpString[24];
      sprintf(myIpString, "%d.%d.%d.%d", myIp[0], myIp[1], myIp[2], myIp[3]);
      sprintf(myTopic, "%sip", topicRaportPrefix);
      client.publish((char*)myTopic, (char*) myIpString);
      sprintf(myTopic, "%stype", topicRaportPrefix);
      client.publish((char*)myTopic,"IR server");
      Serial.print("Topic is: ");
      Serial.println(topicSubscribe);
      if (client.subscribe(topicSubscribe)){
        Serial.println("Successfully subscribed");
      }

      is_conn = 1;
    }
    else {
      Serial.print("MQTT connect failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

// -----------------------------------------------------------------
// Encodig of data
void  encoding (decode_results *results, char * result_encoding)
{
  switch (results->decode_type) {
    default:
    case UNKNOWN:      strncpy(result_encoding,"UNKNOWN\0",8);       break ;
    case NEC:          strncpy(result_encoding,"NEC\0",4);           break ;
    case SONY:         strncpy(result_encoding,"SONY\0",5);          break ;
    case RC5:          strncpy(result_encoding,"RC5\0",4);           break ;
    case RC6:          strncpy(result_encoding,"RC6\0",4);           break ;
    case DISH:         strncpy(result_encoding,"DISH\0",5);          break ;
    case SHARP:        strncpy(result_encoding,"SHARP\0",6);         break ;
    case JVC:          strncpy(result_encoding,"JVC\0",4);           break ;
    case SANYO:        strncpy(result_encoding,"SANYO\0",6);         break ;
    case MITSUBISHI:   strncpy(result_encoding,"MITSUBISHI\0",11);   break ;
    case SAMSUNG:      strncpy(result_encoding,"SAMSUNG\0",8);       break ;
    case LG:           strncpy(result_encoding,"LG\0",3);            break ;
    case WHYNTER:      strncpy(result_encoding,"WHYNTER\0",8);       break ;
    case PANASONIC:    strncpy(result_encoding,"PANASONIC\0",11);    break ;
  }
}

// -----------------------------------------------------------------
void loop(void){
  client.loop();

  if (! client.connected()) {
    Serial.println("Not connected to MQTT....");
    connect_to_MQTT();
  }
  decode_results  results;        // Somewhere to store the results
  if (irrecv.decode(&results)) {  // Grab an IR code
    char myTopic[100];
    char myTmp[50];
    char myValue[500];
    encoding (&results, myTmp);
    if (results.decode_type == PANASONIC) { //Panasonic has address
      // struktura "prefix/typ/bits[/panasonic_address]"
      sprintf(myTopic, "%sreceiver/%s/%d/%d", topicPrefix, myTmp, results.bits, results.panasonicAddress );
    } else {
      sprintf(myTopic, "%sreceiver/%s/%d", topicPrefix, myTmp, results.bits );
    }
    if (results.decode_type != UNKNOWN) {
      // any other has code and bits
      sprintf(myValue, "%d", results.value);
      client.publish((char*) myTopic, (char*) myValue );
    }
    irrecv.resume();              // Prepare for the next value
  }
}

Can someone please help?

Thanks.

Could you try to rename file to main.cpp and provide full build output using pio run -v and share on http://pastebin.com

Hi !

I UP this post because I have the same issue !
There is my output (with verbose option): IRRemote issue - Pastebin.com

I removed some warning not linked to IRremote lib.
My program works fine without this library !

Did someone has already solved this issue ?

Thanks.

Can you add your platformio.ini and your source code so we can reproduce the problem?

There is the script example:

And the platformio.ini:

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
upload_port = COM3

; Serial Monitor options
monitor_port = COM3
monitor_speed = 115200

Your sketch requires the IRremote library. When you compiled your project, some IRremote library was found but possible an invalid one. So it’s helpful to make it more explicit. The most reliable way to work with libraries is to declare them in platformio.ini.

Usually, I would recommend declaring the library like so:

lib_deps =
    IRremote

Unfortunately, several libraries with the name IRremote exist. So it’s required to use the ID in this case:

lib_deps =
    4

The ID can be figured out:

  • Go to PIO Home / Libraries / Registry
  • Search for IRremote
  • Check the details of the libraries; in particular make sure the library is for the Arduino framework
  • Click on Installation and copy the ID

So for your project:

  • Add the above code the platformio.ini
  • Remove the .pio folder in your project directory
  • Build again

I was able to successfully build your code with two additional lines (

2 Likes

PlatformIO also ignores ; comments on libdeps lines, so I like to add the library name after each ID so it’s not quite so confusing, especially when you get a bunch of them and also have version locks happening :wink:

e.g.

lib_deps =
  75@bfef59000d ; Timer
  567@0.14 ; WifiManager
  583@2.0.1 ; ModbusMaster
  1002@1.0.4 ; elapsedMillis
  1467 ; JPEGDecoder
  1559 ; TFT_eSPI
  6164 ; TFT_eFEX
1 Like

Maybe I forgot to tell you I included a IRremote library in the project. I installed it on {project_folder}/lib/IRremote/src

I didn’t installed it by the PIO Libraries page !

EDIT: I’ve just removed it from the lib folder and re-download it from GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
I added all .h and .cpp file in a new folder “src” and it works !

Maybe I was using an old version :slight_smile:

1 Like