priyankark / PhonePi_SampleServer

Companion servers in Node and Python for the PhonePi Sensor Streamer apps.

Home Page:https://play.google.com/store/apps/details?id=com.phonepi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use own Server

chrbaumeister opened this issue · comments

Hey,
I'm tying to stream data using node.js and socket.io and want to use the data to drive a p5js sketch:

This is my Server.js

var express = require("express");
var app = express();
var server = app.listen(5000);
app.use(express.static("public"));
console.log("My Server is Running");

var socket = require("socket.io");
var io = socket(server);

io.sockets.on("connection", newConnection);

function newConnection (socket) {
	console.log("New Connection: " + socket.id);
		
	socket.on("Gyroscope", gyroscopeMSG);
	function gyroscopeMSG(data){
		console.log(data);
	}	
}

I this the right way!?
I'm new to programming sockets.

When I start my App and enter the IP and Port 5000, the App says: "unexpected end of stream on okhttp3.Adress@4883b7tb

How cann I connect PhonePi with my Server?
What is the App sending? And what data can the server listen to?

Hope you can help me. ;)

Hi! Thanks for trying the app out.
The app is completely open source and written in JS. You can actually see how it is streaming the data by seeing the source code of each component at https://github.com/priyankark/PhonePiAndroidApp/tree/master/src/Components Hope that helps!

Thanks for answering!
Ok, that's looks nice, but I can't figure out how to receive data at the client side.

The server gets the data like this (using flask-socktes):


@sockets.route('/gyroscope')
def echo_socket(ws):
	while True:
		message = ws.receive()
		print(message)
		ws.send(message)

Now I want to receive the data on my index.html like this:

var ws = new WebSocket("ws://[...url...]:.../gyroscope");
      ws.onopen = function() {
          ws.send("socket open");
      };
      ws.onclose = function(evt) {
          ws.send("socket closed");
      };
      ws.onmessage = function(message) {
          console.log(message.data);
      };

But it's not working. I've no experience using sockets, but something must be wrong with my code :)

Hey, will try to build a node server very soon when I find some time. If you are successful at it, do send a pull request!

I know I am two years too late :( but I just added a Node server. Wanted to inform you!