Skip to content

esp8266 can't connect to server #3348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
warrior0 opened this issue Jun 13, 2017 · 2 comments
Closed

esp8266 can't connect to server #3348

warrior0 opened this issue Jun 13, 2017 · 2 comments

Comments

@warrior0
Copy link

warrior0 commented Jun 13, 2017

i'm trying to connect esp8266(nodemcu v1.0) to my socket server(programming with node.js) the esp8266 can connect to my wifi but it can't connect to the server.
here is my esp8266 arduino ide code:

`#include <ESP8266WiFi.h>
#include <SocketIOClient.h>
SocketIOClient client;
const char* ssid = "Family";
const char* password = "bat3glendi";
char host[] = "192.168.1.2";
int port = 3848;

extern String RID;
extern String Rfull;

unsigned long previousMillis = 0;
long interval = 2000;

void setup(){
Serial.begin(115200);
delay(10);
Serial.print("connect to: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print('.');
}

Serial.println();
Serial.println(F("connected"));
Serial.print(F("ESP8266's ip: "));
Serial.println(WiFi.localIP());

if (client.connect(host, port)) {
    Serial.println(F("successful connect to socket server"));
    return;
}
if (client.connected()) {
    client.send("connection", "message", "Connected !!!!");
}
Serial.println(WiFi.localIP());

}
void loop()
{
if (millis() - previousMillis > interval) {

previousMillis = millis();
client.send("atime", "message", "Time please?");
}
if (client.monitor()) {
Serial.println(RID);
Serial.println(Rfull);
}

if (!client.connected()) {
  client.reconnect(host, port);
}

}`
here is my socket server code:

`var http = require('http');
var ip = require('ip');

var app = http.createServer(function(req,res){
res.write('

server good!

');
res.end();
});
var io = require('socket.io')(app);

app.listen(3848);
console.log('server ip: ' + ip.address() + ':' + 3848);

io.on('connection', function(socket){
console.log('connected');

socket.on('connection', function(message){
	console.log(message);
	socket.emit('welcome',{
		message: 'connect!!'
	});
});
socket.on('atime', function(data){
	sendTime();
	console.log(data);
});

});

function sendTime() {

var json = {
    ESP8266: 12,		
	soPi: 3.14,						
	time: new Date()						
}
io.sockets.emit('atime', json);

}`

anyone got any free courses about nodemcu .i am just getting started

@tanaydeshmukh1
Copy link

please provide me link for the <ESP8266WiFi.h> library........

@devyte
Copy link
Collaborator

devyte commented Sep 5, 2017

This is not the right place to ask for assistance on your particular project. This is an issue tracker for the core libs.
Please refer to esp8266.com or stackoverflow or similar for discussion/assistance.
Closing.

@devyte devyte closed this as completed Sep 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants