Hey guys, I'm writing code on an esp32 using a w5500 module and I'm trying to make an http SSL request on my test API , and the problem is in the API response, the code prints all the content on the website and I need it only from the response which is the value 1 (which is the second number among the 3 numbers printed at the end of the console), below I will put the LOG of the responses and all the code for you to view, if anyone knows how I can change it to obtain only I would greatly appreciate the answer!!
the respose:
Begin Ethernet
17:36:32.343 -> DHCP OK!
17:36:37.402 -> Local IP : 192.168.0.148
17:36:37.402 -> Subnet Mask : 255.255.255.0
17:36:37.402 -> Gateway IP : 192.168.0.1
17:36:37.439 -> DNS Server : 192.168.0.1
17:36:37.440 -> Ethernet Successfully Initialized
17:36:38.569 -> connected to Resposta inválida: HTTP/1.1 200 OK
17:36:38.693 -> Server: hcdn
17:36:38.693 -> Date: Tue, 03 Oct 2023 20:36:37 GMT
17:36:38.740 -> Content-Type: application/json
17:36:38.740 -> Transfer-Encoding: chunked
17:36:38.819 -> Connection: close
17:36:38.819 -> Vary: Accept-Encoding
17:36:38.819 -> x-powered-by: PHP/8.1.18
17:36:38.883 -> platform: hostinger
17:36:38.883 -> content-security-policy: upgrade-insecure-requests
17:36:38.959 -> x-turbo-charged-by: LiteSpeed
17:36:39.006 -> x-hcdn-request-id: 2785735fb09b8ebe1898eaf4f2a403c5-asc-edge1
17:36:39.006 -> x-hcdn-cache-status: DYNAMIC
17:36:39.070 -> x-hcdn-upstream-rt: 0.014
17:36:39.070 ->
17:36:39.070 -> 1
17:36:39.070 -> 1
17:36:39.070 -> 0
The base file of the code:
#include <SPI.h>
#include <EthernetLarge.h>
#include <SSLClient.h>
#include "trust_anchors.h"
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "thaianramalho.com";
const int rand_pin = A5;
EthernetClient base_client;
SSLClient client(base_client, TAs, (size_t)TAs_NUM, rand_pin);
unsigned long beginMicros, endMicros;
unsigned long byteCount = 0;
bool printWebData = true;
void setup() {
Serial.begin(9600);
delay(1000);
Serial.println("Begin Ethernet");
Ethernet.init(5);
if (Ethernet.begin(mac)) {
Serial.println("DHCP OK!");
} else {
Serial.println("Failed to configure Ethernet using DHCP");
if (Ethernet.hardwareStatus() == EthernetNoHardware) {
Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :(");
while (true) {
delay(1);
}
}
if (Ethernet.linkStatus() == LinkOFF) {
Serial.println("Ethernet cable is not connected.");
}
IPAddress ip(192, 168, 1, 28);
IPAddress dns(192, 168, 1, 1);
IPAddress gw(192, 168, 1, 1);
IPAddress sn(255, 255, 255, 0);
Ethernet.begin(mac, ip, dns, gw, sn);
Serial.println("STATIC OK!");
}
delay(5000);
Serial.print("Local IP : ");
Serial.println(Ethernet.localIP());
Serial.print("Subnet Mask : ");
Serial.println(Ethernet.subnetMask());
Serial.print("Gateway IP : ");
Serial.println(Ethernet.gatewayIP());
Serial.print("DNS Server : ");
Serial.println(Ethernet.dnsServerIP());
Serial.println("Ethernet Successfully Initialized");
if (client.connect(server, 443)) {
Serial.print("connected to ");
client.println("GET /jsonteste.php HTTP/1.1");
client.println("Host: thaianramalho.com");
client.println("Connection: close");
client.println();
} else {
Serial.println("connection failed");
}
beginMicros = micros();
}
void loop() {
int len = client.available();
if (len > 0) {
byte buffer[80];
if (len > 80) len = 80;
client.read(buffer, len);
if (printWebData) {
Serial.write(buffer, len);
}
byteCount = byteCount + len;
// Verifique se a resposta contém "1"
if (strstr((char*)buffer, "1") != NULL) {
Serial.println("deu certo");
} else {
Serial.println("nao deu chefe");
}
}
if (!client.connected()) {
endMicros = micros();
Serial.println();
Serial.println("disconnecting.");
client.stop();
Serial.print("Received ");
Serial.print(byteCount);
Serial.print(" bytes in ");
float seconds = (float)(endMicros - beginMicros) / 1000000.0;
Serial.print(seconds, 4);
float rate = (float)byteCount / seconds / 1000.0;
Serial.print(", rate = ");
Serial.print(rate);
Serial.print(" kbytes/second");
Serial.println();
while (true) {
delay(1);
}
}
}