R
Railway16mo 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
Percy16mo ago
Project ID: d657d7cf-8a1b-4250-ba51-c248ff710b4a
lwks
lwks16mo ago
d657d7cf-8a1b-4250-ba51-c248ff710b4a
Fragly
Fragly16mo ago
process.env.PORT or something oh I was right?
MantisInABox
MantisInABox16mo ago
Yeup
Fragly
Fragly16mo ago
PepeChadge
lwks
lwks16mo ago
but, where i put this?
Fragly
Fragly16mo ago
I mean of course I was wherever you need the port
MantisInABox
MantisInABox16mo ago
You would put it where you have 443
lwks
lwks16mo ago
i'll try, just a sec
Brody
Brody16mo ago
what the hell are you two on about
lwks
lwks16mo ago
y, im confused now
Brody
Brody16mo 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
MantisInABox16mo ago
Oh damn! My bad. Didn’t read it fully 😅
lwks
lwks16mo ago
but i need specify the port, i used 443 bc it's default
Brody
Brody16mo ago
yes thats correct theres an issue elsewhere
Fragly
Fragly16mo ago
lwks
lwks16mo ago
but not work with Railway API
Brody
Brody16mo ago
please send the url your esp is trying to connect to
lwks
lwks16mo ago
i tried with another API example and thats works cafofo.up.railway.app/dev_esp
Brody
Brody16mo ago
try with https://cafofo.up.railway.app/dev_esp instead
lwks
lwks16mo ago
just a sec
Brody
Brody16mo ago
also what esp lib are you using for the http client
lwks
lwks16mo ago
i'm using https lib
lwks
lwks16mo ago
Brody
Brody16mo ago
are you using the ESP8266HTTPClient.h lib too?
lwks
lwks16mo ago
yes no, sorry just ESP8266WiFi.h
Brody
Brody16mo ago
that lib doesnt have anything to do with making http requests so you arent using ESP8266HTTPClient.h?
lwks
lwks16mo ago
i tried a lot of examples and examples but none works
lwks
lwks16mo ago
im using this libs
Brody
Brody16mo ago
you really should be using ESP8266HTTPClient.h it would make your life so much easier
lwks
lwks16mo ago
i think i tried use this lib i i'll try again
Brody
Brody16mo 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
lwks16mo ago
hmmmm, how can i enable insecure mode?
Solution
Brody
Brody16mo 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
Brody16mo ago
this is using ESP8266HTTPClient.h and WiFiClientSecure.h
lwks
lwks16mo ago
im trying that's works
Brody
Brody16mo ago
hell yeah!
lwks
lwks16mo ago
i i'll put code here
Brody
Brody16mo ago
are you using ArduinoJson.h absolute amazing library
lwks
lwks16mo ago
y, i tried too but with information about insecure mode, i'll try again with this lib
Brody
Brody16mo ago
makes working with json on arduino just as easy as any other statically typed language
lwks
lwks16mo 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
Brody16mo ago
except for the use of delay() (use SimpleTimer.h) code looks relatively good
lwks
lwks16mo ago
Ok, thx for the tip
Brody
Brody16mo ago
no problem, im glad i was able to help you! good title change!
Want results from more Discord servers?
Add your server