R
Railway17mo ago
lwks

ESP 8266 Insecure Mode, Port, API, Code

I I'm doing a project on my ESP8266 and I need to specify the port in it, how do I get this port in the application on Raiway?
Solution:
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
...
Jump to solution
45 Replies
Percy
Percy17mo ago
Project ID: d657d7cf-8a1b-4250-ba51-c248ff710b4a
lwks
lwksOP17mo ago
d657d7cf-8a1b-4250-ba51-c248ff710b4a
Fragly
Fragly17mo ago
process.env.PORT or something oh I was right?
MantisInABox
MantisInABox17mo ago
Yeup
Fragly
Fragly17mo ago
PepeChadge
lwks
lwksOP17mo ago
but, where i put this?
Fragly
Fragly17mo ago
I mean of course I was wherever you need the port
MantisInABox
MantisInABox17mo ago
You would put it where you have 443
lwks
lwksOP17mo ago
i'll try, just a sec
Brody
Brody17mo ago
what the hell are you two on about
lwks
lwksOP17mo ago
y, im confused now
Brody
Brody17mo ago
you specify port 443 when connecting from the esp8266 to a service on railway, just like you are doing, so i assume theres an issue elsewhere
MantisInABox
MantisInABox17mo ago
Oh damn! My bad. Didn’t read it fully 😅
lwks
lwksOP17mo ago
but i need specify the port, i used 443 bc it's default
Brody
Brody17mo ago
yes thats correct theres an issue elsewhere
Fragly
Fragly17mo ago
lwks
lwksOP17mo ago
but not work with Railway API
Brody
Brody17mo ago
please send the url your esp is trying to connect to
lwks
lwksOP17mo ago
i tried with another API example and thats works cafofo.up.railway.app/dev_esp
Brody
Brody17mo ago
try with https://cafofo.up.railway.app/dev_esp instead
lwks
lwksOP17mo ago
just a sec
Brody
Brody17mo ago
also what esp lib are you using for the http client
lwks
lwksOP17mo ago
i'm using https lib
lwks
lwksOP17mo ago
Brody
Brody17mo ago
are you using the ESP8266HTTPClient.h lib too?
lwks
lwksOP17mo ago
yes no, sorry just ESP8266WiFi.h
Brody
Brody17mo ago
that lib doesnt have anything to do with making http requests so you arent using ESP8266HTTPClient.h?
lwks
lwksOP17mo ago
i tried a lot of examples and examples but none works
lwks
lwksOP17mo ago
im using this libs
Brody
Brody17mo ago
you really should be using ESP8266HTTPClient.h it would make your life so much easier
lwks
lwksOP17mo ago
i think i tried use this lib i i'll try again
Brody
Brody17mo ago
are you aware that the esp8266 does not contain ssl client certs to validate the request? you will either need to provide a fingerprint or enable insecure mode
lwks
lwksOP17mo ago
hmmmm, how can i enable insecure mode?
Solution
Brody
Brody17mo ago
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
https.begin(client, url);
https.begin(client, url);
https.GET();
https.GET();
https.getString()
https.getString()
Brody
Brody17mo ago
this is using ESP8266HTTPClient.h and WiFiClientSecure.h
lwks
lwksOP17mo ago
im trying that's works
Brody
Brody17mo ago
hell yeah!
lwks
lwksOP17mo ago
i i'll put code here
Brody
Brody17mo ago
are you using ArduinoJson.h absolute amazing library
lwks
lwksOP17mo ago
y, i tried too but with information about insecure mode, i'll try again with this lib
Brody
Brody17mo ago
makes working with json on arduino just as easy as any other statically typed language
lwks
lwksOP17mo ago
c++
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>

// Substitua pelos detalhes da sua rede Wi-Fi
const char* ssid = "SSID";
const char* password = "PASS";

// Endereço da API
const char* host = "API_URL";

void setup() {
Serial.begin(9600);
delay(10);

// Conecta-se à rede Wi-Fi
Serial.println();
Serial.print("Connecting to: ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi Conn established!");
Serial.println("IP address: " + WiFi.localIP().toString());
}

void loop() {
// Use a conexão WiFiClientSecure
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
Serial.print("Connecting to: ");
Serial.println(host);
https.begin(client, host);
int httpCode = https.GET();
if (httpCode > 0){
String payload = https.getString();
Serial.print("Http code: ");
Serial.println(httpCode);
Serial.print("\nPayload: ");
Serial.println(payload);
}
delay(500);

// Verificar se a conexão é bem-sucedida
if (client.connected()) {
Serial.println("Conn sucess!");
} else {
Serial.println("Conn failed!");
return;
}

// Ler a resposta do servidor
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}

Serial.println();
Serial.println("Conn Close!");
client.stop();

// Aguarda alguns segundos antes de fazer uma nova requisição
delay(5000);
}
c++
#include <ESP8266WiFi.h>
#include <WiFiClientSecure.h>
#include <ESP8266HTTPClient.h>

// Substitua pelos detalhes da sua rede Wi-Fi
const char* ssid = "SSID";
const char* password = "PASS";

// Endereço da API
const char* host = "API_URL";

void setup() {
Serial.begin(9600);
delay(10);

// Conecta-se à rede Wi-Fi
Serial.println();
Serial.print("Connecting to: ");
Serial.println(ssid);
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi Conn established!");
Serial.println("IP address: " + WiFi.localIP().toString());
}

void loop() {
// Use a conexão WiFiClientSecure
HTTPClient https;
WiFiClientSecure client;
client.setInsecure();
Serial.print("Connecting to: ");
Serial.println(host);
https.begin(client, host);
int httpCode = https.GET();
if (httpCode > 0){
String payload = https.getString();
Serial.print("Http code: ");
Serial.println(httpCode);
Serial.print("\nPayload: ");
Serial.println(payload);
}
delay(500);

// Verificar se a conexão é bem-sucedida
if (client.connected()) {
Serial.println("Conn sucess!");
} else {
Serial.println("Conn failed!");
return;
}

// Ler a resposta do servidor
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.print(line);
}

Serial.println();
Serial.println("Conn Close!");
client.stop();

// Aguarda alguns segundos antes de fazer uma nova requisição
delay(5000);
}
I looked it up, it's a good library tks for help @Brody!!!!!
Brody
Brody17mo ago
except for the use of delay() (use SimpleTimer.h) code looks relatively good
lwks
lwksOP17mo ago
Ok, thx for the tip
Brody
Brody17mo ago
no problem, im glad i was able to help you! good title change!
Want results from more Discord servers?
Add your server