Skip to content

QuecPython/websocket-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QuecPython WebSocket Server

A simple WebSocket server implementation for QuecPython modules, with optional client example and browser testing instructions.

Features

  • WebSocket server for QuecPython devices
  • Echoes received messages back to the client
  • Supports multiple clients using threads
  • Example WebSocket client (for internal testing)
  • Sample HTML for browser-based testing

Getting Started

Prerequisites

Installation

  1. Upload all project files to your module:

    • _main.py
    • ws_server.py
    • websocket_handshake.py
  2. Run _main.py script.

Usage

  1. Power on your module and run _main.py or change the name to main.py so the program will run automatically.
  2. The server will start on port 8080 by default, but you can set the port you want to be used.
  3. To stop the server, type q in the module’s serial console and press Enter.

Testing with a Browser

You can test the server using a browser. Save the following HTML as test.html and open it in your browser:

<!DOCTYPE html>
<html>
  <body>
    <h2>WebSocket Test</h2>
    <script>
      const ws = new WebSocket("ws://<MODULE_IP>:<PORT>");
      ws.onopen = () => {
        console.log("Connected");
        ws.send("Hello from browser!");
      };
      ws.onmessage = e => {
        console.log("Received:", e.data);
        alert("Received: " + e.data);
      };
      ws.onerror = e => {
        console.error("WebSocket error:", e);
      };
      ws.onclose = () => {
        console.log("WebSocket closed");
      };
    </script>
  </body>
</html>

Replace <MODULE_IP> with your module's IP address and <PORT> with the port number you will use.

Internal Client Example

You can also use the built-in WebSocket client for internal testing. Uncomment the client section in _main.py to enable it. More on QuecPython websocket client here: https://developer.quectel.com/doc/quecpython/API_reference/en/networklib/uwebsocket.html

File Overview

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

websocket server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages