I cannot send data to my webpage
Posted: Sun Aug 30, 2020 10:31 am
I am trying to send data from arduino-esp8266 to my webpage but I cannot make it
This is the 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.setDebugOutput(true);
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 ");
}
void loop()
{
// wait for WiFi connection
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();
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);
}
Is there someone to help me please?
This is the 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.setDebugOutput(true);
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 ");
}
void loop()
{
// wait for WiFi connection
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();
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);
}
Is there someone to help me please?