6

I'm trying to send values from my raspberry pi (in python 2.7.9) to my nodeJS server with socket.io.

My goal ist send many values continuously from my pi over a websocket connection to my node Server (local), which should take the values and show it on the index.html (for other clients, like a Web-Chat where just the raspberry sends values)

I tried everything but I can't make a handshake and send data. When I open the "http://IP_ADDRESS:8080" in my browser I see a connection but not with my python Code.

Please I need some help....

server.js

var express = require('express')
,   app = express()
,   server = require('http').createServer(app)
,   io = require('socket.io').listen(server)
,   conf = require('./config.json');

// Webserver
server.listen(conf.port);

app.configure(function(){

    app.use(express.static(__dirname + '/public'));
});


app.get('/', function (req, res) {

    res.sendfile(__dirname + '/public/index.html');
});

// Websocket
io.sockets.on('connection', function (socket) {

    //Here I want get the data
    io.sockets.on('rasp_param', function (data){
        console.log(data);
    });

    });
});

// Server Details
console.log('Ther server runs on http://127.0.0.1:' + conf.port + '/');

my python websocket-code in which I just want send values

#!/usr/bin/env python
#

from websocket import create_connection

ws = create_connection("ws://IP_ADDRESS:8080/")
ws.send("Some value")
ws.close();
3
  • When you say http://IP_ADDRESS:8080 is IP_ADDRESS 127.0.0.1 or is it an address on the same network your pi is connected to? Commented Aug 9, 2016 at 20:27
  • Yes :) it is in the same network Commented Aug 12, 2016 at 8:10
  • I am having the same issue. I am using this lib: pypi.python.org/pypi/socketIO-client I can connect to python socketIO server: pypi.python.org/pypi/python-socketio But I cannot connect to nodejs socket.io server Any help? Commented Aug 7, 2017 at 23:24

1 Answer 1

2

Socket.io communications aren't plain websockets. You probably need an implementation of the socket.io client on python, to make sure that the messages you are sending are compatible with the socket.io protocol. Something like socketIO-client, maybe.

Sign up to request clarification or add additional context in comments.

1 Comment

I am having the same issue. I am using this lib: pypi.python.org/pypi/socketIO-client I can connect to python socketIO server: pypi.python.org/pypi/python-socketio But I cannot connect to nodejs socket.io server Any help?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.