Error compiling for baord Arduino Uno

My code was working but I needed a different distance sensor so I switched from the lidar based sensor to an ultrasonic one. Now I get this error.

In file included from C:\Users\Jay\Documents\Arduino\brotel-with-sonar\brotel-with-sonar.ino:4:0:
C:\Users\Jay\Documents\Arduino\libraries\Adafruit_MQTT_Library/Adafruit_MQTT.h:54:0: warning: "DEBUG_PRINT" redefined
 #define DEBUG_PRINT(...)                                                       \
 
In file included from C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/includes/platform/FONAPlatform.h:31:0,
                 from C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/Adafruit_FONA.h:9,
                 from C:\Users\Jay\Documents\Arduino\brotel-with-sonar\brotel-with-sonar.ino:3:
C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/includes/platform/FONAPlatStd.h:53:0: note: this is the location of the previous definition
 #define DEBUG_PRINT(...) DebugStream.print(__VA_ARGS__)
 
In file included from C:\Users\Jay\Documents\Arduino\brotel-with-sonar\brotel-with-sonar.ino:4:0:
C:\Users\Jay\Documents\Arduino\libraries\Adafruit_MQTT_Library/Adafruit_MQTT.h:56:0: warning: "DEBUG_PRINTLN" redefined
 #define DEBUG_PRINTLN(...)                                                     \
 
In file included from C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/includes/platform/FONAPlatform.h:31:0,
                 from C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/Adafruit_FONA.h:9,
                 from C:\Users\Jay\Documents\Arduino\brotel-with-sonar\brotel-with-sonar.ino:3:
C:\Users\Jay\Documents\Arduino\libraries\Adafruit_FONA_Library/includes/platform/FONAPlatStd.h:54:0: note: this is the location of the previous definition
 #define DEBUG_PRINTLN(...) DebugStream.println(__VA_ARGS__)
 
C:\Users\Jay\AppData\Local\Temp\cc14jaCj.ltrans0.ltrans.o: In function `setup':
C:\Users\Jay\Documents\Arduino\brotel-with-sonar/brotel-with-sonar.ino:106: undefined reference to `FONAconnect(__FlashStringHelper const*, __FlashStringHelper const*, __FlashStringHelper const*)'
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "Adafruit_BusIO_Register.h"
 Used: C:\Users\Jay\Documents\Arduino\libraries\Adafruit_BusIO-master
 Not used: C:\Users\Jay\Documents\Arduino\libraries\Adafruit_BusIO
exit status 1
Error compiling for board Arduino Uno.

Here is my code.

#include <Adafruit_SleepyDog.h>
#include <SoftwareSerial.h>
#include "Adafruit_FONA.h"
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_FONA.h"
#include <ComponentObject.h>
#include <Wire.h>
#include <Adafruit_AHTX0.h>

/*************************** FONA Pins ***********************************/

// Default pins for Feather 32u4 FONA
#define FONA_RX  2
#define FONA_TX  3
#define FONA_RST 4
SoftwareSerial fonaSS = SoftwareSerial(FONA_TX, FONA_RX);

Adafruit_FONA fona = Adafruit_FONA(FONA_RST);

Adafruit_AHTX0 aht;


/************** Sonar Pin (PWN) ***********/
#define sensorPin 7


/************************* WiFi Access Point *********************************/
#define FONA_APN       "m2mglobal"
#define FONA_USERNAME  ""
#define FONA_PASSWORD  ""

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "*.*.*.*"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    ""
#define AIO_KEY         ""

/************ Global State (you don't need to change this!) ******************/

// Setup the FONA MQTT class by passing in the FONA class and MQTT server and login details.
Adafruit_MQTT_FONA mqtt(&fona, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);

// You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1);  }

// FONAconnect is a helper function that sets up the FONA and connects to
// the GPRS network. See the fonahelper.cpp tab above for the source!
boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *username, const __FlashStringHelper *password);

/****************************** Feeds ***************************************/

// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, "sensors/temperature");
Adafruit_MQTT_Publish humidityPub = Adafruit_MQTT_Publish(&mqtt, "sensors/humidity");
Adafruit_MQTT_Publish depthPub = Adafruit_MQTT_Publish(&mqtt, "sensors/depth");

/*************************** Sketch Code ************************************/

// How many transmission failures in a row we're willing to be ok with before reset
uint8_t txfailures = 0;
#define MAXTXFAILURES 3

float distance = 0;
float duration = 0;
float snowDepth = 0;

void setup() {
  pinMode(sensorPin, INPUT);
Wire.begin();
  while (!Serial);

  // Watchdog is optional!
  //Watchdog.enable(8000);


  
  Serial.begin(115200);


    if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found");




   if (! aht.begin()) {
    Serial.println("Could not find AHT? Check wiring");
    while (1) delay(10);
  }
  Serial.println("AHT10 or AHT20 found");

  Serial.println(F("Adafruit FONA MQTT demo"));

  //mqtt.subscribe(&onoffbutton);

  Watchdog.reset();
  delay(5000);  // wait a few seconds to stabilize connection
  Watchdog.reset();
  
  // Initialise the FONA module
  while (! FONAconnect(F(FONA_APN), F(FONA_USERNAME), F(FONA_PASSWORD))) {
    Serial.println("Retrying FONA");
  }

  Serial.println(F("Connected to Cellular!"));

  Watchdog.reset();
  delay(5000);  // wait a few seconds to stabilize connection
  Watchdog.reset();
}

//uint32_t x=0;


void loop() {
    delay(42000);

/******** Read Sonar Sensor *************/
duration = pulseIn(sensorPin, HIGH);
distance = duration / 58;
snowDepth = distance / 2.54;

Serial.print("distance = ");
Serial.print(snowDepth);
Serial.println(" inches");


    
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data

  float tempF = temp.temperature * (9.0/5.0) + 32.0;
  float hum = humidity.relative_humidity;

  String tempString = String(tempF, 2);
  
  Serial.print("Temperature: "); Serial.print(tempF); Serial.println(" degrees C");
  Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");


  
  // Make sure to reset watchdog every loop iteration!
  Watchdog.reset();

  // Ensure the connection to the MQTT server is alive (this will make the first
  // connection and automatically reconnect when disconnected).  See the MQTT_connect
  // function definition further below.
  MQTT_connect();

  Watchdog.reset();
  // Now we can publish stuff!
  Serial.print(F("\nSending photocell val "));
  Serial.print(tempF);
  Serial.print("...");
  if (! photocell.publish(tempF)) {
    Serial.println(F("Failed"));
    txfailures++;
  } else {
    Serial.println(F("OK!"));
    txfailures = 0;
  }

    Serial.print(F("\nSending humidityPub val "));
  Serial.print(hum);
  Serial.print("...");
  if (! humidityPub.publish(hum)) {
    Serial.println(F("Failed"));
    txfailures++;
  } else {
    Serial.println(F("OK!"));
    txfailures = 0;
  }

      Serial.print(F("\nSending depthPub val "));
  Serial.print(snowDepth);
  Serial.print("...");
  if (! depthPub.publish(snowDepth)) {
    Serial.println(F("Failed"));
    txfailures++;
  } else {
    Serial.println(F("OK!"));
    txfailures = 0;
  }


  Watchdog.reset();  

}

void sensorReading() {
  
}


// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {
    return;
  }

  Serial.print("Connecting to MQTT... ");

  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
    Serial.println(mqtt.connectErrorString(ret));
    Serial.println("Retrying MQTT connection in 5 seconds...");
    mqtt.disconnect();
    delay(5000);  // wait 5 seconds
  }
  Serial.println("MQTT Connected!");
}

You'll need to post your code using code tags </> ad some kind of schematic to get proper help.

1 Like

This line is causing your error. You are declaring this function but it is never defined. Where did you get it from? The comments would suggest a companion file fonahelper.cpp that needs to be available. Is it available?

@blh64 Thanks! That was my problem. I had opened a new window and cut and pasted the code from the old one and didn't bring over the helper file. Much appreciated!