i cant connect my server ![]()
connecting to assess.mmaviot.com:443
sending data to server
request sent
Command :
/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb
Status :
HTTP/1.1 400 Bad Req
Status Size:
20
HTTP/1.1 400 Bad Req
** Connection Failed **
HTTP/1.1 400 Bad Req
receiving from remote server
Print Data Available
uest
Server: nginx/1.14.2
Date: Fri, 20 Aug 2021 16:49:55 GMT
Content-Type: text/html
Content-Length: 271
Connection: close
400 Bad Request
The plain HTTP request was sent to HTTPS portnginx/1.14.2
closing connection
Code :
#include <SPI.h>
#include <ENC28J60lwIP.h>
#include <ESP8266WiFi.h>
const char* host = "assess.mmaviot.com";
const uint16_t port = 443;
#define CSPIN 15
ENC28J60lwIP eth(CSPIN);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(103, 130, 144, 73);
void setup() {
Serial.begin(115200);
delay(500);
WiFi.mode(WIFI_OFF);
SPI.begin();
// if (!eth.config(ip, gw, nm, gw, IPADDR_NONE)) {
// Serial.println("wrong config");
// }
eth.setDefault(); // use ethernet for default route
if (!eth.begin(mac)) {
Serial.println("ethernet hardware not found ... sleeping");
while (1) {
delay(1000);
}
} else {
Serial.print("connecting ethernet");
while (!eth.connected()) {
Serial.print(".");
delay(1000);
}
}
Serial.println();
Serial.print("ethernet IP address: ");
Serial.println(eth.localIP());
Serial.println(eth.gatewayIP());
Serial.println(eth.subnetMask());
Serial.println(WiFi.dnsIP());
}
void loop() {
static bool wait = true;
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
delay(5000);
return;
}
// This will send a string to the server
Serial.println("sending data to server");
if (client.connected()) {
//////////////////////////////////////////////
String command_get = "/gadget/skeleton?serial=swr012108031138&uid=95f916e0-56d6-487f-82dd-da75b14081cb";
delay(20);
client.println( String("GET ") + command_get + " HTTP/1.1\r\n" + "Host: " + "assess.mmaviot.com" + "\r\n" + "Connection: close" + "\r\n\r\n");
Serial.println("request sent");
delay(500);
Serial.flush();
char status[20] = {0};
client.readBytesUntil('\r', status, sizeof(status));
Serial.println("Command :");
Serial.println(command_get);
Serial.println("Status :");
Serial.println(status);
Serial.println("Status Size:");
Serial.println(String(sizeof(status)));
Serial.println(status);
if (strcmp(status + 9, "200 OK") == 0)
{
Serial.println("Connection Success");
// TLS = true;
while (client.connected()) {
char endOfHeaders[] = "\r\n\r\n";
if (client.find(endOfHeaders)) {
Serial.println(status);
String Data_Server = client.readString();
// AnsTLS = Data_Server;
Serial.println(Data_Server);
}
}
}
else {
Serial.println("** Connection Failed **");
Serial.println(status);
}
/////////////////////////////////////////////////
//
//
// client.println("hello from ESP8266");
}
// wait for data to be available
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
delay(60000);
return;
}
}
// Read all the lines of the reply from server and print them to Serial
Serial.println("receiving from remote server");
// not testing 'client.connected()' since we do not need to send data here
Serial.println("Print Data Available");
while (client.available()) {
char ch = static_cast<char>(client.read());
Serial.print(ch);
}
// Close the connection
Serial.println();
Serial.println("closing connection");
client.stop();
if (wait) {
delay(300000); // execute once every 5 minutes, don't flood remote service
}
wait = true;
}