Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

micropython nodemcu webpage problem

Status
Not open for further replies.

yefj

Advanced Member level 5
Advanced Member level 5
Joined
Sep 12, 2019
Messages
1,505
Helped
1
Reputation
2
Reaction score
5
Trophy points
38
Activity points
9,113
Hello,i have used micropython to create wifi accsses point as shown bellow.It works.
I lack the definition of the web page design.
My goal is to connect the network shown bellow,then enter an IP address into the webpage and see a variable printed on the web page.
I tried to use this manual but its too complicated i entered the code ,and its not connecting to the web page ,although i connected to the WIFI network.
I need a command for defining IP and a command for printing variables on the webpage.
Is there some one who can reccomnd me a source?
Thanks.

Code:
ap_if = network.WLAN(network.AP_IF)
ssid = 'MicroPython-AP23'
password = '123456789'
ap_if.active(True)
ap_if.config(essid=ssid, password=password)
 

I want to see a web page from my created wifi network,
i have managed to asemmble the following code shown bellow,with socket as shown bellow
i enter the wifi network,then i write the IP adrress( i tried them both) and nothing.

i have done exactly as in the manual shown bellow, i cant get any webpage
Where did i go wrong?

Code:
import network
import usocket as socket
ap_if = network.WLAN(network.AP_IF)
ssid = 'MicroPython-AP29'
password = '123456789'
ap_if.active(True)
ap_if.config(essid=ssid, password=password)

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('',80))
s.listen(5)
while True:
    conn, addre=s.accept()
    request=conn.recv(1024)
    request=str(request)
    response="gyhkjgku"
    conn.send("HTTP/1.1 200 OK\n")
    conn.send("Content-type: text/html\n")
    conn.send("Connection: close\n\n")
    conn.sendall(response)
    conn.close()
 

I'm not an expert in Python by a long way but if you only send a HTTP header you won't see anything in a web browser. It needs some content as well.
Try adding:
conn.send(" This is a test<br> ")
before the 'Connection:close' line.

Brian.
 

Hello Brian i have added this line,then i tried again and succsesfully connected to a a wifi network on my iphone.it connected sucsesfully.IP 192.168.4.4,mask 255.255.255.0 router 192.168.4.1 .I have entered those adresses to my explorer and nothing,it says there is no such web page.

Code:
import network
import usocket as socket
ap_if = network.WLAN(network.AP_IF)
ssid = 'MicroPython-AP29'
password = '123456789'
ap_if.active(True)
ap_if.config(essid=ssid, password=password)

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('',80))
s.listen(5)
while True:
    conn, addre=s.accept()
    request=conn.recv(1024)
    request=str(request)
    response="gyhkjgku"
    conn.send("HTTP/1.1 200 OK\n")
    conn.send("Content-type: text/html\n")
    conn.send("Connection: close\n\n")
    conn.sendall(response)
    conn.send(" This is a test<br> ")
    conn.close()
 

Hello Brian,the error was the i wrote " instead of '.
It works great as you can see.writing HTML script not working
is there conn command to increase font?
Thanks.
1608306558614.png


Code:
import network
import usocket as socket
ap_if = network.WLAN(network.AP_IF)
ssid = 'MicroPython-AP29'
password = '123456789'
ap_if.active(True)
ap_if.config(essid=ssid, password=password)

s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind(('',80))
s.listen(5)
while True:
    conn, addre=s.accept()
    request=conn.recv(1024)
    request='The temperature is:'
    request2=str(12.7)
    response='gyhkjgku'
    conn.send('HTTP/1.1 200 OK\n')
    conn.send('Content-type: text/html\n')
    conn.send('Connection: close\n\n')
    conn.sendall(request)
    conn.sendall(request2)
    conn.close()
 

Not a 'conn' command but you can add any valid HTML command to the web page.
Try changing:
request='The temperature is:'
to:
request='<h1>The temperature is:'

Brian.
 
  • Like
Reactions: yefj

    yefj

    Points: 2
    Helpful Answer Positive Rating
Yes,works like a charm.Thank you very much.

Code:
import network

import usocket as socket

ap_if = network.WLAN(network.AP_IF)

ssid = 'MicroPython-AP29'

password = '123456789'

ap_if.active(True)

ap_if.config(essid=ssid, password=password)



s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)

s.bind(('',80))

s.listen(5)

while True:

    conn, addre=s.accept()

    request=conn.recv(1024)

    request='<p style="color:red"><u><h1>The temperature is:</u></p>'

    request2=str(12.7)

    response='gyhkjgku'

    conn.send('HTTP/1.1 200 OK\n')

    conn.send('Content-type: text/html\n')

    conn.send('Connection: close\n\n')

    conn.sendall(request)

    conn.sendall(request2)

    conn.close()
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top