Go Down

Topic: ESP32/ESP8266 connect to localhost server using WiFi (Read 1 time) previous topic - next topic

eahabissac

Dec 05, 2017, 06:48 pm Last Edit: Dec 05, 2017, 08:50 pm by eahabissac
Hi, I have made a simple local server to receive the data from ESP and put it in data base
the server is working fine as I tested it using postman. the server is listening to port 127.0.0.1:3000

my problem is that client.connect(host,port) returns false.


Code: [Select]
#include "Arduino.h"

#include "WiFi.h"



WiFiClient client;
const IPAddress server(192,168,1,10);

const int httpPort = 3000;


const char* ssid = "******";
const char* password =  "********";
void setup()
{
  Serial.begin(115200);
  
  Serial.println();
  Serial.println("Booted");
  Serial.println("Connecting to Wi-Fi");

  WiFi.begin (ssid, password);
  WiFi.mode(WIFI_STA);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    yield();
  }
  Serial.println("WiFi connected");

 if (client.connect(server,httpPort )){
 Serial.println("Client Connected");

 }


 else{
     Serial.println("No Connection");
  }


}

// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here
}



Juraj

use
Code: [Select]
#include <ESP8266WiFi.h>

and remove those arduino includes

eahabissac

use
Code: [Select]
#include <ESP8266WiFi.h>

and remove those arduino includes

This is ESP32 WiFi library not Arduino WiFi library
I have removed the doubled "Arduino.h"  the problem is not there

Juraj


eahabissac

from esp8266 arduino core 2.3?
I have tested the provided example on ESP32 and ESP8266 on both platforms the connection to the localhost failed

for sure when I am switching the platforms for testing I change the WiFi library

WiFi.h for ESP32
ESP8266WiFi.h for ESP8266

I am using esp8266 core 2.2.0 and the latest  for ESP32 core 

Juraj

ok. I understand.

the examples work? WiFiClient example?

eahabissac

ok. I understand.

the examples work? WiFiClient example?
Yes I can connect to any online host like "script.google.com" or sparkfun

Juraj

the IP address is correct? in post text you have the loopback address and in sketch a real address.

eahabissac

the IP address is correct? in post text you have the loopback address and in sketch a real address.
IPv4 Address. . . . . . . . . . . : 192.168.1.10
   Subnet Mask . . . . . . . . . . . : 255.255.255.0

I was disparate so I reset it manually :D yes its correct 

Juraj

IPv4 Address. . . . . . . . . . . : 192.168.1.10
   Subnet Mask . . . . . . . . . . . : 255.255.255.0

I was disparate so I reset it manually :D yes its correct 
it is the server address, right? not the esp address?

the server is http or https?

eahabissac

it is the server address, right? not the esp address?

the server is http or https?
yes, my pc IP address which runs the local  server

Juraj

the postman url, if you test it from browser is http or https? why port 3000? it is unusual

eahabissac

the postman url, if you test it from browser is http or https? why port 3000? it is unusual
its http
3000 No reason,
its working fine with postman

Go Up