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");
}
}