Skip to content

Instantly share code, notes, and snippets.

@SwitchScienceCode
Created September 30, 2017 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SwitchScienceCode/3b78145abeaa83cb0b103319307fc3b2 to your computer and use it in GitHub Desktop.
Save SwitchScienceCode/3b78145abeaa83cb0b103319307fc3b2 to your computer and use it in GitHub Desktop.
import pyb
import network
import machine
import usocket
import utime
spi = pyb.SPI(1)
cs = machine.Pin(pyb.Pin.board.X5, machine.Pin.OUT)
def setMacAddress(address):
cs.low()
# address of the register of the mac address
spi.send(0x00)
spi.send(0x09)
# write action
spi.send(0x80)
# 6 byte of datasize
spi.send(0x06)
# mac address
for add in address:
spi.send(add)
# not sure if this needed
utime.sleep(1)
cs.high()
# init network driver
nic = network.WIZNET5K(spi, pyb.Pin.board.X5, pyb.Pin.board.X4)
nic.ifconfig(('192.168.0.10', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
print(nic.ifconfig())
# set mac address
setMacAddress([0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
print(nic.regs())
html = """<!DOCTYPE html>
<html>
<head><title>pyboard Accelerometer</title></head>
<body><p>X:%d Y:%d Z:%d</p></body>
</html>
"""
s = usocket.socket()
s.bind(('0.0.0.0', 80))
s.listen(1)
accel = pyb.Accel()
led1 = pyb.LED(1)
while True:
cl, addr = s.accept()
print('connected')
led1.on()
response = html % (accel.x(), accel.y(), accel.z())
cl.send(html)
cl.close()
led1.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment