Error: expected primary-expression before '.' token

Hi!

I'm working on a set up that has a couple of LDRs and a DHT11 sensor as part of a project on gauging the most beneficial place to position a plant (using Lux and Temperature). It's done using a featherboard and sending data to ThingSpeak and works absolutely fine with the LDR side of things, but the coding for the DHT11 is making me pull my hair out. I'm always getting the following error:

Users/alexandraross/Downloads/ThingspeakConnection__test2_/ThingspeakConnection__test2_.ino: In function 'void loop()':
ThingspeakConnection__test2_:130: error: expected primary-expression before '.' token
   temperature = dht.readTemperature();  
                    ^
ThingspeakConnection__test2_:132: error: expected primary-expression before '.' token
   humidity = dht.readHumidity();  
                 ^
exit status 1
expected primary-expression before '.' token

In regards to this little section of code

static boolean data_state = false;  
  float temperature;
  temperature = dht.readTemperature();  
  float humidity;
  humidity = dht.readHumidity();  
  Serial.print("Temperature Value is :");  
  Serial.print(temperature);  
  Serial.println("C");  
  Serial.print("Humidity Value is :");  
  Serial.print(humidity);  
  Serial.println("%");  
  // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different  
  // pieces of information in a channel. Here, we write to field 1.  
  if( data_state )  
  {  
   ThingSpeak.writeField(myChannelNumber, 5, temperature, myWriteAPIKey);  
   data_state = false;  
  }  
  else  
  {  
   ThingSpeak.writeField(myChannelNumber, 6, humidity, myWriteAPIKey);  
   data_state = true;  
  }  
  delay(15000); // ThingSpeak will only accept updates every 15 seconds.

I can't work out what it's wanting me to put in there.

Any possible explanation would be much appreciated!

I can't work out what it's wanting me to put in there.

It is complaining that the . in front of the functions is not in the right place, because, most likely, you have not created an instance of a class that you called dht.

Posting ALL of your code IS important.

The code is awfully long, but here goes:

#include "ThingSpeak.h"
#include <SPI.h>
#include <WiFi101.h>

char ssid[] = "TripMate-4530";     //  your network SSID (name) 
char pass[] = "********";   // your network password
WiFiClient  client; 

#include <dht.h>
 
#define dht_apin A2 // Analog Pin sensor is connected to
 
dht DHT;





unsigned long myChannelNumber = 341384; //Put your channel number in here
const char * myWriteAPIKey = "*****************"; //Put your API key in here

uint8_t temperature, humidity;  

void setup() {
  Serial.begin(57600);   // Make sure that the number in the bottom right of the Serial Monitor matches this
 
  WiFi.setPins(8,7,4,2); // Setup the WiFi on the Feather boards

  /* Start the WiFi connection */
  Serial.println("Starting..."); 
  Serial.println("Connecting to WiFi");  
  int conn = WiFi.begin(ssid, pass);
  if( conn == WL_CONNECTED )        { Serial.println("OK!");}
  else if( conn == WL_IDLE_STATUS ) {Serial.println("Idle");}
  else                              {Serial.println("Unknown response");}

  /* Now connect to ThingSpeak */
  ThingSpeak.begin(client);
  Serial.println("Started");
}

void loop() {
  
  /* First of all, get the data and calculate the voltage */
  // read the input on analog pin 0:
  int sensorValue0 = analogRead(A0);

  //The voltage can be between 0 and 3.3v, and gives readings from 0 to 1023
  float Vout0 = sensorValue0 * (3.3 / 1024.0); 

  float RLDR0 = (1.0 * (3.3 - Vout0))/Vout0;

  float Lux0 = (500.0/RLDR0);

  

  //Check that a channel number has been set
  if( myChannelNumber < 0 ) { Serial.println("Warning! No channel number set!"); }

  /* 
   * Finally, try to write to ThingSpeak
   * There are up to 8 fields in a channel, allowing you to store up to 8 different
   * pieces of information.  Here, we write to field 1. 
   */
  Serial.print("Writing Lux0" );
  Serial.print(Lux0);
  Serial.print(" to field 4 of channel " );
  Serial.println(myChannelNumber);
  int resp0 = ThingSpeak.writeField(myChannelNumber, 4, Lux0, myWriteAPIKey);
  Serial.print("Response: ");
  Serial.println(resp0);
  delay(15000); // ThingSpeak will only accept updates every 15 seconds.


   /* First of all, get the data and calculate the voltage */
  // read the input on analog pin 1:
  int sensorValue1 = analogRead(A1);

  //The voltage can be between 0 and 3.3v, and gives readings from 0 to 1023
  float Vout1 = sensorValue1 * (3.3 / 1024.0); 

  float RLDR1 = (1.0 * (3.3 - Vout1))/Vout1;

  float Lux1 = (500.0/RLDR1);

  

  //Check that a channel number has been set
  if( myChannelNumber < 0 ) { Serial.println("Warning! No channel number set!"); }

  /* 
   * Finally, try to write to ThingSpeak
   * There are up to 8 fields in a channel, allowing you to store up to 8 different
   * pieces of information.  Here, we write to field 1. 
   */
  Serial.print("Writing Lux1" );
  Serial.print(Lux1);
  Serial.print(" to field 5 of channel " );
  Serial.println(myChannelNumber);
  int resp1 = ThingSpeak.writeField(myChannelNumber, 5, Lux1, myWriteAPIKey);
  Serial.print("Response: ");
  Serial.println(resp1);
  delay(15000); // ThingSpeak will only accept updates every 15 seconds.


 //Read temperature and humidity values from DHT sensor:

  static boolean data_state = false;  
  float temperature;
  temperature = dht.readTemperature();  
  float humidity;
  humidity = dht.readHumidity();  
  Serial.print("Temperature Value is :");  
  Serial.print(temperature);  
  Serial.println("C");  
  Serial.print("Humidity Value is :");  
  Serial.print(humidity);  
  Serial.println("%");  
  // Write to ThingSpeak. There are up to 8 fields in a channel, allowing you to store up to 8 different  
  // pieces of information in a channel. Here, we write to field 1.  
  if( data_state )  
  {  
   ThingSpeak.writeField(myChannelNumber, 5, temperature, myWriteAPIKey);  
   data_state = false;  
  }  
  else  
  {  
   ThingSpeak.writeField(myChannelNumber, 6, humidity, myWriteAPIKey);  
   data_state = true;  
  }  
  delay(15000); // ThingSpeak will only accept updates every 15 seconds. 

}

dht DHT;Did you meanDHT dht;?

#include <dht.h>

This defines a class, with some name. If the developer followed conventions, the class is called dht.

dht DHT;

This creates an instance of the class in a REALLY stupid way. Calling the instance the same name as the class, but in a different case, is like getting a dog, and calling it DOG. Really, can't anyone use some imagination?

  float temperature;
  temperature = dht.readTemperature();

This calls the readTemperature() method of the non-existent DHT instance. That is NOT possible. So, the compiler told you that.

PaulS:

dht DHT;

This creates an instance of the class in a REALLY stupid way. Calling the instance the same name as the class, but in a different case, is like getting a dog, and calling it DOG. Really, can't anyone use some imagination?

I disagree thoroughly with this, it seems very straightforward - case convention distinquishes class from
instance variable, names are descriptive. Good code style is about clarity and consistency.

I disagree thoroughly with this

So, you have a dog named DOG?

MarkT:
I disagree thoroughly with this, it seems very straightforward - case convention distinquishes class from
instance variable, names are descriptive. Good code style is about clarity and consistency.

That's reasonable, but only if you can remember which case you are using for which...and it seems that the OP can't.

Steve