1
Good, I have this code that in the future will read the temperature and humidity through sensors. But now I was testing to see if I could upload the data to the database, something that’s going wrong. I can connect to wifi (smartphone hotspot) but I can’t connect to the server. What should I do?
Code:
#include < ESP8266WiFi.h >
const char* ssid = "ESP-8266";
const char* password = "esp8266imsi";
const char* server = "192.168.8.100";
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(10);
WiFi.begin(ssid, password);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
}
void loop() {
Serial.print("Temperature: 25\n");
if (client.connect(server,80)) {
String url = "/post-esp-data.php?humsolo=";
url += ("25");
url += ("&temp=");
url += ("30");
Serial.print("Requesting URL: ");
Serial.println(url);
client.print(String("GET ") + url + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n\r\n");
}
else{
Serial.println("Erro ao enviar!\n");
}
client.stop();
Serial.println("Waiting...\n");
// delay between updates
delay(30000); //30s minute delay
}