Created
September 30, 2017 13:20
-
-
Save SwitchScienceCode/3b78145abeaa83cb0b103319307fc3b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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