• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Trying something new

Q&A Forum › Category: ESP8266 › Trying something new
0 Vote Up Vote Down
nan_cogtest asked 4 years ago

I don’t have the transceiver so i want to use WIFI. So what i have done is to create a host and connect to my localhost using WIFI, however using localhost does not work as part of the paths, so i use IP.

The actual page is set at http://localhost:54062/api/Environment/Save, so i use 192.168.1.100:54062/api/env/save. How do i connect using Wifi?

I have this

const char* host = "192.168.1.80";
WiFiClient client;
const int httpPort = 54062;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;

this works gets me connected to IP but not to “save” part

This does not work http://localhost:54062/api/Environment/Save
nor http://192.168.0.80:54062/api/Environment/Save

Thanks

Question Tags: ESP32 wifi
12 Answers
0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Hello, unfortunately I’m not sure I understand exactly what you’re trying to do…

  1. Do you want your ESP to make an HTTP request to another device on that URL?
  2. Or do you want to turn your ESP in a web server to receive requests on that URL?

Which project are you following from my courses? Thanks!

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

i want to connect to my localhost, which is connecting to a Web API on my PC. it has a URL http://192.168.0.80:54062/api/Environment/Save, const char* host = http://192.168.0.80:54062/api/Environment/Save does not work

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

So this is what i want to connect to http://localhost:54062/api/Environment/Save , i substitute the localhost for physical IP address.. but not working

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Based on that information, it looks like you’re doing everything right. If the ESP8266 is connected to the same network and your web api, you can connect to it using the IP address, port and define the path URL /api/Environment/Save. So, I’m not sure what’s missing…

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

sure, but how do you define the URL and send that?
const char* host = “192.168.1.80”; which is localhost
In reality i wanted host to be http://localhost:54062/api/Environment/Save like in postman

// Use WiFiClient class to create TCP connections
WiFiClient client;
const int httpPort = 54062;
if (!client.connect(host, httpPort)) {
Serial.println(“connection failed”);
return;
Now where do i include the the rest of the URL /api/Environment/Save
I guess many of us use localhost.. You must know postman? it post and sends data to localhost.

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Yes, I’m familiar with Postman for HTTP quests and API testing. You can only use localhost when you’re making requests to your web app with the same computer (because it has the same IP address).

When the ESP32 calls a service to your laptop, you need to use the IP address of the device that is connecting to (instead of the localhost).

Yes, defining the IP address like that is how you do it.

const char* host = "192.168.1.80";

Regards,
Rui

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

the full path is http://localhost:54062/api/Environment/Save
Localhoost = “192.168.1.80” Port is 54062
what about the rest? How do i get to this /api/Environment/Save

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

In the section that you do the POST or GET, you can enter the path of the request. As follows:
client.println(“POST /api/Environment/Save TTP/1.1”);
client.println(“Host: “192.168.1.80);

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

Need to string together a URI

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Why is that?
I think that if you set the port and the host (the other device IP address or domain name), you just need to add the path to the request like I’ve mentioned in my previous comment…
It always worked for me like that…

0 Vote Up Vote Down
nan_cogtest answered 4 years ago

Ok, will try.. do i need to add the port somewhere, 54062?
Thank you

0 Vote Up Vote Down
Rui Santos Staff answered 4 years ago

Yes, you need to define the port and IP address that you wish to connect to.

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] SMART HOME with RPi, ESP32, and ESP8266 (version 1.2) March 8, 2023
  • [eBook Updated] ESP32-CAM Projects (version 1.3) January 7, 2023

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2023 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.