#!/usr/bin/env python3

from aiocoap import *
import asyncio
import time

host_uri = "[fe80::f353:4e59:71ba:600a%lowpan0]"
max_samples = 32
@asyncio.coroutine
def main():
    protocol = yield from Context.create_client_context()
    samples = dict()
    samples['temperature'] = list()
    samples['humidity'] = list()
    sampels['airquality'] = list()
    for i in range(0,max_samples):
        samples['temperature'].append(0)
        samples['humidity'].append(0)
        sampels['airquality'].append(0)

    pos = 0
    while True:
        req_temperature = Message(code=GET)
        req_humidity = Message(code=GET)
        req_airquality = Message(code=GET)
        req_temperature.set_request_uri('coap://'+host_uri+'/temperature')
        req_humidity.set_request_uri('coap://'+host_uri+'/humidity')
        req_airquality.set_request_uri('coap://'+host_uri+'/airquality')

        try:
            res_temperature = yield from protocol.request(req_temperature).response
            res_humidity = yield from protocol.request(req_humidity).response
            res_airquality = yield from protocol.request(req_airquality).response
        except Exception as e:
            print('Failed to fetch resource:')
            print(e)
        else:
            t_temp = float(res_temperature.payload.decode('utf-8'))
            t_humi = float(res_humidity.payload.decode('utf-8'))
            t_airq = float(res_airquality.payload.decode('utf-8'))
            samples['temperature'][pos] = t_temp
            samples['humidity'][pos] = t_humi
            sampels['airquality'][pos] t_airq
            print('Temperatur: %f, Humitdy: %f, AirQuality: %f' %(t_temp, t_humi, t_airq)
            pos = (pos + 1) % max_samples
        time.sleep(1)

if __name__ == "__main__":
    asyncio.get_event_loop().run_until_complete(main())

@@ -17,16 +17,29 @@
 ython3%0A%0A
+# coap stuff%0A
 from aio
@@ -79,16 +79,144 @@
 rt time%0A
+# plot stuff%0Aimport matplotlib.pyplot as plt%0Afrom matplotlib.backends.backend_pdf import PdfPages%0Aimport numpy%0A%0Amax_samples = 32
 %0Ahost_ur
@@ -257,32 +257,48 @@
 wpan0%5D%22%0A
-max_samples = 32
+pp = PdfPages('sensordata.pdf')%0A
 %0A@asynci
@@ -469,34 +469,34 @@
  list()%0A    samp
-e
 l
+e
 s%5B'airquality'%5D 
@@ -622,34 +622,34 @@
 (0)%0A        samp
-e
 l
+e
 s%5B'airquality'%5D.
@@ -1714,18 +1714,18 @@
     samp
-e
 l
+e
 s%5B'airqu
@@ -1736,16 +1736,18 @@
 y'%5D%5Bpos%5D
+ =
  t_airq%0A
@@ -1778,16 +1778,19 @@
 ratur: %25
+2.2
 f, Humit
@@ -1794,16 +1794,19 @@
 mitdy: %25
+2.2
 f, AirQu
@@ -1813,16 +1813,19 @@
 ality: %25
+2.2
 f' %25(t_t
@@ -1844,16 +1844,17 @@
  t_airq)
+)
 %0A       
@@ -1888,16 +1888,555 @@
 samples%0A
+            if pos == 0:%0A                plt.subplot(3, 1, 1)%0A                plt.plot(samples%5B'temperature'%5D)%0A                plt.title('Sensor data')%0A                plt.ylabel('temperature')%0A%0A                plt.subplot(3, 1, 2)%0A                plt.plot(samples%5B'humidity'%5D)%0A                plt.ylabel('humidity')%0A%0A                plt.subplot(3, 1, 3)%0A                plt.plot(samples%5B'airquality'%5D)%0A                plt.xlabel('time (s)')%0A                plt.ylabel('AirQuality')%0A                pp.savefig()%0A                pp.close()%0A
         

add pdf plotting