In the example program, "BasicHttpClient", line 77 has the instruction "http.begin("http://example.com/index.html");" and line 81 has "int httpCode = http.GET();".
What is the relationship between these two lines of code? Does the "http.begin" load up the send data while the "http.GET();" sends the data on the network?
Do I need one "http.GET();" line for every "http.begin"?
Jurai - Thank you for your help. It's greatly appreciated.
One problem I am having is that I see more information in the header code than I can find in the product manual. I have a program working, I am not sure why. I am trying to control outlets on a network enabled power switch. The program attached toggles the state of outlet #5 every 5 seconds. I modified the BasicHttpClient example. How far off the mark am I?
/**
* BasicHTTPClient.ino
*
* Created on: 24.05.2015
*
*/
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiMulti.h>
#include <HTTPClient.h>
#define USE_SERIAL Serial
WiFiMulti wifiMulti;
bool flip = true;
void setup() {
USE_SERIAL.begin(115200);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println();
for(uint8_t t = 4; t > 0; t--) {
USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
USE_SERIAL.flush();
delay(1000);
}
wifiMulti.addAP("*****", "*****");
}
void loop() {
// wait for WiFi connection
if((wifiMulti.run() == WL_CONNECTED)) {
HTTPClient http;
if (flip == false) {
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
http.begin("http://192.168.39.93/index.htm"); //HTTP
http.begin("http://admin:1234@192.168.39.93/outlet?5=OFF");
flip = true;
}
else {
USE_SERIAL.print("[HTTP] begin...\n");
// configure traged server and url
//http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
http.begin("http://192.168.39.93/index.htm"); //HTTP
http.begin("http://admin:1234@192.168.39.93/outlet?5=ON");
flip = false;
}
USE_SERIAL.print("[HTTP] GET...\n");
// start connection and send HTTP header
int httpCode = http.GET();
// httpCode will be negative on error
if(httpCode > 0) {
// HTTP header has been send and Server response header has been handled
USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if(httpCode == HTTP_CODE_OK) {
String payload = http.getString();
USE_SERIAL.println(payload);
}
} else {
USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
}
http.end();
}
delay(5000);
}