why do i get a undefined reference to

I am new to arduino, and get a undefined reference to error. Iam trying to code a transmitter and receiver to receive data from a Adafruit si-7021. This works in serial, but not when i send it.

the code:

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include "Adafruit_Si7021.h"

RH_ASK driver;
struct dataStruct{
 float readHumidity(); //here is the problem
 float readTemperature(); //here is the problem
 float Humidity;
 float Temperature;
 float begin;
 unsigned long counter;

}sensor;


void setup()
{
   Serial.begin(9600);  // Debugging only
   if (!driver.init())
        Serial.println("init failed");

  Adafruit_Si7021 sensor = Adafruit_Si7021();
}

void loop()
{
   uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
   uint8_t buflen = sizeof(buf);

   if (driver.recv(buf, &buflen)) // Non-blocking
   {
 int i;

 // Message with a good checksum received, dump it.
 driver.printBuffer("Got:", buf, buflen);
       memcpy(&sensor, buf, sizeof(sensor));
       Serial.println("");
       
              // Serial.print("press_norm: ");
     //  Serial.print(myData.press_norm);
       
                     Serial.print("  Temperature: ");
       Serial.print(sensor.readTemperature(),  2);
       
                         Serial.print("  Humidity: ");
       Serial.print(sensor.readHumidity(),  2);
       
       Serial.print("  counter: ");
       Serial.println(sensor.counter);
   }
}

and the transmitter:

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include "Adafruit_Si7021.h"


RH_ASK driver;
struct dataStruct{
 float readHumidity();
 float readTemperature();
 float Humidity;
 float Temperature;
 float begin;
 unsigned long counter;

}sensor;

byte tx_buf[sizeof(sensor)] = {0};

void setup() {
Serial.begin(9600);
if (!driver.init())
     Serial.println("init failed");

   Adafruit_Si7021 sensor = Adafruit_Si7021();
   sensor.begin();

 //sensor.Temperature=sensor.readTemperature();
 //sensor.Humidity=sensor.readHumidity();
 //  sensor.readHumidity()=sensor.Humidity
 // sensor.readTemperature()=sensor.Temperature
   
     
}

void loop() {

  memcpy(tx_buf, &sensor, sizeof(sensor) );
 byte zize=sizeof(sensor);

driver.send((uint8_t *)tx_buf, zize);

  // driver.send((uint8_t *)msg, strlen(msg));
   driver.waitPacketSent();
   sensor.counter++;
   delay(2000);
 

}

Please post your code following the directions below.
Please post your complete error message following the directions below.

To post code and/or error messages:

  1. Use CTRL-T in the Arduino IDE to autoformat your complete code.
  2. Paste the complete autoformatted code between code tags (the </> button)
    so that we can easily see and deal with your code.
  3. Paste the complete error message between code tags (the </> button)
    so that we can easily see and deal with your messages.
  4. If you already posted without code tags, you may add the code tags by
    editing your post. Do not change your existing posts in any other way.
    You may make additional posts as needed.

Before posting again, you should read the three locked topics at the top of the Programming Questions forum, and any links to which these posts point.

If your project involves wiring, please provide a schematic and/or a wiring diagram and/or a clear photograph of the wiring.

Good Luck!

Please read this post, http://forum.arduino.cc/index.php?topic=149014.0 and pay attention to point 7 about how to post code.

You gave all but the important part of the error message. WHAT did it say was undefined? Don't cut the error message down. Post the whole thing.

#include <RH_ASK.h>
#include <SPI.h> // Not actualy used but needed to compile
#include <Adafruit_Si7021.h>





RH_ASK driver;
struct dataStruct {
  float readHumidity();
  float readTemperature();
  float Humidity;
  float Temperature;
  float begin;
  unsigned long counter;

} sensor;





void setup()
{
  Serial.begin(9600);  // Debugging only
  if (!driver.init())
    Serial.println("init failed");

  Adafruit_Si7021 sensor = Adafruit_Si7021();
}

void loop()
{
  uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
  uint8_t buflen = sizeof(buf);

  if (driver.recv(buf, &buflen)) // Non-blocking
  {
    int i;

    // Message with a good checksum received, dump it.
    driver.printBuffer("Got:", buf, buflen);
    memcpy(&sensor, buf, sizeof(sensor));
    Serial.println("");

    // Serial.print("press_norm: ");
    //  Serial.print(myData.press_norm);

    Serial.print("  Temperature: ");
    Serial.print(sensor.readTemperature(),  2);

    Serial.print("  Humidity: ");
    Serial.print(sensor.readHumidity(),  2);

    Serial.print("  counter: ");
    Serial.println(sensor.counter);
  }
}

and the error message:

C:\Users\GEBRUI~1\AppData\Local\Temp\ccqT62Cc.ltrans1.ltrans.o: In function `loop':

C:\Users\Gebruiker\Documents\Arduino\sketch_jan30h/sketch_jan30h.ino:51: undefined reference to `dataStruct::readTemperature()'

C:\Users\Gebruiker\Documents\Arduino\sketch_jan30h/sketch_jan30h.ino:54: undefined reference to `dataStruct::readHumidity()'

collect2.exe: error: ld returned 1 exit status

exit status 1
Fout bij het compileren van board Arduino Nano
float readHumidity();
float readTemperature();

Are these supposed to me methods or variables?

struct dataStruct {
  float readHumidity();
  float readTemperature();
  float Humidity;
  float Temperature;
  float begin;
  unsigned long counter;

} sensor;

In this struct you promised to write two functions that belong to the struct one named readHumidity, and one named readTemperature. But you haven't shown where you've written either of those functions.

This

  Adafruit_Si7021 sensor = Adafruit_Si7021();

declares a variable called sensor that immediately goes out of scope.

This

struct dataStruct {
  float readHumidity();
  float readTemperature();
  float Humidity;
  float Temperature;
  float begin;
  unsigned long counter;

} sensor;

declares a variable called sensor that is of type struct dataStruct that is global.

What did you intend? What did you expect?

I would be tempted to start by getting rid of the struct dataStruct, replacing it with the line about Adafruit_Si7021. Then I would get rid of the Adafruit_Si7021 line in the setup() function. But that is just me, you may have a different goal.

I think I have sort it out, but now i get this error:

C:\Users\Gebruiker\Documents\Arduino\sketch_jan31a\sketch_jan31a.ino: In function 'void setup()':

sketch_jan31a:40: error: expression cannot be used as a function

   sensor.Humidity = sensor.readHumidity();

                                         ^

sketch_jan31a:41: error: expression cannot be used as a function

   sensor.Temperature = sensor.readTemperature();

                                               ^

exit status 1
expression cannot be used as a function

with this code:

#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile
#include <Adafruit_Si7021.h>


RH_ASK driver;



struct dataStruct {
  //float press_norm ;
  //float press_hg;
  float temp;
  float press;
  float readHumidity;
  float readTemperature;
  float Humidity;
  float Temperature;
  float begin;
  unsigned long counter;

} sensor;

byte tx_buf[sizeof(sensor)] = {0};

void setup()
{
  Serial.begin(9600);    // Debugging only
  if (!driver.init())
    Serial.println("init failed");


  //myData.press_norm=1000.11;
  //myData.press_hg=0.59;
  //myData.temp=22.394;
  //readHumitidy = sensor.readHumitidy;
  //readTemperature = sensor.readTemperature;
  sensor.Humidity = sensor.readHumidity();
  sensor.Temperature = sensor.readTemperature();



}

void loop()
{



  memcpy(tx_buf, &sensor, sizeof(sensor) );
  byte zize = sizeof(sensor);

  driver.send((uint8_t *)tx_buf, zize);

  // driver.send((uint8_t *)msg, strlen(msg));
  driver.waitPacketSent();
  sensor.counter++;
  delay(2000);


}

//sensor.readTemperature()
//{
//  status=sensor.readTemperature();
//}

So, now you have an instance of a struct named sensor. The struct has a field called readHumidity. You are trying to use that value as though it was a function. Why?

You're using the Winchester Method of debugging: Aim a shotgun at the code, pull the trigger, and hope something good happens. Not likely. In your first iteration of the sensor structure, you declared two functions to read the humidity and temperature. When that didn't work and at the behest of Delta_G, you changed these from function calls to variables...another shotgun blast, but no change.

Now, stop and think. Why did you put those functions in a structure in the first place? Was their a reason? If not, you (still) need to write two functions that allow you to read those two sensors. Write the code for those two functions, make explicit calls to them in your code, and see what happens.

Personally, I don't like structs with functions. That's what classes are for. if you want a class, define a class. If you want a struct, to collect related data, use a struct.

Personally I see structs as classes with default public access, nothing less or more.