I get an error which has me baffled.
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
const char* ssid = "Cabin-Sensor-Access-Point";
const char* password = "123456789";
//Your IP address or domain name with URL path
const char* serverNameTemp = "http://192.168.4.1/door";
String door;
unsigned long previousMillis = 0;
const long interval = 5000;
#define RedLED D3 // GPIO pin assignments. LEDs have a series R and turn
#define GreenLED D4 // on when pin is high
#define DoorSwitches D0 // There is an external pullup on this
int D0_doorval = 0;
//********************************************************************************************************
//********************************************************************************************************
void setup( ) {
Serial.begin(9600);
Serial.println();
ConfigGPIO( );
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("Connected to WiFi");
}
//********************************************************************************************************
//********************************************************************************************************
void loop( ) {
if (WiFi.status( ) != WL_CONNECTED) {
WiFi.begin(ssid, password);
}
while (WiFi.status( ) != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
// Check WiFi connection status
if ((WiFiMulti.run() == WL_CONNECTED)) {
door = httpGETRequest(serverNameTemp);
//Serial.println("Door: " + door);
// save the last HTTP GET Request
previousMillis = currentMillis;
} else {
Serial.println("WiFi Disconnected");
}
}
delay( 5000 );
}
//********************************************************************************************************
//********************************************************************************************************
String httpGETRequest( const char* ssid ) {
WiFiClient client;
HTTPClient http;
// Your IP address with path or Domain name with URL path
http.begin(client, ssid);
// Send HTTP POST request
int httpResponseCode = http.GET();
String payload = "--";
if ( httpResponseCode > 0 ) {
//Serial.print("HTTP Response code: ");
//Serial.println(httpResponseCode);
payload = http.getString();
ledStatusIndicators( payload.toInt( ) );
// Free resources
http.end();
return payload;
}
}
//********************************************************************************************************
//********************************************************************************************************
void ledStatusIndicators( int D0_doorval ) {
// Read payload from server which read the two door switches which are connected in
// series, one on each 1/2 door, and closed when door closed.
if ( D0_doorval == 1 ) { // One or both half door switches open due to pullup
digitalWrite( RedLED, 1 ) ; // Red LED on
digitalWrite( GreenLED, 0 ) ; // Green LED off
Serial.println( "Door Open" );
} else {
digitalWrite( RedLED, 0 ) ;
digitalWrite( GreenLED, 1 ) ;
Serial.println( "Door Closed" );
}
}
//********************************************************************************************************
//********************************************************************************************************
void ConfigGPIO( void ) {
pinMode( DoorSwitches, INPUT ); // DoorSwitches input pin
pinMode( RedLED, OUTPUT ); // Red and Green LEDs output pins
pinMode( GreenLED, OUTPUT );
digitalWrite( RedLED, 0 ); // Turn off LEDs
digitalWrite( GreenLED, 0 );
}
Error is (i tried posting as code, post huge amount of crap) -
C:\Users\danaa\Desktop\ESP8266CabinBasementDoor\ClientCabinDoorSense\ClientCabinDoorSense.ino: In function 'String httpGETRequest(const char*)':
C:\Users\danaa\Desktop\ESP8266CabinBasementDoor\ClientCabinDoorSense\ClientCabinDoorSense.ino:77:16: error: control reaches end of non-void function [-Werror=return-type]
77 | WiFiClient client;
| ^~~~~~
cc1plus.exe: some warnings being treated as errors
Using library ESP8266WiFi at version 1.0 in folder: C:\Users\danaa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266WiFi
Using library ESP8266HTTPClient at version 1.2 in folder: C:\Users\danaa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.1.2\libraries\ESP8266HTTPClient
exit status 1
Compilation error: control reaches end of non-void function [-Werror=return-type]
Any and all help greatly appreciated.
Regards, Dana.