Giter VIP home page Giter VIP logo

phonepi_sampleserver's Introduction

PhonePi_SampleServer

These are simple servers with WebSocket support that accept the sensor data and write it to a text file. These are companion sample servers for the PhonePi Sensor Streamer app.

Migration Notice

Due to changes in the Android ecosystem since the last time the app was updated, we have had to re-write PhonePi. Also we have few extra sensors like camera and mic available in the new version. All new users are requested to download the "Sensor Stream" app (https://play.google.com/store/apps/details?id=com.sensorsensei) especially if you have an Android version >= X. All new updates will be made to this app. It's available for free. A pro version will be available in the upcoming months with more enancements and support for other protocols apart from Web Sockets.

We will continue to support "PhonePi" and "PhonePi+" for as long as feasible and atleast until the new version achieves feature parity with PhonePi+.

Steps:

  • Clone the repository or download the zip file and unzip it to a directory of your choice.

To Run the Python Server (version >= Python 3.0)

  • Make sure you have python (version >=3) installed and you can access both pip and python from the command line/ terminal
  • To check the same open command line/terminal and type python --version and pip --version
  • There are two servers available in Python, one uses Flask and Flask_Sockets and the other uses Websockets with async io. Both should work well. Choose as per your requirements.
  • cd to the directory where the folder was extracted in the command line
  • Optional Step: It's highly recommended, you create a virtual env before installing dependencies. Activate the virtual environment and proceed. OS specific steps are available in the docs [https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/]

Brief Summary of steps to follow to create virtual env [Optional Step]

cd Python
cd Flask or cd WebSocket # Depending upon which server you want to use
py -m venv env # Create virtual env
source env/bin/activate (On Linux or Mac) or .\env\Scripts\activate (On Windows)

Final Installation and run steps

cd PhonePi_SampleServer-master/Python
cd Flask or cd WebSocket # Depending upon which server you want to use
pip install -r requirements.txt 
python3 PhonePi.py

To run the Node Server (latest version recommended)

cd Node
npm install
npm start

To use the app

  • Make sure both your phone and the laptop/raspi are on same network.
  • Find the internal ip address of the raspi/laptop
  • If you are using Phone Pi and not Phone Pi+, simply type the ip address:5000.Example: 192.168.1.24:5000 in the app's input bar.
  • You don't need the port number if you are using Phone Pi+. Just input the ip address. Example: 192.168.1.24
  • Switch on whatever sensor's data you want to stream.

You can make any changes you want to to PhonePi.py or PhonePi.js

Data Format Cheat sheet:

Server details (Python)

This makes use of flask_sockets. Note the use of namespaces which are in accordance with the sensor's name. Sample code:

@sockets.route('/accelerometer') 
def echo_socket(ws):
	 f=open("accelerometer.txt","a")
	 while True:
		message = ws.receive()
		print(message) 
        	ws.send(message)
		print>>f,message
	 f.close()

The app would then establish a connection to ws://url//accelerometer where url is what the user enters (ip address:port)

Contribution guidelines

This repository is open to contributions. On the server side, we are looking to support sample servers in more languages and frameworks such as node.js, Go etc. Please feel free to raise PRs!

For more support, please e-mail [email protected]

phonepi_sampleserver's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

phonepi_sampleserver's Issues

GPS support

Hi, is it possible to add the GPS field to the app?

Error named unable to resolve host

while running as per the instruction, in the android application, getting an alert named "Unable to resolve host 'gyroscope' No address associated with hostname". In this gyroscope.txt file is making in the laptop folder but no values are getting stored.

How to use own Server

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. ;)

Flask_Sockets is incompatible with Flask 2 causing Python server to fail

User reported getting the following issue:

Traceback (most recent call last): File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\gevent\pywsgi.py", line 999, in handle_one_response self.run_application() File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\geventwebsocket\handler.py", line 75, in run_application self.run_websocket() File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\geventwebsocket\handler.py", line 52, in run_websocket list(self.application(self.environ, lambda s, h, e=None: [])) File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\flask\app.py", line 2088, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\flask_sockets.py", line 40, in __call__ handler, values = adapter.match() File "C:\Users\MasterS\AppData\Roaming\Python\Python39\site-packages\werkzeug\routing.py", line 2030, in match raise WebsocketMismatch() werkzeug.routing.WebsocketMismatch: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. 2021-05-28T20:45:50Z {'REMOTE_ADDR': '192.168.0.14', 'REMOTE_PORT': '43050', 'HTTP_HOST': '192.168.0.4:5000', (hidden keys: 26)} failed with WebsocketMismatch

Can't redeem promo code

Great app, I wanted to use plus version but redeem codes say that are expired, is there any chance to refresh them? Thanks in advance!

Accessing Variable from another script

from flask import Flask 
from flask_sockets import Sockets

app = Flask(__name__)
sockets = Sockets(app)

@sockets.route('/orientation')
def echo_socket(ws):
    while True:
        message = ws.receive()
        raw2 = message.split(',')
        global orient1
        orient1 = float(raw2[0])
        orient2 = float(raw2[1])
        orient3 = float(raw2[2])
        print('x = ', orient1, "is", type(orient1))
        # print('y = ', orient2, "is", type(orient2))
        # print('z = ', orient3, "is", type(orient3))
        ws.send(message)


@app.route('/') 
def hello():
    return 'Hello World!'

if __name__ == "__main__":
    from gevent import pywsgi
    from geventwebsocket.handler import WebSocketHandler
    server = pywsgi.WSGIServer(('0.0.0.0', 5000), app, handler_class=WebSocketHandler)
    server.serve_forever()

How can I access variable orient1 from another python script?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.