Good Afternoon,
I hope that someone can please help.
My Code below should send data to MySQL. But for some reason... it just doesnt.
So if i copy and paste the url created (postStr) manually into the web browser, it submits the data to the DB perfectly, but it does not do it when running normally.
In my monitor, it shows connected and the link displays correctly as well...
Please assist? Where am I missing it?
#include <ESP8266WiFi.h>
#include <SimpleDHT.h>
const char* ssid = "MySSID";
const char* password = "MyPass";
const int httpPort = 80;
const char* server = "154.xxx.xxx.xxx";
const char* host = "154.xxx.xxx.xxx";
int i = 0;
int pinDHT11 = 2;
SimpleDHT11 dht11;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid,password);
while (WiFi.status() != WL_CONNECTED)
{
delay (500);
Serial.print(".");
}
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
WiFiClient client;
if (!client.connect(server,httpPort))
{
Serial.println("Connection Failed");
return;
}
else
{
Serial.println("Connection Success");
}
byte temperature = 0;
byte humidity = 0;
if (dht11.read(pinDHT11, &temperature, &humidity, NULL)) {
Serial.print("Read DHT11 failed.");
return;
}
if (client.connect(server,80)) {
String postStr = "154.xxx.xxx.xxx/Node_set.php?";
postStr +="&Temp=";
postStr += String(temperature);
postStr +="&Hum=";
postStr += String(humidity);
client.print(String("GET ") + postStr + " HTTP/1.1\r\n" +
"Host: " + host + "r\n" +
"Connection: close\r\n\r\n");
Serial.print(postStr);
Serial.print("\n\r");
Serial.print("\n\r");
Serial.print("Temperature: ");
Serial.print((int)temperature);
Serial.print(" C\n\r");
Serial.print("Humidity: ");
Serial.print((int)humidity);
Serial.print(" %\n\r");
} // CLOSE IF CONNECT
client.stop();
Serial.println("Waiting…");
delay (60000);
i++;
}
Thank you very much!
Kind Regards