Hi, I'm trying to send the serial communication output of Arduino UNO - ESP32 to 000Webhost, but it always failed.
This is the command I use. I hope someone can help me ![]()
#include <SoftwareSerial.h>
#include "WiFi.h"
#include "HTTPClient.h"
//variabel software serial
SoftwareSerial DataSerial (18, 19);
//milis
unsigned long previousMillis = 0;
const long interval = 3000;
//variabel array pharsing
String arrData[32];
//var for wifi and pss
const char* ssid = "WHERE";
const char* pass = "Exercise-ok-";
//variabel server
const char* host = "faotdaud27.000webhostapp.com";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
DataSerial.begin(9600);
//connect to wifi
WiFi.begin(ssid, pass);
Serial.println("Connecting....");
while(WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(500);
}
//if connected to wifi
Serial.println("Connected");
}
void loop() {
// conf millis
unsigned long currentMillis = millis ();
if(currentMillis - previousMillis >= interval)
{
//update premillis
previousMillis =currentMillis;
//read dataserial
String data = "";
while(DataSerial.available()>0)
{
data += char(DataSerial.read());
}
data.trim();
if(data != "")
{
// format data "122#52.00#223"
//pharsing
int index =0;
for(int i=0; i<= data.length() ; i++)
{
char delimiter = '#' ;
if(data[i] != delimiter)
arrData[index] += data[i];
else
index++; //batasi klo tidak variabel + 1
}
if(index == 2)
{
Serial.println(arrData[0]);
Serial.println(arrData[1]);
Serial.println(arrData[2]);
}
String tds = arrData[0];
String ph = arrData[1];
String aliran = arrData[2];
arrData[0] = "";
arrData[1] = "";
arrData[2] = "";
// send data to server
WiFiClient client ;
// inisialisasi port
const int httpPort = 80;
if( !client.connect(host, httpPort) );
{
Serial.println("Connection Failed");
return;
}
//send to web
String Link;
HTTPClient http;
Link ="http://" + String(host) + "/senddata.php?tds=" + String(tds) + "&ph=" + String(ph) + "&aliran=" + String(aliran);
http.begin(Link);
http.GET();
// respon
String respon = http.getString();
Serial.println(respon);
http.end();
}
DataSerial.println("Yes");
}
}
this program succeeds when connecting to the router, but fails when connecting to the server/host