eypiem / IoT-Robot-Server

Flask server for an IoT robot project.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IoT-Robot-Server

The goal of this project was to create an online platform in which users can find and connect to their robots from anywhere. The user can monitor the status, sensors data, and also send live commands to their robots.

The server uses Flask and operates on a Linux system. It employs WebSocket and TCP connections to establish a live, two-way stream of data between the web browser and the robot.

Deployment

Firstly, create a virtual environment and install the required packages:

python3 -m venv my_venv
source my_venv/bin/activate
pip install -r requirements.txt

Then, run the server:

export FLASK_ENV=development
flask run

Configuration

In app.py:

You can change the TCP server and WebSocket server ports:

class TCPServerThread(threading.Thread):
    PORT = 7070
class WebsocketsThread(threading.Thread):
    PORT = 7071

Communication format

The server and the robot communicate with each other using JSON commands. You can create new commands by assigning a new type and adding your required parameters. (Note that new commands should also be added in the robot side.)

Existing command types:

self_info:

From the robot to the server. To declare the availability of the robot.

{
    type: "self_info"
    data: {
        name: "Robot X",
        id: "1as6df"
    }
}

robots:

From the browser to the server. To get a list of available robots.

{
    type: "robots"
    data: {
        robots: [
            {
                name: "Robot X",
                id: "1as6df"
            },
            ...
        ]
    }
}

conn_req:

From the browser to the server. To start a connection.

{
    type: "conn_req"
    data: {
        id: "1as6df"
    }
}

disconn_req:

From the browser to the server. To end a connection.

{
    type: "disconn_req"
    data: {
        id: "1as6df"
    }
}

msg:

Between the browser and the robot. To send a text message.

{
    type: "msg"
    data: {
        data: "Hello world."
    }
}

com_led:

From the browser to the robot. To change the LED status.

{
    type: "com_led"
    data: {
        state: True
    }
}

com_buzzer:

From the browser to the robot. To change the buzzer status.

{
    type: "com_buzzer"
    data: {
        state: False
    }
}

com_motor:

From the browser to the robot. To control the motors.

{
    "type": "com_motor"
    "data": {
        "m1": {
            "dir": "CW",
            "spd": 20
        }
    }
}

orientation_data:

From the robot to the browser. To send accelerometer data.

{
    "type": "orientation_data"
    "data": {
        "pitch": 45,
        "roll": 60,
    }
}

climate_data:

From the robot to the browser. To send climate sensor data.

{
    "type": "climate_data"
    "data": {
        "temperature": 27,
        "pressure": 86000,
    }
}

Possible improvements

  • Add authetication before connecting to robot.
  • Add voice and video transmition capability.
  • Estabilish direct connection from robot to browser for reduced latancy and server load (ex. WebRTC).

Authors

License

MIT

About

Flask server for an IoT robot project.


Languages

Language:JavaScript 46.2%Language:Python 30.6%Language:HTML 11.9%Language:CSS 11.3%