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();
Samy
  • 1,013
  • 3
  • 15
  • 25
  • 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? – Will Aug 09 '16 at 20:27
  • Yes :) it is in the same network – Samy Aug 12 '16 at 08:10
  • I am having the same issue. I am using this lib: https://pypi.python.org/pypi/socketIO-client I can connect to python socketIO server: https://pypi.python.org/pypi/python-socketio But I cannot connect to nodejs socket.io server Any help? – Mike Aug 07 '17 at 23:24

1 Answers1

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.

dvlsg
  • 5,378
  • 2
  • 29
  • 34
  • 2
    I am having the same issue. I am using this lib: https://pypi.python.org/pypi/socketIO-client I can connect to python socketIO server: https://pypi.python.org/pypi/python-socketio But I cannot connect to nodejs socket.io server Any help? – Mike Aug 07 '17 at 23:24