import asyncio
import json
import logging
import os.path
import socket
import struct
import threading
import time

import aiocoap.resource as resource
import aiocoap
from persistent_queue import PersistentQueue
import yaml

from sensors import setup_air_quality, setup_temp_sensor


LOGGER = logging.getLogger("mqtt_sensor")
CHUNK_SIZE = 20


class DataResource(resource.Resource):
    """
    Example resource which supports GET and PUT methods. It sends large
    responses, which trigger blockwise transfer.
    """

    def __init__(self, queue, lcd):
        super(DataResource, self).__init__()
        self.queue = queue
        self.lcd = lcd

    @asyncio.coroutine
    def render_get(self, request):
        ack = struct.unpack('I', request.payload)[0]

        # Delete the amount of data that has been ACK'd
        self.queue.delete(ack)

        # Get data from queue
        size = CHUNK_SIZE if len(self.queue) > CHUNK_SIZE else len(self.queue)
        LOGGER.debug("Getting %s from the queue", size)
        data = self.queue.peek(size)

        # Create and send response
        response = aiocoap.Message(
            code=aiocoap.CONTENT,
            payload=json.dumps({'data': data}).encode('utf-8'))
        return response


def run(config, hostname, queue, lcd):
    # Start server
    try:
        root = resource.Site()
        root.add_resource(('.well-known', 'core'), resource.WKCResource(root.get_resources_as_linkheader))
        root.add_resource(('data',), DataResource(queue, lcd))

        asyncio.async(aiocoap.Context.create_server_context(root))
        asyncio.get_event_loop().run_forever()
    except KeyboardInterrupt:
        pass


@@ -46,239 +46,78 @@
 ort 
-os.path%0Aimport socket%0Aimport struct%0Aimport threading%0Aimport time%0A%0Aimport aiocoap.resource as resource%0Aimport aiocoap%0Afrom persistent_queue import PersistentQueue%0Aimport yaml%0A%0Afrom sensors import setup_air_quality, setup_temp_sensor
+struct%0Aimport time%0A%0Aimport aiocoap.resource as resource%0Aimport aiocoap
 %0A%0A%0AL
@@ -492,30 +492,13 @@
     
-@
 async
-io.coroutine%0A   
  def

Remove some extra code from coap server