not logged in | [Login]
This is little tutorial to get you started with the cc3k wlan module. You can buy one of these from sparkfun, adafruit, etc. I used this one.
The wiring depends on the SPI-bus you are using. One way to do it is like that:
import pyb import network # this inits the module, the arguments contain the wiring information wifi = network.CC3k(pyb.SPI(1), pyb.Pin('X5'), pyb.Pin('X4'), pyb.Pin('X3')) # this connects to your wifi wifi.connect('ssid', 'password')
Now that we are connected to the wifi, let's browse the web (assuming your wifi is connected to the web).
addr = socket.getaddrinfo('micropython.org', 80) s = socket.socket() s.connect(addr[-1]) s.send('GET /\r\n\r\n') r = s.recv(1024) s.close()
Let's serve something.
host = '' port = 8080 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((host, port)) sock.listen(1) # Loop forever, listening for requests: while True: try: csock, caddr = sock.accept() print('Connection from:', caddr) csock.send('Server running on the pyboard!!!\n') csock.close() except OSError: pass
Now on your computer type:
telnet ip-address 8080
ip-address should be the address of your pyboard, you can find it by asking your router.
If you are getting
OSError: Failed to init wlan module - a hard reset of the pyboard solves that.
Last edited by Sebastian Plamauer, 2014-10-30 17:50:16