pycom / pycom-micropython-sigfox

A fork of MicroPython with the ESP32 port customized to run on Pycom's IoT multi-network modules.
MIT License
196 stars 167 forks source link

How can I log any errors encountered in the MicroWebSrv server #323

Open jdcrunchman opened 4 years ago

jdcrunchman commented 4 years ago

Please include the following information when submitting a bug report:

I activated the WLAN and Hot Spot.

Set up the Access point

ap = network.WLAN(network.AP_IF) ap.ifconfig(('192.168.84.1', '255.255.255.0', '192.168.84.1', '192.168.84.1')) # ip, netmask, gateway, dns ap.active(True) ap.config(essid='aWhisper', authmode=network.AUTH_WPA_WPA2_PSK, password='')

2. Then, I did that...

I ran the original main.py code from the github then I went to my laptop, and connected to the WIFI, then I checked network connectivity by sending a test ping. The Ping worked just fine.

Then, using the browser on the Mac, and pointed it to: http://192.168.84.1/index.html The startup screen came up just fine.

But when I went to another page, I get a 405 error. Is there anyway I can trace through the server code and turn on some server logging, so I can try and debug why this doesn't work?

I'm sending the full ZIP of all the HTML, IMG, CSS files WhisperMagicMessagingUI.zip

This is my main entry code I run, right after the boot.py.

mainSetup.py - I run this right after the boot.py

import network

Setup the WLAN

wlan = network.WLAN(network.STA_IF) # create station interface wlan.active(True) # activate the interface myscan = wlan.scan() # scan for access points wlan.isconnected() # check if the station is connected to an AP

print ("WLAN Setup")

Set up the Access point

ap = network.WLAN(network.AP_IF) ap.ifconfig(('192.168.84.1', '255.255.255.0', '192.168.84.1', '192.168.84.1')) # ip, netmask, gateway, dns ap.active(True) ap.config(essid='aWhisper', authmode=network.AUTH_WPA_WPA2_PSK, password='my-password')

print ("Access point setup - IP = " + "192.168.84.1")

print ("creating an array of table values") mytable = [['john', "not listening", "36db"], ['andy', 'Online', '56db']]

print ("Now run mainweb.py to start the server") import mainweb

Then run "mainweb.py" below

from microWebSrv import MicroWebSrv from trace import bp

bp('testing', (1,2,3,5)[3], 3**5)

----------------------------------------------------------------------------

@MicroWebSrv.route('/test') def _httpHandlerTestGet(httpClient, httpResponse) : content = """\ <!DOCTYPE html>

TEST GET

TEST GET

Client IP address = %s
First name:
Last name:
""" % httpClient.GetIPAddr()
httpResponse.WriteResponseOk( headers        = None,
                              contentType    = "text/html",
                              contentCharset = "UTF-8",
                              content        = content )

@MicroWebSrv.route('/test', 'POST') def _httpHandlerTestPost(httpClient, httpResponse) : formData = httpClient.ReadRequestPostedFormData() firstname = formData["firstname"] lastname = formData["lastname"] content = """\ <!DOCTYPE html>

TEST POST

TEST POST

Firstname = %s
Lastname = %s
""" % ( MicroWebSrv.HTMLEscape(firstname),
        MicroWebSrv.HTMLEscape(lastname) )
httpResponse.WriteResponseOk( headers        = None,
                              contentType    = "text/html",
                              contentCharset = "UTF-8",
                              content        = content )

@MicroWebSrv.route('/edit/') # /edit/123 -> args['index']=123 @MicroWebSrv.route('/edit//abc/') # /edit/123/abc/bar -> args['index']=123 args['foo']='bar' @MicroWebSrv.route('/edit') # /edit -> args={} def _httpHandlerEditWithArgs(httpClient, httpResponse, args={}) : content = """\ <!DOCTYPE html>

TEST EDIT """ content += "

EDIT item with {} variable arguments

"\ .format(len(args)) if 'index' in args : content += "

index = {}

".format(args['index']) if 'foo' in args : content += "

foo = {}

".format(args['foo']) # bp('content = ', content) content += """
"""
httpResponse.WriteResponseOk( headers        = None,
                              contentType    = "text/html",
                              contentCharset = "UTF-8",
                              content        = content )

----------------------------------------------------------------------------

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")

----------------------------------------------------------------------------

routeHandlers = [

( "/test", "GET", _httpHandlerTestGet ),

( "/test", "POST", _httpHandlerTestPost )

]

srv = MicroWebSrv(webPath='/') srv.MaxWebSocketRecvLen = 256 srv.WebSocketThreaded = False srv.AcceptWebSocketCallback = _acceptWebSocketCallback srv.Start()

There are other files in this document as well, such as css, images, and such.
Am I using some feature in my HTML that is not supported on the MicroWebSrv package? All of the files are in the attached ZIP file.

Thank you!

robert-hh commented 4 years ago

Wrong board. Please refer to forum.micropython.org

jdcrunchman commented 4 years ago

Sorry, the website forum.micropythpn.org http://forum.micropythpn.org cannot be found

Can you please direct me to the proper page?

On Tue, Jul 23, 2019 at 1:15 PM robert-hh notifications@github.com wrote:

Wrong board. Please refer to forum.micropythpn.org

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pycom/pycom-micropython-sigfox/issues/323?email_source=notifications&email_token=AAX4GONTHS65SN2POZIBNADQA5RFHA5CNFSM4IGHE4VKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2UJZUI#issuecomment-514366673, or mute the thread https://github.com/notifications/unsubscribe-auth/AAX4GOOLT7BGET5ZZ34QCHLQA5RFHANCNFSM4IGHE4VA .

robert-hh commented 4 years ago

https://forum.micropython.org/ You misspelled the name, at least in your post.