-->
Page 1 of 2

Cannot send data to my website

PostPosted: Wed Aug 26, 2020 11:02 am
by dimbil
I am trying to send data from esp8266-arduino to my website but unfortunately I cannot
This is my code
#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

ESP8266WiFiMulti WiFiMulti;
String myURL ="http://alfa8400.000webhostapp.com/index.php?";
//
String first = "alfa";
String second = "vita";

void setup() {

Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println();

for (uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] WAIT %d...", t);
Serial.flush();
delay(1000);
}

WiFi.mode(WIFI_STA);
WiFiMulti.addAP("user-name", "pwd ");

}

if ((WiFiMulti.run() == WL_CONNECTED)) {

WiFiClient client;

HTTPClient http;

Serial.print("[HTTP] begin...\n");
if (http.begin(client, myURL+"first="+first+"&second="+second))
Serial.print("[HTTP] GET...\n");
//
http.begin(myURL); //
int httpCode = http.GET();

// httpCode will be negative on error
if (httpCode > 0) {
//
Serial.printf("[HTTP] GET... code: %d", httpCode);

if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s", http.errorToString(httpCode).c_str());
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect");
}
}
delay(10000);
}

Can you please help me?

Re: Cannot send data to my website

PostPosted: Wed Aug 26, 2020 11:18 am
by Bonzo
Serial.printf("[HTTP] GET... code: %d", httpCode);

This should display an error code; what is it?
I am not not sure you can use Serial.printf

Re: Cannot send data to my website

PostPosted: Thu Aug 27, 2020 1:12 am
by dimbil
It displays the following:
0f000, len 1384, room 16
tail 8
csum 0xef
csum err
ets-main.c

Re: Cannot send data to my website

PostPosted: Thu Aug 27, 2020 7:40 am
by Bonzo
So that error is something in your code and not a problem connecting to the webserver. Have you tried the example code without changing it to your values?