Hello guys! I’m sorry for my English.
my esp8266 does not connect to the database. I did everything like this in the tutorial. We receive the following message:
Connected to the WiFi network with IP address: 192.168.0.101
Timer set to 30 seconds (variable delay timer), it will take 30 seconds before publishing the first reading.
httpRequestData: api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 23.10 & value2 = 31.99 & value3 = 1013.30
Error code: -1
This active example with no results:
your domain name with URL path or IP address with path
http .begin (server name); // Specify the content type header http.addHeader (“Content-Type”, “ // Prepare your HTTP POST request data // String httpRequestData = “api_key =” + apiKeyValue + “& sensor =” + sensorName // + “& location =” + sensorLocation + “& value1 =” + String (bme.readTemperature ()) // + “& value2 =” + String (bme.readHumidity ()) + “& value3 =” + String (bme.readPressure () / 100.0F) + “”; Serial.print ("httpRequestData:"); Serial.println (httpRequestData); // You can comment the httpRequestData variable above // then use the httpRequestData variable below (for testing purposes without the BME280 sensor) String httpRequestData = "api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 24. int httpResponseCode = http.POST (httpRequestData);
my configuration is:
const char * serverName = “estacionelsano.000webhostapp.com/esp-weather-station.php“; // Keep this API key value to be compatible with the PHP code provided on the project page. // If you change the value of apiKeyValue, the PHP file /esp-post-data.php must also have the same key String apiKeyValue = “tPmAT5Ab3j7F9”; String sensorName = "BME280"; String sensorLocation = "Office";
Any suggestion?
Thanks a lot
¡Hola chicos! Lo siento por mi ingles.
mi esp8266 no se conecta a la base de datos. Hice todo así en el tutorial. Recibimos el siguiente mensaje:
Conectado a la red WiFi con dirección IP: 192.168.0.101
Temporizador configurado en 30 segundos (temporizador variable de retardo), tomará 30 segundos antes de publicar la primera lectura.
httpRequestData: api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 23.10 & value2 = 31.99 & value3 = 1013.30
Código de error: -1
Este ejemplo activo sin resultados:
su nombre de dominio con ruta URL o dirección IP con ruta
http .begin (nombre del servidor);
// Especifique el encabezado de tipo de contenido
http.addHeader (“Content-Type”, “
// Preparar sus datos de solicitud HTTP POST
// String httpRequestData = “api_key =” + apiKeyValue + “& sensor =” + sensorName
// + “& location =” + sensorLocation + “& value1 =” + String (bme.readTemperature ())
// + “& value2 =” + String (bme.readHumidity ()) + “& value3 =” + String (bme.readPressure () / 100.0F) + “”;
Serial.print (“httpRequestData:”);
Serial.println (httpRequestData);
// Puede comentar la variable httpRequestData arriba
// luego, use la variable httpRequestData a continuación (para fines de prueba sin el sensor BME280)
Cadena httpRequestData = “api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 24.
int httpResponseCode = http.POST (httpRequestData);
mi configuración es:
const char * serverName = “estacionelsano.000webhostapp.com/esp-weather-station.php”;
// Mantenga este valor de clave API para que sea compatible con el código PHP proporcionado en la página del proyecto.
// Si cambia el valor de apiKeyValue, el archivo PHP /esp-post-data.php también debe tener la misma clave
String apiKeyValue = “tPmAT5Ab3j7F9”;
String sensorName = “BME280”;
String sensorLocation = “Oficina”;
¿Cualquier sugerencia?
muchas gracias
Hello Raul,
Are you using an ESP32 or ESP8266 board?
I’ve used Google auto-translate to convert your answer to English, because I don’t speak Spanish! Thanks for understanding.
Regards,
Rui
Hi Rui! Thank you very much for answering. I use an esp8266 nodemecu amica. The host you use is 000webhost in the free version. Does that have something to do with it? here is my website
https://estacionelsano.000webhostapp.com/esp-weather-station.php
I think my problem is that the data is not entering the table.
If you enter the link this: https://estacionelsano.000webhostapp.com/esp-post-data.php
You can see that the database is fine.
(Later I will use esp32, but I have to study the book I bought you)
Do you need any more information? If you want, I give you access to my website. Thanks a lot
Hello again, can you please auto-translate your questions before posting them? Unfortunately I don’t speak Spanish and I have to manually auto-translate them. Thanks for understanding.
Can you try with an ESP32? Just upload the same code and see if it works for you. Sometimes that error happens with the ESP8266, but it works with the ESP32.
I would like just to ensure that it’s something wrong with the code and not with the web host setup.
Thanks!
Hi Rui Thank you very much for replying. Sorry, I already translate it into English. I use an esp8266 nodemecu amica. The host you use is 000webhost in the free version. Does that have something to do with it? here is my website
https://estacionelsano.000webhostapp.com/esp-weather-station.php
I think my problem is that the data doesn’t fit in the table.
If you enter the link this: https://estacionelsano.000webhostapp.com/esp-post-data.php
You can see that the database is fine.
(Later I will use esp32, but I have to study the book I bought you) I don’t have esp32 yet 🙁
Do you need more info? If you wish, I give you access to my website. Thank you
No problem! Thanks for translating it, I appreciate your time.
Some free hosting providers don’t allow connections from unknown devices (that’s why I recommend Bluehost). It will only accept connections from web browsers (and blocks connections from other devices).
However, many of our readers used the free web host called 000webhost.com and it worked for them.
I think it might be an error with your ESP8266 code, are you entering HTTP in the URL path in your ESP8266 or HTTPS? Can you try with just HTTP?
As I said in my previous comment, I think you don’t need Bluehost. The hosting 000webhost should also work just fine and it’s working, I think it’s just something going wrong with the ESP8266 code.
Thanks!
With “http” I got this: connected to the WiFi network with IP address: 192.168.0.108
Timer set to 30 seconds (variable delay timer), it will take 30 seconds before publishing the first reading.
httpRequestData: api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 22.97 & value2 = 63.32 & value3 = 992.71
HTTP response code: 200
In the database I receive nothing. I leave you the complete code, could you review it please? From already thank you very much !!!!
#ifdef ESP32 # include <WiFi.h> #include <HTTPClient.h> #else # include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> #endif # include <Wire.h> # incluir <Adafruit_Sensor.h> #include <Adafruit_BME280.h> const char * ssid = "TP-LINK2"; const char * contraseña = "wifiseguro"; // Su nombre de dominio con ruta URL o dirección IP con ruta const char * serverName = "http://estacionelsano.000webhostapp.com/esp-weather-station.php"; // Mantenga este valor de clave API para que sea compatible con el código PHP proporcionado en la página del proyecto. // Si cambia el valor de apiKeyValue, el archivo PHP / esp-post-data. String apiKeyValue = "mi api"; String sensorName = "BME280"; String sensorLocation = "Oficina"; / * # include <SPI.h> #define BME_SCK 18 #define BME_MISO 19 #define BME_MOSI 23 #define BME_CS 5 * / #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme; // I2C // Adafruit_BME280 bme (BME_CS); // hardware SPI // Adafruit_BME280 bme (BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI // las siguientes variables son longitudes sin signo porque el tiempo, medido en // milisegundos, se convertirá rápidamente en un número mayor que el que se puede almacenar en un int. unsigned long lastTime = 0; // Temporizador establecido en 10 minutos (600000) // temporizador largo sin signo Delay = 600000; // Establece el temporizador en 30 segundos (30000) unsigned long timerDelay = 30000; configuración nula () { Serial.begin (115200); WiFi.begin (ssid, contraseña); Serial.println ("Conexión"); while (WiFi.status ()! = WL_CONNECTED) { delay (500); Serial.print ("."); } Serial.println (""); Serial.print ("Conectado a la red WiFi con dirección IP:"); Serial.println (WiFi.localIP ()); // (también puede pasar un objeto de biblioteca Wire como & Wire2) bool status = bme.begin (0x76); if (! status) { Serial.println ("¡No se pudo encontrar un sensor BME280 válido, verifique el cableado o cambie la dirección I2C!"); mientras que (1); } Serial.println ("Temporizador configurado a 30 segundos (variable timerDelay), tomará 30 segundos antes de publicar la primera lectura"); } void loop () { // Envía una solicitud HTTP POST cada 10 minutos if ((millis () - lastTime)> timerDelay) { // Comprueba el estado de la conexión WiFi if (WiFi.status () == WL_CONNECTED) { HTTPClient http; // Su nombre de dominio con ruta URL o dirección IP con ruta http.begin (serverName); // Especifique el encabezado de tipo de contenido http.addHeader ("Content-Type", "application / x-www-form-urlencoded"); // Prepare sus datos de solicitud HTTP POST Cadena httpRequestData = "api_key =" + apiKeyValue + "& sensor =" + sensorName + "& location =" + sensorLocation + "& value1 =" + String (bme.readTemperature ()) + "& value2 =" + String (bme.readHumidity ()) + "& value3 =" + String (bme.readPressure () / 100.0 F) + ""; Serial.print ("httpRequestData:"); Serial.println (httpRequestData); // Puede comentar la variable httpRequestData arriba // luego, use la variable httpRequestData a continuación (para fines de prueba sin el sensor BME280) // String httpRequestData = "api_key = tPmAT5Ab3j7F9 & sensor = BME280 & location = Office & value1 = 24.75 & value2 = 49.54 & value3 = 1005.14; value2 = 49.54 & value3 = 1005.14; value // Enviar solicitud HTTP POST int httpResponseCode = http.POST (httpRequestData); // Si necesita una solicitud HTTP con un tipo de contenido: // int httpResponseCode = http.POST ("¡Hola, mundo!"); // Si necesita una solicitud HTTP con un tipo de contenido: application / json, use lo siguiente: //http.addHeader("Content-Type "," application / json "); // int httpResponseCode = http.POST ("{\" value1 \ ": \" 19 \ ", \" value2 \ ": \" 67 \ ", \" value3 \ ": \" 78 \ "}"); if (httpResponseCode> 0) { Serial.print ("Código de respuesta HTTP:"); Serial.println (httpResponseCode); } else { Serial.print ("Código de error:"); Serial.println (httpResponseCode); } // Recursos gratuitos http.end (); } else { Serial.println ("WiFi desconectado"); } lastTime = millis (); } }
Your variable should be like this:
const char* serverName = "http://estacionelsano.000webhostapp.com/esp-post-data.php";
It also looks like, you’ve modified the password and the main page no longer connects to your database:
“Connection failed: ProxySQL Error: Access denied for user ‘id13935491_esp_tablero’@’2a02:4780:bad:f00d::3’ (using password: YES)”