0

Temperature not declared in this scope
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Temperature not declared in this scope

by cbrucewarren on Sun May 09, 2021 9:18 pm

I'm trying to reactivate code I had used a year ago to connect to Adafruit I/O using the sample code for a BMP280 module as input. Now I'm getting odd errors. I think I've updated all the appropriate libraries but obviously something has changed in the past 12-18 months...any thoughts??

I've attached the compile error output.
Attachments
ArduinoError.txt
(3.5 KiB) Downloaded 4 times

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: Temperature not declared in this scope

by blnkjns on Mon May 10, 2021 12:23 am

Scope error means that the variable name misses a correct declaration in the scope where it's used, but this can be easily caused by not closing the brackets in a correct way, leaving for example a function open.
To help you, we do need the code though. Post it with code-tags.

blnkjns
 
Posts: 610
Joined: Fri Oct 02, 2020 3:33 am

Re: Temperature not declared in this scope

by cbrucewarren on Mon May 10, 2021 1:27 am

here is the main code:
Code: Select all | TOGGLE FULL SIZE
/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout
  ----> http://www.adafruit.com/products/2651

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries. 
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>


Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

//--------------------  ESP wifi setup  ---------------

#include <ESP8266WiFi.h>// this library is not visible unless the ESP board is selected.
#include <WiFiClientSecure.h>
#include <StreamString.h>
#include <base64.h>
#include <ESP8266HTTPClient.h>
#include "config.h"

//AdafruitIO_Feed *temperature = io.feed("temperature");
//AdafruitIO_Feed *pressure = io.feed("pressure");

void setup() {
  Serial.begin(9600);
  Serial.println(F("BMP280 test"));
 
  if (!bme.begin()) { 
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
  //***
  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while(io.status() < AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());
 
}
 
void loop() {
    // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
io.run();
    float Mytemperature = bme.readTemperature();
    float Mypressure = round(bme.readPressure());
 float newMypressure = Mypressure/1000;
 //Serial.print(newMypressure);
   
 
    Serial.print("Temperature = ");
    Serial.print(Mytemperature);
    Serial.println(" *C");
   
    Serial.print("Pressure = ");
    Serial.print(newMypressure);
    Serial.println(" kPa");

    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25)); // this should be adjusted to your local forcast
    Serial.println(" m");
    temperature->save(Mytemperature);
    pressure->save(newMypressure);
    Serial.println();
    delay(180000);// update every 3 minutes
}

and here is the config.h:
Code: Select all | TOGGLE FULL SIZE
/************************ Adafruit IO Config *******************************/

// visit io.adafruit.com if you need to create an account,
// or if you need your Adafruit IO key.
#define IO_USERNAME    "cbrucewarren"
#define IO_KEY         "871745c581406d3c773af43b637923b8003f3bd2"

/******************************* WIFI **************************************/

// the AdafruitIO_WiFi client will work with the following boards:
//   - HUZZAH ESP8266 Breakout -> https://www.adafruit.com/products/2471
//   - Feather HUZZAH ESP8266 -> https://www.adafruit.com/products/2821
//   - Feather M0 WiFi -> https://www.adafruit.com/products/3010
//   - Feather WICED -> https://www.adafruit.com/products/3056

#define WIFI_SSID       "bct2015"
#define WIFI_PASS       "chin00k11"

// comment out the following two lines if you are using fona or ethernet
#include "AdafruitIO_WiFi.h"
AdafruitIO_WiFi io(IO_USERNAME, IO_KEY, WIFI_SSID, WIFI_PASS);


/******************************* FONA **************************************/

// the AdafruitIO_FONA client will work with the following boards:
//   - Feather 32u4 FONA -> https://www.adafruit.com/product/3027

// uncomment the following two lines for 32u4 FONA,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_FONA.h"
// AdafruitIO_FONA io(IO_USERNAME, IO_KEY);


/**************************** ETHERNET ************************************/

// the AdafruitIO_Ethernet client will work with the following boards:
//   - Ethernet FeatherWing -> https://www.adafruit.com/products/3201

// uncomment the following two lines for ethernet,
// and comment out the AdafruitIO_WiFi client in the WIFI section
// #include "AdafruitIO_Ethernet.h"
// AdafruitIO_Ethernet io(IO_USERNAME, IO_KEY);



This is installed on Adafruit Feather Huzzah ESP8266

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: Temperature not declared in this scope

by blnkjns on Mon May 10, 2021 8:39 am

Problem is here:
Code: Select all | TOGGLE FULL SIZE
//AdafruitIO_Feed *temperature = io.feed("temperature");
//AdafruitIO_Feed *pressure = io.feed("pressure");


With a later call to it here:

Code: Select all | TOGGLE FULL SIZE
    temperature->save(Mytemperature);
    pressure->save(newMypressure);

You uncommented the declaration of the pointers for temperature and pressure, hence the not declared in this scope error.

blnkjns
 
Posts: 610
Joined: Fri Oct 02, 2020 3:33 am

Re: Temperature not declared in this scope

by cbrucewarren on Mon May 10, 2021 11:38 am

Thanks.. yes my mistake; I had commented out those and the save statement to prove that at least the BMP was being read and forgot to uncomment them.
I"ve done that and the attached is the error messages on compile... seems to be a lot of issues with the libraries?...
Attachments
ArduinoError.txt
(24.54 KiB) Downloaded 2 times

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: Temperature not declared in this scope

by cbrucewarren on Mon May 10, 2021 11:42 am

Which of these libraries should be used: AdafruitIO_arduino or AdafruitIO_arduino_master?

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: Temperature not declared in this scope

by cbrucewarren on Mon May 10, 2021 12:35 pm

I downloaded the lastest Arduino-master library zip from github; when I tried to install a .zip library i got this:
Specified folder/zip file does not contain a valid library
Invalid library found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master: no headers files (.h) found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master
Invalid library found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master: no headers files (.h) found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master

If I go to "manage library", i get a long list of the "Invalid library found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master: no headers files (.h) found in /Users/bruce/Arduino/My Sketches/libraries/Arduino-master" warnings. The library "arduino-master" does not show up in the manage library window so I can't try to update it from there.

I"m sure this is operator error, but not obvious to me...?

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Re: Temperature not declared in this scope

by brubell on Fri May 14, 2021 10:09 am

cbrucewarren wrote:Which of these libraries should be used: AdafruitIO_arduino or AdafruitIO_arduino_master?


Adafruit_IO_Arduino was likely installed from the Arduino IDE's library manager tool.

You may delete the AdafruitIO_arduino_master folder ( /Users/bruce/Arduino/My Sketches/libraries and named Arduino-master)

brubell
 
Posts: 1377
Joined: Fri Jul 17, 2015 10:33 pm

Re: Temperature not declared in this scope

by cbrucewarren on Fri May 14, 2021 11:12 am

did that and re-installed the board driver via board manager and now it works. thanks

cbrucewarren
 
Posts: 77
Joined: Sun Mar 09, 2014 1:57 pm

Please be positive and constructive with your questions and comments.


cron