项目作者: labgua

项目描述 :
This is a simple abstraction of remote control for GPIO RPI
高级语言: Python
项目地址: git://github.com/labgua/RPIModel.git
创建时间: 2017-12-24T12:00:24Z
项目社区:https://github.com/labgua/RPIModel

开源协议:GNU General Public License v3.0

下载


RPIModel

Introduction

This is a simple abstraction of remote control for GPIO RPI.
There is a WebSocket Server that runs on the RPI accessible from any client that support the WebSocket standard known by many modern technologies

The architecture is centralized in the RPI; it receives all messages from the client, updates own status and tells to the remaining connected nodes the new state updated.

RPIModel implements a transmission protocol message-based, where there are two kind of message, setup and update : the setup message are used to set a mode pin and the update message are used to update the status of a pin.

For example this is a setup message that sets the pin 12 as OUTPUT

  1. {
  2. 'pin' : 12,
  3. 'mode' : 'OUTPUT'
  4. }

And the next message is used as update message :

  1. {
  2. 'pin' : 12,
  3. 'mode' : 'OUTPUT',
  4. 'value' : 'ON'
  5. }

Architecture

Server

The server architecture is implemented with Tornado Web Server, a python implementation of networking library that works on RaspberryPI.
The server class ‘RPIWebSocket’ extends a ‘WebSocketHandler’ that use the wrapper-model ‘RPIModel’ class.
This is an important class that save the state of the ports which is not normally stored by the RPi.GPIO library.

To start the server run the folowing command :

  1. $ sudo python ws_server.py

If there aren’t problem you can see the message ‘WEBSOCKET RPI!!’.
The server is running on ip of the RaspberryPi on the port 8888.

Assuming that the ip of the RPi is 1.2.3.4, now you can go on the 1.2.3.4:8888/static with a browser to use the javascript-client and interact with the RPI.

Client

At the moment the client is a browser, but can be any other node that support the WebSocket protocol.
The browser (desktop or mobile) uses the javascript class ‘WebSocket’, a client appropriately instantiated via the user-interface.

Once you have visited the page 1.2.3.4:8888/static :

  • insert the address of the websocket server
  • click on the ‘connetti’ button
  • send an update message, selecting the pin and the mode
  • if the pin is an digital output, you can click on the pin to toggle the state
  • else is the pin is an digital input, the color of the input change with the signal variation on it