Skip to content

Youssefbenhammouda/BenCommunication-Micropython-Server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BenCommunication-Micropython-Server

A python library that runs on the server side to communicate with BenCommunication-Micropython-client.

The BenCommunication project uses UDP protocol to communicate with the BenCommunication-Micropython-client, it can assure a secure communication between Micropython and Python scripts over the network. BenCommunication use AES CBC algorithm to encrypt the traffic with a key file that must be kept in a secure place.

The library will:

  • Generate a random iv for each request and send it along with the payload.
  • Generate a unique ID for each request.

Installation

Download benserver.py and save it on the main directory of project. Download requirements.txt and run :

pip install -r requirements.txt

Setup

Generate a keyfile using:

from benserver import generate_new_secret
generate_new_secret("key.sec")

Object arguments

benserver.server() can have the following arguments:

  1. localip (str) => The IP the server is going to listen to, use "0.0.0.0".
  2. port (int) => The port used by server.
  3. keyfile (str) => (default=key.sec) the keyfile, it contains 32 random bytes. See Setup
  4. timeout (int) => (default=10) How much time to wait for response from server.
  5. buffersize (int) => (default=4096) The buffer for Udp Socket.

Usage

You can add functions to handle actions sent by client with:

from benserver import server
udpserver = server("0.0.0.0",8585)
def echo(text):
	return  text
udpserver.add_action_handler("echo", echo) # When user send {"action":"echo","data":...}, it will return same data.
udpserver.start() # Start listening for infinite time.

Example receive data from sensor every 1 minute

See Example to send data from sensor every 1 minute

Last tested with MicroPython v1.19.1 on 2022-06-18; ESP module with ESP8266.

If you have any suggestions, feel free to fork and send a pull request. Thanks for reading :D

About

A python library that acts as a server to communicate with Micropython.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages