"'HTTPClient' does not name a type; did you mean 'HttpClient'?"
I probably have an excess of #include libraries added to try an solve this error. In my research I have come across several comments about their being several 'HTTPClient.h' and 'HttpClient.h', which appears to be true. This is confusing to say the least. Whether this is the problem, I am not certain.
If I add: #include HttpClient.h (note lower case 'ttp', then the error becomes -
"'HTTPClient' does not name a type; did you mean 'HttpClient'?"
If anyone can shed some light on this I would be very grateful. Here is my test sketch:
Code: Select all
// test Rui sketch
// cannot overcome following error:
// 'HTTPClient' does not name a type; did you mean 'HttpClient'?
#include <b64.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <WiFi101.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
#include <SPI.h>
#include <WiFi.h>
#include <HTTPClient.h>
// My code moved from loop() ...
WiFiClient client;
HTTPClient http;
// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
const char* serverName = "http://redristracards.com/post-data.php";
String apiKeyValue = "tPmAT5Ab3j7F9";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("Connecting");
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to WiFi network with IP Address: ");
Serial.println(WiFi.localIP());
// (you can also pass in a Wire library object like &Wire2)
bool status = bme.begin(0x76);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring or change I2C address!");
while (1);
}
}
void loop() {
//Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){
// Your Domain name with URL path or IP address with path
http.begin(client, serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue + "&value1=" + String(bme.readTemperature())
+ "&value2=" + String(bme.readHumidity()) + "&value3=" + String(bme.readPressure()/100.0F) + "";
Serial.print("httpRequestData: ");
Serial.println(httpRequestData);
if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
// Free resources
http.end();
}
else {
Serial.println("WiFi Disconnected");
}
//Send an HTTP POST request every 30 seconds
delay(30000);
}