Exemple #1
0
 def _init_spi(self, pos):
     if pos == 1:
         self.bus = pyb.SPI(1, pyb.SPI.MASTER, polarity=0)
         self.CSn = pyb.Pin("X5", pyb.Pin.OUT_PP, pull=pyb.Pin.PULL_UP)
     elif pos == 2:
         self.bus = pyb.SPI(2, pyb.SPI.MASTER, polarity=0)
         self.CSn = pyb.Pin("Y5", pyb.Pin.OUT_PP, pull=pyb.Pin.PULL_UP)
     self.CSn.high()
Exemple #2
0
 def power_down(self):
     if self.upcount > 1:
         self.upcount -= 1
     elif self.upcount == 1:
         self.upcount = 0
         if self.al is not None:
             self.al.high()                  # Power off
         pyb.delay(10)                       # Avoid glitches on switched
         if self.ah is not None:             # I2C bus while power decays
             self.ah.low()                   # Disable I2C pullups
     for bus in (pyb.SPI(1), pyb.SPI(2), pyb.I2C(1), pyb.I2C(2)):
         bus.deinit()                        # I2C drivers seem to need this
Exemple #3
0
    def __init__(self, spi_bus=1, led_count=1, intensity=1):
        """
        Params:
        * spi_bus = SPI bus ID (1 or 2)
        * led_count = count of LEDs
        * intensity = light intensity (float up to 1)
        """
        self.led_count = led_count
        self.intensity = intensity

        # prepare SPI data buffer (4 bytes for each color)
        self.buf_length = self.led_count * 3 * 4
        self.buf = array('B', (0 for _ in range(self.buf_length)))

        # intermediate work buffer where data is buffered in the correct order
        self.work_buf_length = self.led_count * 3
        self.work_buf = array('B', (0 for _ in range(self.work_buf_length)))

        # r, g, b relative offsets, then led -> base offset for each led
        self.buffer_map = array('H', [0, 1, 2] +
                                [i * 3 for i in range(self.led_count)])

        # SPI init
        self.spi = pyb.SPI(spi_bus,
                           pyb.SPI.MASTER,
                           baudrate=3200000,
                           polarity=0,
                           phase=0)

        # turn LEDs off
        self.show([])
Exemple #4
0
def main():
    SPI = pyb.SPI(1)
    #DIN=>X8-MOSI/CLK=>X6-SCK
    #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in)
    #CLK =>SPI(1).SCK  'X6' SPI clock
    RST = pyb.Pin('PE9')
    CE = pyb.Pin('PE8')
    DC = pyb.Pin('PE7')
    LIGHT = pyb.Pin('PE6')
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)
    # for i in range(83):
    # lcd_5110.lcd_write_draw(i,0,1)
    # for i in range(83):
    # lcd_5110.lcd_write_draw(i,5,0x80)
    # for i in range(6):
    # lcd_5110.lcd_write_draw(0,i,0xff)
    # for i in range(6):
    # lcd_5110.lcd_write_draw(83,i,0xff)
    while True:
        a = 0
        b = 32
        for i in range(8):
            lcd_5110.lcd_write_pictuer(0, 0, a, b)
            a += 32
            b += 32
            pyb.delay(150)
Exemple #5
0
  def __init__(self, pinout, height=32, external_vcc=True, i2c_devid=DEVID):
    self.external_vcc = external_vcc
    self.height       = 32 if height == 32 else 64
    self.pages        = int(self.height / 8)
    self.columns      = 128

    # Infer interface type from entries in pinout{}
    if 'dc' in pinout:
      # SPI
      rate = 16 * 1024 * 1024
      self.spi = pyb.SPI(1, pyb.SPI.MASTER, baudrate=rate, polarity=1, phase=0)  # SCK: Y6: MOSI: Y8
      self.dc  = pyb.Pin(pinout['dc'],  pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
      self.res = pyb.Pin(pinout['res'], pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
      self.offset = 0
    else:
      # Infer bus number from pin
      if pinout['sda'] == 'X10':
        self.i2c = pyb.I2C(1)
      else:
        self.i2c = pyb.I2C(2)
      self.i2c.init(pyb.I2C.MASTER, baudrate=400000) # 400kHz
      self.devid = i2c_devid
      # used to reserve an extra byte in the image buffer AND as a way to
      # infer the interface type
      self.offset = 1
      # I2C command buffer
      self.cbuffer = bytearray(2)
      self.cbuffer[0] = CTL_CMD
Exemple #6
0
 def __init__(self, spi_bus=1, led_count=1, intensity=1):
     self.led_count = led_count
     self.intensity = intensity
     self.buf_length = self.led_count * 3 * 4
     self.buf = bytearray(self.buf_length)
     self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=1)
     self.show([])
Exemple #7
0
 def __init__(self, cs_pin="P3", clk_polarity=1, clk_phase=0): # private
     self.__pin = pyb.Pin(cs_pin, pyb.Pin.IN)
     self.__polarity = clk_polarity
     self.__clk_phase = clk_phase
     self.__spi = pyb.SPI(2)
     rpc_slave.__init__(self)
     self._stream_writer_queue_depth_max = 1
    def __init__(self, spi_bus=1, led_count=1, intensity=1, pl9823=False):
        """
        Params:
        * spi_bus = SPI bus ID (1 or 2)
        * led_count = count of LEDs
        * intensity = light intensity (float up to 1)
        """
        self.led_count = led_count
        self.intensity = intensity
        self.pl9823 = pl9823

        # prepare SPI data buffer (4 bytes for each color -- 5 bytes for PL9823)
        self.buf_length = self.led_count * 5 * 3 if pl9823 else self.led_count * 4 * 3
        self.buf = bytearray(self.buf_length)

        # Reset data buffer for PL9823
        if self.pl9823:
            self.resetbuf = bytearray(PL9823_RESETBUF_SIZE)
            for num in range(len(self.resetbuf)):
                self.resetbuf[num] = 0

        # SPI init
        baudrate = 2857000 if self.pl9823 else 3200000
        self.spi = pyb.SPI(spi_bus,
                           pyb.SPI.MASTER,
                           baudrate=baudrate,
                           polarity=0,
                           phase=1)

        # turn LEDs off
        self.show([])
Exemple #9
0
    def init(self, bus):
        retry = 0

        self._cs_pin = pyb.Pin(self.chip_select, pyb.Pin.OUT_PP)
        if (ADNS3080_RESET != 0):
            self._reset_pin = pyb.Pin(ADNS3080_RESET, pyb.Pin.OUT_PP)

        self._cs_pin.high()  # disable device (Chip select is active low)

        # reset the device
        self.reset()

        # start the SPI library
        self.spi = pyb.SPI(bus,
                           pyb.SPI.MASTER,
                           baudrate=CLOCK_SPEED_USED,
                           polarity=0,
                           phase=1,
                           firstbit=pyb.SPI.MSB)

        # check the sensor is functioning
        while (retry < 3):
            function = self.read_register(ADNS3080_PRODUCT_ID)
            if (function == 0x17):
                return True
            retry += 1
        return False
Exemple #10
0
    def __init__(self, spi_bus=1, intensity=1):
        """
        Params:
        * spi_bus = SPI bus ID (1 or 2)
        * led_count = count of LEDs
        * intensity = light intensity (float up to 1)
        """

        self.color_stop = self.c_red
        self.color_headlight = self.c_white
        self.color_directional = self.c_yellow

        self.headlights = False
        self.stops = False
        self.direction_r = False
        self.direction_l = False
        self.state = 0
        self.id = 0


        self.led_count = 9
        self.intensity = intensity

        # prepare SPI data buffer (4 bytes for each color)
        self.buf_length = self.led_count * 3 * 4
        self.buf = bytearray(self.buf_length)

        # SPI init
        self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=1)

        # turn LEDs off
        #self.show([])
        self.show()
Exemple #11
0
def display(board):
    spi = pyb.SPI(sys_config['oled']['spi_bus'], pyb.SPI.MASTER,
                  baudrate=80000000, polarity=1, phase=0)
    reset = pyb.Pin(sys_config['oled']['reset'], pyb.Pin.OUT)
    rs = pyb.Pin(sys_config['oled']['rs'], pyb.Pin.OUT)
    cs = pyb.Pin(sys_config['oled']['spi_cs'], pyb.Pin.OUT)
    disp = LimiFrogDisplay(board, spi, cs=cs, rs=rs, reset=reset)
    return disp
Exemple #12
0
 def __init__(self, cs_pin="P3", freq=1000000, clk_polarity=1, clk_phase=0): # private
     self.__pin = pyb.Pin(cs_pin, pyb.Pin.OUT_PP)
     self.__freq = freq
     self.__polarity = clk_polarity
     self.__clk_phase = clk_phase
     self.__spi = pyb.SPI(2)
     rpc_master.__init__(self)
     self._stream_writer_queue_depth_max = 1
def SPIDbg(ndx):
    #p_sclk = machine.Pin.board.J9_9
    #p_mosi = machine.Pin.board.J9_13
    #s = pyb.SPI(ndx, pyb.SPI.MASTER, baudrate=876000, phase=1, polarity=1, bits=12, firstbit=1)
    s = pyb.SPI(ndx, pyb.SPI.MASTER)
    tx = 'I love you!'
    rx = bytearray(4)
    rx2 = bytearray(len(tx))
    s.send_recv(send=tx, recv=rx, halfduplex=1)
    s.send_recv(send=tx, recv=rx2)

    return s
Exemple #14
0
 def __init__(self, master, config):
     super().__init__(pyb.SPI(config.spi_no), pyb.Pin(config.csn_pin), pyb.Pin(config.ce_pin), config.channel, config.payload_size)
     if master:
         self.open_tx_pipe(TwoWayRadio.pipes[0])
         self.open_rx_pipe(1, TwoWayRadio.pipes[1])
     else:
         self.open_tx_pipe(TwoWayRadio.pipes[1])
         self.open_rx_pipe(1, TwoWayRadio.pipes[0])
     self.set_power_speed(POWER_3, SPEED_250K) # Best range for point to point links
     self.start_listening()
     self.txmsg = TxMessage()                # Data for transmission
     self.inlist = []                        # List of received bytes objects
def sdtest():
    sd = sdcard.SDCard(pyb.SPI(1), pyb.Pin.board.X21)  # Compatible with PCB
    pyb.mount(sd, '/fc')
    print('Filesystem check')
    print(os.listdir('/fc'))

    line = 'abcdefghijklmnopqrstuvwxyz\n'
    lines = line * 200  # 5400 chars
    short = '1234567890\n'

    fn = '/fc/rats.txt'
    print()
    print('Multiple block read/write')
    with open(fn, 'w') as f:
        n = f.write(lines)
        print(n, 'bytes written')
        n = f.write(short)
        print(n, 'bytes written')
        n = f.write(lines)
        print(n, 'bytes written')

    with open(fn, 'r') as f:
        result1 = f.read()
        print(len(result1), 'bytes read')

    fn = '/fc/rats1.txt'
    print()
    print('Single block read/write')
    with open(fn, 'w') as f:
        n = f.write(short)  # one block
        print(n, 'bytes written')

    with open(fn, 'r') as f:
        result2 = f.read()
        print(len(result2), 'bytes read')

    pyb.mount(None, '/fc')

    print()
    print('Verifying data read back')
    success = True
    if result1 == ''.join((lines, short, lines)):
        print('Large file Pass')
    else:
        print('Large file Fail')
        success = False
    if result2 == short:
        print('Small file Pass')
    else:
        print('Small file Fail')
        success = False
    print()
    print('Tests', 'passed' if success else 'failed')
Exemple #16
0
 def __init__(self, bus, baudrate=328125):
     self.spi_bus = pyb.SPI(bus,
                            pyb.SPI.MASTER,
                            bits=8,
                            firstbit=pyb.SPI.MSB,
                            crc=None)
     if bus == 1:
         self.CS_pin = pyb.Pin('X5')
     else:
         self.CS_pin = pyb.Pin('Y5')
     self.CS_pin.init(pyb.Pin.OUT_PP)
     self.buffer = bytearray(2)
 def __init__(self, master, config):
     super().__init__(pyb.SPI(config.spi_no), pyb.Pin(config.csn_pin),
                      pyb.Pin(config.ce_pin), config.channel,
                      FromMaster.payload_size())
     if master:
         self.open_tx_pipe(RadioFast.pipes[0])
         self.open_rx_pipe(1, RadioFast.pipes[1])
     else:
         self.open_tx_pipe(RadioFast.pipes[1])
         self.open_rx_pipe(1, RadioFast.pipes[0])
     self.set_power_speed(POWER_3,
                          SPEED_250K)  # Best range for point to point links
     self.start_listening()
Exemple #18
0
def ini():
    import pyb
    import time
    import network
    cc3k = network.CC3K(pyb.SPI(2), pyb.Pin('Y5'), pyb.Pin('Y4'),
                        pyb.Pin('Y3'))
    cc3k.connect('42', '***')  #WLAN: (Ap , Password)

    while (cc3k.isconnected() == 0):
        time.sleep(0.5)

    print("network:", cc3k.isconnected())
    print(cc3k.ifconfig())
Exemple #19
0
def init_oled():
    # init oled
    import seps525
    spi1 = pyb.SPI(1, pyb.SPI.MASTER, baudrate=30000000)
    oled_rs = machine.Pin('PC4', pyb.Pin.OUT_PP)
    oled_cs = machine.Pin('PC5', pyb.Pin.OUT_PP)
    oled_nrst = machine.Pin('PB1', pyb.Pin.OUT_PP)
    oled_nrst.low()
    oled_rs.high()
    oled_cs.high()
    oled_nrst.high()

    display = seps525.SEPS525(160, 128, spi1, oled_cs, oled_rs)
    return display
Exemple #20
0
 def __init__( self, aLoc, aDC, aReset ) :
   '''aLoc SPI pin location is either 1 for 'X' or 2 for 'Y'.
      aDC is the DC pin and aReset is the reset pin.'''
   self._size = tft._SCREENSIZE
   self.rotate = 0                    #Vertical with top toward pins.
   self._rgb = True                   #color order of rgb.
   self.dc  = pyb.Pin(aDC, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
   self.reset = pyb.Pin(aReset, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
   rate = 200000 #100000000 #Set way high but will be clamped to a maximum in SPI constructor.
   cs = "X5" if aLoc == 1 else "Y5"
   self.cs = pyb.Pin(cs, pyb.Pin.OUT_PP, pyb.Pin.PULL_DOWN)
   self.cs.high()
   self.spi = pyb.SPI(aLoc, pyb.SPI.MASTER, baudrate = rate, polarity = 1, phase = 0, crc=None)
   self.colorData = bytearray(2)
   self.windowLocData = bytearray(4)
Exemple #21
0
def main():
    SPI = pyb.SPI(1)  #DIN=>X8-MOSI/CLK=>X6-SCK
    #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in)
    #CLK =>SPI(1).SCK  'X6' SPI clock

    RST = pyb.Pin('X1')
    CE = pyb.Pin('X2')
    DC = pyb.Pin('X3')
    LIGHT = pyb.Pin('X4')
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)

    lcd_5110.lcd_write_string('Hello EveryOne', 0, 0)
    lcd_5110.lcd_write_string('It', 6, 1)
    lcd_5110.lcd_write_string('Is', 12, 2)
    lcd_5110.lcd_write_string('Turnip', 60, 3)
    lcd_5110.lcd_write_string('Smart', 0, 4)
Exemple #22
0
def main():
    SPI = pyb.SPI(1)  #DIN=>X8-MOSI/CLK=>X6-SCK
    #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in)
    #CLK =>SPI(1).SCK  'X6' SPI clock

    RST = pyb.Pin('Y10')
    CE = pyb.Pin('Y11')
    DC = pyb.Pin('Y9')
    LIGHT = pyb.Pin('Y12')
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)

    lcd_5110.lcd_write_string('Hello Python!', 0, 0)
    lcd_5110.lcd_write_string('Micropython', 6, 1)
    lcd_5110.lcd_write_string('TPYBoard', 12, 2)
    lcd_5110.lcd_write_string('v102', 60, 3)
    lcd_5110.lcd_write_string('This is a test of LCD5110', 0, 4)
Exemple #23
0
    def __init__(self):
        self.cs = Pin('X5', Pin.OUT_PP)
        self.cs.value(True)  # Active low

        if 0:
            pd = Pin('X11', Pin.OUT_PP)
            pd.value(False)
            pd.value(True)

        self.sp = pyb.SPI(1,
                          pyb.SPI.MASTER,
                          baudrate=15000000,
                          polarity=0,
                          phase=0,
                          bits=8,
                          firstbit=pyb.SPI.MSB)
Exemple #24
0
def main():
    SPI = pyb.SPI(1)
    RC522_SDA = 'X4'
    RC522_RST = 'X2'
    rc52 = rc522.MFRC522()
    rc52.init_spi(SPI, RC522_RST, RC522_SDA)
    while True:
        (status, backBits) = rc52.SeekCard(0x52)
        if (status == 0):
            (
                status,
                id,
            ) = rc52.Anticoll()
            print("card_id=", id)
        else:
            print("NO_CARD")
        pyb.delay(1000)
Exemple #25
0
    def __init__(self, spi_bus=1, led_count=1, intensity=1, mem=PREALLOCATE):
        #Params:
        # spi_bus = SPI bus ID (1 or 2)
        # led_count = count of LEDs
        # intensity = light intensity (float up to 1)
        # mem = how stingy to be with memory (comes at a speed & GC cost)
        self.led_count = led_count
        self.intensity = intensity  # FIXME: intensity is ignored
        self.mem = mem
        # 0 prealloc
        # 1 cache
        # 2 create Pixel each time

        # prepare SPI data buffer (4 bytes for each color for each pixel,
        # with an additional zero byte at the end to make sure the data line
        # comes to rest low)
        self.buf = bytearray(4 * 3 * led_count + 1)

        if mem <= CACHE:
            # Prepare a cache by index of Pixel objects
            self.pixels = pixels = [None] * led_count
            if mem == PREALLOCATE:  # Pre-allocate the pixels
                for i in range(led_count):
                    pixels[i] = Pixel(self.buf, 3 * i)

        # OBSOLETE
        #self.bits = array('L', range(256))
        #bb = bytearray_at(addressof(self.bits), 4*256)
        #mask = 0x03
        #buf_bytes = self.buf_bytes
        #for i in range(256):
        #    index = 4*i
        #    bb[index] = buf_bytes[i >> 6 & 0x03]
        #    bb[index+1] = buf_bytes[i >> 4 & 0x03]
        #    bb[index+2] = buf_bytes[i >> 2 & 0x03]
        #    bb[index+3] = buf_bytes[i & 0x03]

        # SPI init
        self.spi = pyb.SPI(spi_bus,
                           pyb.SPI.MASTER,
                           baudrate=3200000,
                           polarity=0,
                           phase=1)

        # turn LEDs off
        self.show([])
Exemple #26
0
def main():
    SPI = pyb.SPI(1)
    #DIN=>X8-MOSI/CLK=>X6-SCK
    #DIN =>SPI(1).MOSI 'X8' data flow (Master out, Slave in)
    #CLK =>SPI(1).SCK  'X6' SPI clock
    RST = pyb.Pin('Y10')
    CE = pyb.Pin('Y11')
    DC = pyb.Pin('Y9')
    LIGHT = pyb.Pin('Y12')
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)
    lcd_5110 = upcd8544.PCD8544(SPI, RST, CE, DC, LIGHT)

    lcd_5110.lcd_write_draw_x(0, 0, 20, 50)
    lcd_5110.lcd_write_draw_x(40, 0, 36, 10)
    lcd_5110.lcd_write_draw_x(20, 0, 36, 60)
    lcd_5110.lcd_write_draw_x(30, 10, 0, 80)
    lcd_5110.lcd_read_hc()
def test_connect():
    nic = network.CC3K(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4,
                       pyb.Pin.board.Y3)
    nic.connect('YOUR_ROUTER_HERE', 'YOUR_ROUTER_PASSWORD_HERE')
    while not nic.isconnected():
        pyb.delay(50)
    print(nic.ifconfig())

    # now use usocket as usual
    import usocket as socket
    addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
    s = socket.socket()
    s.connect(addr)
    s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n')
    data = s.recv(1000)
    print(data)
    s.close()
Exemple #28
0
    def __init__(self, spi_bus=1, led_count=1, intensity=1):
        """
        Params:
        * spi_bus = SPI bus ID (1 or 2)
        * led_count = count of LEDs
        * intensity = light intensity (float up to 1)
        """
        self.led_count = led_count
        self.intensity = intensity

        # prepare SPI data buffer (4 bytes for each color)
        self.buf_length = self.led_count * 3 * 4
        self.buf = bytearray(self.buf_length)

        # SPI init
        self.spi = pyb.SPI(spi_bus, pyb.SPI.MASTER, baudrate=3200000, polarity=0, phase=0)

        # turn LEDs off
        self.show([])
Exemple #29
0
def init():
	global pinCMD
	global pinRST
	global pinVPP
	global spi
	global fb
	fb = bytearray(128*16)
	spi = pyb.SPI(9, pyb.SPI.MASTER, baudrate=4000000)
	pinCMD = pyb.Pin('21', pyb.Pin.OUT, value=True)
	pinRST = pyb.Pin('122', pyb.Pin.OUT, value=True)
	pinVPP = pyb.Pin('11', pyb.Pin.OUT, value=True)
	lstInitSeq = [	
	0xae,		#	Display OFF
	0xd5,		#	Set D-clock
	0x50,		#	100Hz
	0x20,		#	Set row address
	0x81,		#	Set contrast control
	0xc0,
	0xa0,		#	Segment remap
	0xa4,		#	Set Entire Display ON
	0xa6,		#	Normal display
	0xad,		#	Set external VPP
	0x80,
	0xc0,		#	Set Common scan direction
	0xd9,		#	Set phase length
	0x25,
	0xdb,		#	Set Vcomh voltage
	0x28,		#	0.687*VPP
	]

	io_vpp(True)				#	power panel
	io_reset(True)				#	start reset
	pyb.delay(2)						#	20uS delay
	io_reset(False)			#	release reset
	pyb.delay(100)						#	wait for SH1107 to come out of reset

	initLen = len(lstInitSeq)
	for i in range(initLen):
		WriteCmd(lstInitSeq[i])
	cls()							#	clear oled
	WriteCmd(0xaf)						#	enable OLED	
Exemple #30
0
def main():
    import network, pyb
    nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.A3, pyb.Pin.board.A4)
    while not nic.isconnected():
        pass
    nic.active(1)
    nic.ifconfig(
        ('192.168.178.135', '255.255.255.0', '192.168.178.1', '192.168.178.1'))
    ip_address_v4 = nic.ifconfig()[0]

    s = socket.socket()
    ai = socket.getaddrinfo(ip_address_v4, 80)
    print("Bind address info:", ai)
    addr = ai[0][-1]
    print("IP Address: ", addr)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.bind(addr)
    s.listen(5)
    print("Listening, connect your browser to http://<this_host>:80/")

    counter = 0
    while True:
        sock, addr = s.accept()
        #s.setblocking(False)
        print("Client address:", addr)
        stream = sock.makefile("rwb")
        req = stream.readline().decode("ascii")
        method, path, protocol = req.split(" ")
        print("Got", method, "request for", path)
        while True:
            h = stream.readline().decode("ascii").strip()
            if h == "":
                break
            print("Got HTTP header:", h)
        stream.write((CONTENT % counter).encode("ascii"))
        stream.close()
        sock.close()
        counter += 1
        print()