\. This program was written to test the PHP webpage function
in lieu of the input from the ESP board #1 (sensor board) .\

#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>

WiFiMulti wifiMulti;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  for(uint8_t t = 4; t > 0; t--){
    Serial.printf("[SETUP] WAIT %d...\n", t);
    Serial.flush();
    delay(1000);
  }
  wifiMulti.addAP("OSU_Access", "");
}

String command = "on"; // change this command to "on" or "off" depending on desired output to PHP

void loop() {
  // put your main code here, to run repeatedly:

  if((wifiMulti.run() == WL_CONNECTED)) { //wait for WiFi connection
    HTTPClient http; //Creates an HTTPClient object to be used
    //Begins request we will eventually POST
    http.begin("https://web.engr.oregonstate.edu/~bergkev/ENGR103/sensorupload.php");
    //Setup this request to look like an HTML form
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");
    
    //Data to send with HTTP post
    String myString;
    myString = "command=";
    myString = myString + command; //outputs string "command=on" or "command=off" depending on what string "command" is set to on line 22
    Serial.print ("Command Sent: "); //prints output command
    Serial.println (myString);
    
    // Send HTTP POST request
    int httpCode = http.POST(myString);
    if (httpCode > 0) { //Did we get a valid response?
      String payload = http.getString();
      Serial.println(payload);
    }
    else {
      Serial.printf ("[HTTP] GET... code: %d\n", httpCode); //prints error if unsuccessful
    }
  http.end(); //End this request
  } 
  delay(5000);
}
