Hello,
Just if you want a Micro HTTP Web Server and language templating for MicroPython (used on Pycom modules) :
https://github.com/jczic/MicroWebSrv
A Micro HTTP Web Server and language templating for MicroPython
Re: A Micro HTTP Web Server and language templating for MicroPython
Thanks for the information.
I have included it with minor modifications into my MicroPython port as a frozen module and it works very well.
Are you planning to implement WebSockets protocol and posted multipart data mentioned in "issues" ?
I have included it with minor modifications into my MicroPython port as a frozen module and it works very well.
Are you planning to implement WebSockets protocol and posted multipart data mentioned in "issues" ?
Re: A Micro HTTP Web Server and language templating for MicroPython
Your library looks great! Is it compatible with an ESP32? Have you tried implementing websockets?jczic wrote:Hello,
Just if you want a Micro HTTP Web Server and language templating for MicroPython (used on Pycom modules) :
https://github.com/jczic/MicroWebSrv
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: A Micro HTTP Web Server and language templating for MicroPython
@jczic
I am trying to get websockets to work on my ESP32 using your library.
I have tried all your examples and they work fine on the firmware I am using (laboris port)
This is the code that I tried to start the webserver and send websocket messages, I also have a htlm file in the flash/www/ directory that is for receiving the websockets message and display it on the screen.
I get the following error
I am trying to get websockets to work on my ESP32 using your library.
I have tried all your examples and they work fine on the firmware I am using (laboris port)
This is the code that I tried to start the webserver and send websocket messages, I also have a htlm file in the flash/www/ directory that is for receiving the websockets message and display it on the screen.
I get the following error
with this codeAttributeError: 'MicroWebSrv' object has no attribute 'SendText'
Code: Select all
from microWebSrv import MicroWebSrv
import time
def _acceptWebSocketCallback(webSocket, httpClient) :
print("WS ACCEPT")
webSocket.RecvTextCallback = _recvTextCallback
webSocket.RecvBinaryCallback = _recvBinaryCallback
webSocket.ClosedCallback = _closedCallback
def _recvTextCallback(webSocket, msg) :
print("WS RECV TEXT : %s" % msg)
webSocket.SendText("Reply for %s" % msg)
def _recvBinaryCallback(webSocket, data) :
print("WS RECV DATA : %s" % data)
def _closedCallback(webSocket) :
print("WS CLOSED")
mws = MicroWebSrv() # TCP port 80 and files in /flash/www
mws.MaxWebSocketRecvLen = 256 # Default is set to 1024
mws.WebSocketThreaded = False # WebSockets without new threads
mws.AcceptWebSocketCallback = _acceptWebSocketCallback# Function to receive WebSockets
mws.Start()
t=0
while True:
print(t)
mws.SendText(str(t))
time.sleep(1)
t+=1
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: A Micro HTTP Web Server and language templating for MicroPython
Ok I found the wstest.html and am playing with it now and it works.
I think that I maybe better understanding how it work. The server can only send a message in response the the client sending a message first???
I want to graph live data from my robot and new data will be available from a timer event on the ESP32 every 100ms so I assume then I have to have java script client side that sends a message every 100ms for the esp32 to respond with new data to???
edit
ok I seem to have worked it out by using setInterval(myFunction, 100); and am now successfully sending the needed data every 100ms.
Now to find some open source javascript for plotting the data
I think that I maybe better understanding how it work. The server can only send a message in response the the client sending a message first???
I want to graph live data from my robot and new data will be available from a timer event on the ESP32 every 100ms so I assume then I have to have java script client side that sends a message every 100ms for the esp32 to respond with new data to???
edit
ok I seem to have worked it out by using setInterval(myFunction, 100); and am now successfully sending the needed data every 100ms.
Now to find some open source javascript for plotting the data
-
- Posts: 847
- Joined: Mon Nov 20, 2017 10:18 am
Re: A Micro HTTP Web Server and language templating for MicroPython
Ok I am getting further but need a little advice.
So I think it works like this. The client needs to establish the websocket but once this is done the the client doesn't need to request a message the server can push out messages.
For the server to push out the message it needs a pointer to the websocket. The only way that I seem to be able to get a pointer to the websocket is have the client send a message first then make a global variable point to the websocket.
Once the client executes this javascript websocket = new WebSocket(wsUri); the webscoket is made, is there a way at the server side to detect this and get a pointer to it??
here is the round about way I made it work but it far from pretty coding
So I think it works like this. The client needs to establish the websocket but once this is done the the client doesn't need to request a message the server can push out messages.
For the server to push out the message it needs a pointer to the websocket. The only way that I seem to be able to get a pointer to the websocket is have the client send a message first then make a global variable point to the websocket.
Once the client executes this javascript websocket = new WebSocket(wsUri); the webscoket is made, is there a way at the server side to detect this and get a pointer to it??
here is the round about way I made it work but it far from pretty coding
Code: Select all
from microWebSrv import MicroWebSrv
import utime
wsflag = False
def _acceptWebSocketCallback(webSocket, httpClient) :
print("WS ACCEPT")
webSocket.RecvTextCallback = _recvTextCallback
webSocket.RecvBinaryCallback = _recvBinaryCallback
webSocket.ClosedCallback = _closedCallback
def _recvTextCallback(webSocket, msg) :
print("WS RECV TEXT : %s" % msg)
webSocket.SendText("Reply for %s" % msg+ str(t))
global wsflag
global ws
ws = webSocket
wsflag = True
def _recvBinaryCallback(webSocket, data) :
print("WS RECV DATA : %s" % data)
def _closedCallback(webSocket) :
print("WS CLOSED")
mws = MicroWebSrv() # TCP port 80 and files in /flash/www
mws.MaxWebSocketRecvLen = 256 # Default is set to 1024
mws.WebSocketThreaded = False # WebSockets without new threads
mws.AcceptWebSocketCallback = _acceptWebSocketCallback# Function to receive WebSockets
mws.Start()
t=0
while not wsflag : pass
while True:
print(t)
if not ws.IsClosed() : ws.SendText(str(t))
utime.sleep_ms(100)
t+=1