command line websocket client for Raspberry Pi2- no browser required implementation? - python

Send data read from GPiO to server, not only with WIFI, but also on mobile network outside anywhere. I dont have and dont want to deal with setting a public address for RPi2, so this is why I need RPi2 to be client, sending data thru websockets to server on public address. It could be node.js, python, PHP client - server, as long as it is without of the need for a browser at the client side RPi2. Any suggestions ? Thank you.
Additionally, can you please explain how would "server side node.js client" work ?

An (incomplete) list of libraries with websocket support
For Python, you could look at:
Tornado Web
Twisted Matrix
Autobahn
Crossbar.io
For node.js you could look at:
socket.io
web-socket-js
Also, you should consider editing your question. Just ask one at a time. Your second question you should research yourself, a little googling would get a link or two to a nice article explaining what you would like to know.

Related

Workaround to open COM port for serial communication on client-side (preferably in Python)

Goal
I have made a website using the Flask framework and am fairly comfortable with HTML, CSS, JS, Python. My goal is to connect an arduino to the client's PC's usb port and use serial.write() to send a number to it.
Notes
I have a working example of interfacing with python if arduino was connected to the server.
import serial
ser = serial.Serial('COM4', 9600)
ser.write('5')
Now I want to run these exact 3 lines on the client side.
Is this even doable? I have researched a lot and it seems that this is not doable due to security reasons? (I'm hoping somebody proves me wrong here.) That is why I'm looking for a workaround. But before that I must mention, I don't need any of the data (numbers) to come from the server. Once the webpage is loaded all serial communication that I need is on the client side.
Client side python: I have looked into writing python on the client side and read about skulpt and PyPyjs but am not sure how I could run the mentioned 3 lines with them on client side(neither seems to support pyserial needed for import serial or at least I have not had any luck finding documentation)
I also looked into arduino documentation for interfacing with software but it seems that all the languages mentioned are server side. If you know of any possible direction languages that could help, I'd be happy to know and go learn them. I saw many forums mentioning Node.js but my understanding is that would also only do the job on the server side.
I'd appreciate any help on where else/other topics I should look into. Thanks in advance.
Is this even doable? I have researched a lot and it seems that this is not doable due to security reasons?
You are correct. There is no ability for browsers to access a COM port. It doesn't matter what language or framework you pick, a browser isn't going to give you that access.
You would need to make a standalone desktop application. You can use HTML and JavaScript to access serial ports, just not in a browser. Chrome Apps (which are actually going away) can do it, as well as an App that uses Electron.

real time communication between python server and a python client(not a browser)

Back in the javascript world there is a library all the socket part called socket.io
the way it works is by send and receiving the data by and events.
for example: the server can send to the client an event called "msg_received" with the message itself as the data.
in python it seems to not be as asynchronous as its in javascript. its also not working with events but only with strings which is a bit diffrent than how i use to work with the sockets.
i.e socket.send(<string>), socket.recv(<integer>)
i would love if anyone could put some light the issue to explain to me how it works in python since i've searched all over the internet and couldn't find an answer.. or point me to a similar library like the one i mentioned above.

Using PythonAnywhere as a game server

I'm building a turn-based game and I'm hoping to implement client-server style networking. I really just need to send the position of a couple of objects and some other easily encodable data. I'm pretty new to networking, although I've coded some basic stuff in socket and twisted. Now, though, I need to be able to send the data to a computer that isn't on my local network, and I can't do port forwarding since I don't have admin access to the router and I'm also not totally sure that would do the trick anyways since I've never done it. So, I was thinking of running some Flask or Bottle or Django, etc. code off PythonAnywhere. The clients would then send data to the server code on PythonAnywhere, and when the turn passed, the other client would just go look up the information it needed on the server. I guess then the server would act as just a data bank with some simple getter and setter methods. My question is how can this be implemented? Can my Socket code on my client program talk to my Flask code on PythonAnywhere?
Yes, client code can talk to your project at PythonAnywhere, as you will be given a unique project url like http://yourblogname.pythonanywhere.com/. Your server will listen the 80 port at that url.
It depends what sort of connection your clients need to make to the server. PythonAnywhere supports WSGI, which means "normal" HTTP request/response interactions -- GET, POST, etc. That works well for "traditional" web pages or web apps.
If your client side needs dynamic, two-way connections using non-HTTP protocols, using raw sockets, or even websockets, PythonAnyhwere doesn't support that at present.

How to communicate between client device and webserver?

I've build a little device based on the raspberry pi. Now I want to configure it using my web server. The idea is that I enter all the details on my django web page and then the device just pulls that off the server.
But there are two problems I'm not sure how to solve:
I have multiple devices for multiple users so some kind of Login must be provided.
The device also sends pictures from time to time. Right now it's using FTP with a general login, but I want to personalize that too for every device. The uploads will need a resume function so http is out!
So the basic question is: Should I get started with sockets or is there a better and safer way to do it? Maybe there is some kind of open source library that's been tested a lot?
Instead of hand coding sockets, I would suggest using HTTP with BASIC authentication to communicate between the device and the web server. You can uniquely assign an id/pwd to each device, and BASIC authentication is well supported by all web servers and client side libraries.
There are some security concerns with BASIC authentication even if you use HTTPS, but it maybe acceptable in your particular case here.
Maybe you could use SSH, with Fabric for instance. Here an example.

One server vs. multiple clients with data communication

I have a question on how to implement a server and multiple clients with data communication.
They share the same dataset for each step. That is, a server gets the same step's data for each client. I have no idea how to sync all clients and communicate data file for each step.
Can you give me some hints or a basic idea? An example will be perfect.
Take a loot at these
Multi-threaded multi-client server in python
Client Server programming in python?
http://ilab.cs.byu.edu/python/select/echoserver.html
If you don't want to deal with details like socket and connection handling and you like high diving, you should look into Twisted
Here's a SO answer with a simple example of a server using Twisted

Categories