washo4evr / Socket.io-v1.x-Library

Socket.io Library for Arduino
108 stars 58 forks source link

Not working with esp32 #64

Open futechiot opened 5 years ago

futechiot commented 5 years ago

Hello There,

i have a socket.io server running, and its working fine with esp8266 using another library.
using your library i'm not able to connect to our socket.io server for ESP8266 AND ESP32. this examples only work for for your server code(APP.JS)??

i have server code as follow:

#! /usr/bin/env node
var fs = require('fs');
var opt = require('optimist');
var url = require('url');
var argv = opt.usage('Usage: $0 [flags]')
.alias('p', 'port')
.describe('p', 'TCP port for the http server (3000)')
.alias('d', 'debug')
.describe('d', 'Enable debug output')
.alias('l', 'log')
.describe('l', 'Log arduino output to file')
.argv;
if (argv.help) {
opt.showHelp();
process.exit();
}
var port = argv.port || 3000;
var log_file = "datalog.txt";
console.log('WebSocket Commander here!', argv);

//Load https certificates
var privateKey = fs.readFileSync('keys/key.pem', 'utf8');
var certificate = fs.readFileSync('keys/cert.pem', 'utf8');
var credentials = {
key: privateKey,
cert: certificate,
passphrase: 'socketio'
};

//  Configure HTTP server
//
var express = require('express');
var app = express();
var https = require('https');
var server = https.Server(credentials, app);
var io = require('socket.io')(server);
io.set('log level', argv.debug ? 3 : 1);
app.use(express.static(__dirname + '/public'));
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html');
});

server.listen(port);
console.log('Listening on port:', port);
//  Socket.io startup
//
var output_socket;
var fs = require('fs');
var tty = io
.of('/tty')
.on('connection', function (socket) {
console.log('Browser connected.');
socket.emit('message', 'Connected to server at ' + new Date().toString() + '\n');
socket.on('message', function (data) {
console.log('from client: ', data);
if (output_socket) output_socket.emit(data);
});
var sendPingToBrowser=setInterval(function () {
console.log("Pinging Browser...");
socket.emit('message','Ping from server...'+'\n');
},30000);
});
//Not working
tty.on('disconnect',function(data){
console.log("Browser disconnect");
});
io.on('connection', function (socket) {
socket.on('device status', function (data) {
//If device begins to communicate 
if (data.status == "200") {
console.log("device ready to recieve data");
//Send ping to client ever 1000ms
sendPing = setInterval(function () {
console.log("emittng message...");
io.emit('server status', {
status: '100'
});
}, 1000);
} else if (data.status == "100") {
console.log("Recieved ping from client", data)
io.emit('server status', {
status: '100'
});
} else {
console.log("device not ready");
console.log(data);
}
});
//On getting a message form the server
socket.on('message', function (data) {
console.log("Recieved Message");
console.log(data);
tty.emit('message', data);
});
output_socket = socket; // save global ugh
//On disconnect stop emitting
socket.on('disconnect', function () {
io.emit('Esp disconnected');
});
});
//  Keyboard handling
//
var cmd = '';
process.stdin.setRawMode(true);
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function (key) {
if ((key === '\u0003') || (key == 'q')) process.exit();
else if ((key === '\r') || (key == '\n')) {
process.stdout.write('\r\n');
output_socket.emit(cmd);
cmd = '';
} else {
process.stdout.write(key);
cmd = cmd + key;
}
});

while i'm using hello_time ESP32 i'm getting these warnings: and for ESP8266 this codes are not working for our server code `C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp: In member function 'void SocketIOClient::send(String, String, String)': C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:401:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[2] = (msglength >> 56) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:403:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[3] = (msglength >> 48) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:405:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[4] = (msglength >> 40) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:407:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[5] = (msglength >> 32) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp: In member function 'void SocketIOClient::sendJSON(String, String)':

C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:459:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[2] = (msglength >> 56) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:461:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[3] = (msglength >> 48) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:463:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[4] = (msglength >> 40) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:465:29: warning: right shift count >= width of type [-Wshift-count-overflow] header[5] = (msglength >> 32) & 255; ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp: In member function 'bool SocketIOClient::monitor()':

C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:163:1: error: control reaches end of non-void function [-Werror=return-type]

} ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp: In member function 'void SocketIOClient::send(String, String, String)':

C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:404:15: error: 'header[4]' may be used uninitialized in this function [-Werror=maybe-uninitialized] client.print((char)header[4]); ^ C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp: In member function 'void SocketIOClient::sendJSON(String, String)':

C:\Users\Arana\Documents\Arduino\libraries\Socket.io-v1.x-Library-master\SocketIOClient.cpp:462:15: error: 'header[4]' may be used uninitialized in this function [-Werror=maybe-uninitialized] client.print((char)header[4]); ^ cc1plus.exe: some warnings being treated as errors ` kindly fix this, thank you

bo01ean commented 5 years ago

Can you try running the server without the credentials?

futechiot commented 5 years ago

@bo01ean yes, i have a credential but i can't simply give you the host IP of our server dude! moreover, i have another esp8266 library for the socket.io, it works fine,

but i want to send data on our socket.io server using ESP32.