ESP8266 with BME280 - hung up on (client.connect)

I’m getting a few errors I dont understand and could use a little help. If I comment out “if (client.connect(server, 80));” to the bottom, it will compile fine. Thanks in advance.

//prototype humidor#1 rev 9 increased to 72%h and reduced bias resistor from 10k to 1k because i also installed a circ fan on the humidify circuit
//Tutorial:   http://esp8266.github.io/Arduino/versions/2.0.0/doc/ota_updates/ota_updates.html#web-browser
//Now with a working web OTA on Proto #1 & unit #2!
//For Windows, install Bonjour.
//7/12/2017 changed if statement to else if statement because programing was halting on it.
//DONT forget to update API key ex:"17GUL8UPXWYEMNAC", SSID and PW, and MAC addresses to selectivley program
//try to fix problem of freezing up if no network connection
//opoen: http://esp8266-webupdate.local/update in your browser
//add BME280 capability

//----------------------------------------------------------BME280

#include <BME280I2C.h>
BME280I2C bme;
bool metric = false;    //to change to Canadian, make true.
void printBME280Data(Stream * client);
#include <PID_v1.h>

//----------------------------------------------------------OLED

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 16   //pin 16
Adafruit_SSD1306 display(OLED_RESET);

//----------------------------------------------------------WIFI
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
WiFiClient client;

const char* host = "esp8266-webupdate";
const char* ssid     = "cleo****";
const char* password = "Bullsh****";
//String apiKey = "17GUL8UPXWYEMNA@C";     //Cigar Hydration System #1   Channel ID: 172771 HUMIDOR
//String apiKey =   "2PF1HY5EG1NNBR@PK";   //Cigar Hydration System #2   Channel ID: 216567
String apiKey = "U2JBD30O159B0YB@N";       //Cigar Hydration System #4   Channel ID: 275546 BILLS' HUMIDOR
const char* server = "api.thingspeak.com";
const int fanOutput = 14;


//---------------------------------------------------------------INTRUDER

int analogPin = 0;
int light = 0;
int hSP = 70;    //Set the Humidity SP here only
int lSP = 300 ;   //Set the light SP here only

//--------------------------------------------------------------------------------SETUP
void setup()
{
  Serial.begin(115200);
  bme.begin() ;
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(fanOutput, OUTPUT);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // displays' I2C address
  //  dht.begin();
  Serial.begin(115200);
  delay(500);
  Serial.println("Booting Sketch...");
  WiFi.mode(WIFI_AP_STA);
  WiFi.begin(ssid, password);
  Serial.println(ssid);
  Serial.println(password);
  delay(500);
  while (WiFi.waitForConnectResult() != WL_CONNECTED)
    Serial.print(".");
  delay(500);

  {
    WiFi.begin(ssid, password);
    Serial.println("WiFi failed, retrying.");
  }

  MDNS.begin(host);
  httpUpdater.setup(&httpServer);
  httpServer.begin();
  MDNS.addService("http", "tcp", 80);
  Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser\n", host);
  Serial.println("");
  Serial.println("WiFi connected");
  MDNS.begin(host);
  delay(500);
}

//----------------------------------------------------------------------------LOOP
void loop(void) {

  printBME280Data(&Serial);
  delay(500);
}
void printBME280Data(Stream * client) {
  httpServer.handleClient();

  float temp(NAN), hum(NAN), pres(NAN);
  uint8_t pressureUnit(3);
  bme.read(pres, temp, hum, metric);
  Serial.print(hum);
  Serial.print(" %RH ");
  Serial.print("---------- ");
  Serial.print(temp);
  Serial.print(" °F");
  Serial.println();
  //-------------------------------------------------------------------DISPLAY_LOGIC
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 0);
  //--------------------------- Temp
  display.println("Humidity:");
  display.setCursor(70, 0);
  display.println(hum);
  //--------------------------- Temp
  display.setCursor(0, 8);
  display.println("Temp:");
  display.setCursor(70, 8);
  display.println(temp);
  display.display();

  if (client.connect(server, 80)); { // "184.106.153.149" or api.thingspeak.com
    String postStr = apiKey;
    postStr += "&field1=";
    postStr += String(hum);
    postStr += "&field2=";
    postStr += String(temp);
    postStr += "\r\n\r\n";
    postStr += "&field3=";
    postStr += String(light);
    //ADD HERE TO GET POSTED

    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
    client.print("Content-Type: application/x-www-form-urlencoded\n");
    client.print("Content-Length: ");
    client.print(postStr.length());
    client.print("\n\n");
    client.print(postStr);
    Serial.print("Temperature: ");
    Serial.print(temp);
    Serial.print(" degrees Celcius Humidity: ");
    Serial.print(hum);
    Serial.println("% send to Thingspeak");
    client.stop();
    Serial.println("Waiting");
  }
}

When you encounter an error you’ll see a button on the right side of the orange bar “Copy error messages”. Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

Several issues are apparent without seeing an actual error printout which would help. Not sure this is all of them.

  1. You declare the stream “client” for use as the web client. Then you try to pass the Serial stream pointer to the printBME280Data subroutine which also receives it as “client”. I doubt you are actually using the client stream you intended. Try removing the parameter in both the call and the subroutine as you do not appear to be actually using it and are instead just printing directly to Serial and the Web client streams.
void loop(void) {

  printBME280Data(); //<--- Remove Parameter being Sent
  delay(500);
}
void printBME280Data() {//<--- Remove Parameter being Received
  1. It looks like you may have and extra ; in this line following 80)) and you might want to remove it if you want that if statement to actually do something.
  if (client.connect(server, 80)); { // "184.106.153.149" or api.thingspeak.com

wzaggle, that worked! Thank you taking the time to look at my code. I never would have found that. I'm not really sure where to learn more about what I just changed. That bit of code was copied from another program. Any suggestions would be appreciated as well.

Onward and upward!

Jeff

The subroutine you copied out of the example was written to accept a specified output stream. This means it could work with any output stream like a web client or a serial port. That local stream inside the subroutine was called "client", but the Global stream you declared for your web connection was also called "client". The local version of client took precedence over the global version and you were trying to use the wrong stream which caused some of your errors. To start you could research local vs global variables and learn more about what was happening.