arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
282 stars 170 forks source link

Adafruit ESP8266 #48

Closed BluesQuinn closed 5 years ago

BluesQuinn commented 5 years ago

Hi there, I'm doing a project which tried to connect sensor BME280 and Adafruit ESP8266. I used this library but it showed a bug that

Arduino: 1.8.5 (Windows 10), Board: "Adafruit Feather HUZZAH ESP8266, 80 MHz, Flash, Enabled, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 9600"

In file included from C:\Users\qiuch\Documents\Arduino\libraries\ArduinoHttpClient\src/ArduinoHttpClient.h:8:0,

                 from C:\Users\qiuch\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/AdafruitIO.h:23,

                 from C:\Users\qiuch\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/wifi/AdafruitIO_ESP8266.h:18,

                 from C:\Users\qiuch\Documents\Arduino\libraries\Adafruit_IO_Arduino\src/AdafruitIO_WiFi.h:32,

                 from sketch\config.h:21,

                 from C:\Users\qiuch\Desktop\Code Test\esp8266\esp8266\esp8266.ino\esp8266.ino.ino\esp8266.ino\esp8266.ino.ino:20:

C:\Users\qiuch\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h: In member function 'virtual void HttpClient::flush()':

C:\Users\qiuch\Documents\Arduino\libraries\ArduinoHttpClient\src/HttpClient.h:310:50: error: return-statement with a value, in function returning 'void' [-fpermissive]

     virtual void flush() { return iClient->flush(); };

                                                  ^

exit status 1
Error compiling for board Adafruit Feather HUZZAH ESP8266.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I don't know why. I will be appreciate with any help. Thank you very much.

The following content is the code:

#include "config.h"

/************************* Sensor Configuration *********************/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// BME280 Sensor Definitions
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)

// Instanciate the sensors
Adafruit_BME280 bme;

/**************************** Example ********************************/
// Delay between sensor reads, in seconds
#define READ_DELAY 10

// BME280 Data
int temperatureReading = 0;
int altitudeReading = 0;
int humidityReading = 0;
int pressureReading = 0;

// set up the feeds for the BME280
AdafruitIO_Feed *temperatureFeed = io.feed("temperature");
AdafruitIO_Feed *humidityFeed = io.feed("humidity");
AdafruitIO_Feed *pressureFeed = io.feed("pressure");
AdafruitIO_Feed *altitudeFeed = io.feed("altitude");

void setup() {
  // start the serial connection
  Serial.begin(9600);

  // wait for serial monitor to open
  while (!Serial);

  Serial.println("Environmental Logger");

  // set up BME280
  setupBME280();

  // 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();

  Serial.println("Reading Sensors...");

  // Read the temperature from the BME280
  temperatureReading = bme.readTemperature();

  // convert from celsius to degrees fahrenheit
  temperatureReading = temperatureReading * 1.8 + 32;

  Serial.print("Temperature = "); Serial.print(temperatureReading); Serial.println(" *F");

  // Read the pressure from the BME280
  pressureReading = bme.readPressure() / 100.0F;
  Serial.print("Pressure = "); Serial.print(pressureReading); Serial.println(" hPa");

  // Read the altitude from the BME280
  altitudeReading = bme.readAltitude(SEALEVELPRESSURE_HPA);
  Serial.print("Approx. Altitude = "); Serial.print(altitudeReading); Serial.println(" m");

  // Read the humidity from the BME280
  humidityReading = bme.readHumidity();
  Serial.print("Humidity = "); Serial.print(humidityReading); Serial.println("%");

  // send data to Adafruit IO feeds
  temperatureFeed->save(temperatureReading);
  humidityFeed->save(humidityReading);
  altitudeFeed->save(altitudeReading);
  pressureFeed->save(pressureReading);

  // delay the polled loop
  delay(READ_DELAY * 1000);
}

// Set up the BME280 sensor
void setupBME280() {
  bool status;
  status = bme.begin();
  if (!status)
  {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }
  Serial.println("BME Sensor is set up!");
}
abachman commented 5 years ago

It looks like the actual issue is in the ESP8266 board support package which changed the return value of the flush method to be bool rather than void.

It's not clear whether the ESP8266 Arduino should change or whether this library should handle the new function definition.

sandeepmistry commented 5 years ago

Fixed via https://github.com/arduino-libraries/ArduinoHttpClient/pull/49.