Διαδίκτυο των Αντικειμένων - IoT sdima@ece.upatras.gr
ΑΠΟΚΤΗΣΗ ΑΚΑΔΗΜΑΪΚΗΣ ΔΙΔΑΚΤΙΚΗΣ ΕΜΠΕΙΡΙΑΣ ΣΕ ΝΕΟΥΣ ΕΠΙΣΤΗΜΟΝΕΣ ΚΑΤΟΧΟΥΣ ΔΙΔΑΚΤΟΡΙΚΟΥ ΣΤΟ ΠΑΝΕΠΙΣΤΗΜΙΟ ΠΑΤΡΩΝ (ΦΚ/MIS) Ε.655/ 5001184. sdima@ece.upatras.gr
Γιατί όχι Linux Linux :robust, developer-friendly OS, platform για IoT devices. Memory footprint. Δε θα μπορέσει να τρέξει σε 8 ή 16-bit MCUs, και ίσως ακόμα 32-bit MCUs δε διαθέτουν αρκετή RAM για το Linux kernel. (Cortex-M) Linux: embedded devices με graphically rich user interfaces.
Δημοφιλή λειτουργικά συστήματα OS στο ΙοΤ Raspbian: Debian port, Mate: fork Gnome 2 Contiki: 10KB RAM, 30KB ROM Riot: 1.5 KB RAM, 5 KB of ROM. Windows 10 IoT Core: Raspberry Pi 2 και MinnowBoard MAX
Wireless Sensor and Actor Networks Services? Operating Systems? Protocols? Core network e.g. Internet Protocols? End-user Sink node Gateway Computer services
Operating Systems σε embedded systems Operating System (OS) σε ένα embedded system είναι ένα λεπτό thin software που βρίσκεται ανάμεσα στο hardware του node και στο application layer. OS παρέχει basic programming abstractions στον application developer. Το βασικό task του OS είναι να επιτρέψει σε applications να αλληλεπιδράσουν με τα hardware resources, για να κάνουν schedule και prioritise tasks να μεσολαβήσουν μεταξύ applications και services που προσπαθούν να χρησιμοποιήσουν τα ίδια memory resources.
Βασικά χαρακτηριστικά των OS για embedded systems Memory management Power management File management Networking Παροχή programming environment και tools (commands, interpreters, compiler, etc.) Εntry points για access σε sensitive resources όπως το γράψιμο σε input components. scheduling, multi-threading, handling interrupts, memory allocations.
Threads and events thread είναι μια αλληλουχία από programmed instructions που μπορούν να γίνουν managed και να εκτελεστούν ανεξαρτήτως ενός scheduler Ένα event driven program συνήθως εκτελεί ένα event loop,]. Αναμένει την ύπαρξη ενός event, e.g. input από internal alarms. Όταν το event συμβεί το πρόγραμμα συλλέγει δεδομένα για το event και το κάνει dispatch σε ένα event handler software.
Thread-based vs Event-based Programming Είναι σημαντικό η υποστήριξη concurrent tasks (I/O systems) Thread-based programming χρησιμοποιεί multiple threads και single address space. Με αυτόν τον τρόπο αν ένα thread είναι blocked από κάποιο I/O operation, το thread μπορεί να γίνει suspended και άλλα tasks μπορεί να εκτελεστούν σε διαφορετικά threads. Προστασία των shared data structures με locks, coordination της εκτέλεσης των threads. Ένα πρόγραμμα multiple threading μπορεί να είναι σύνθετο, να έχει bugs και να οδηγεί σε deadlocks.
Thread-based vs Event-based Programming το event-based programming χρησιμοποιεί events και event handlers. Event handlers γίνονται registered στον OS scheduler και γίνονται αναλόγως fires. O kernel του OS συνήθως υλοποιεί μια loop function που κάνει polls για events και καλεί τους σχετικούς event handlers. Ένα event επεξεργάζεται από τον event handler μέχρι την ολοκλήρωση του εκτός αν οδηγηθεί σε ένα blocking operation. Σε περίπτωση blocking operation κάνει register ένα νέο call back και επιστρέφει τον έλεγχο στον scheduler.
Embedded Operating Systems OS τρέχει σε devices με restricted functionality Στην περίπτωση των sensor nodes, χαρακτηρίζονται και από limited processing capability e.g. Contiki Restricted σε narrow applications industrial controllers, robots, networking gear, gaming consoles, metering, sensor nodes Η αρχιτεκτονική και ο σκοπός των embedded OS αλλάζει καθώς αλλάζουν τα hardware capabilities (i.e. mobile phones)
Contiki Contiki είναι ένα open source operating system για το Internet of Things. Τρέχει σε networked embedded systems και wireless sensor nodes. Είναι σχεδιασμένο για microcontrollers με μικρή memory. Ένα τυπικό Contiki configuration απαιτεί 2 kilobytes RAM και 40 kilobytes ROM. Contiki παρέχει IP communication, για IPv4 και IPv6. Contiki υποστηρίζει 6lowPAN header compression και το CoAP application layer protocol.
Contiki- Functional aspects kernel functions: event-driven kernel; multithreading : application library => hybrid OS. Τα services επικοινωνούν μεταξύ τους μέσω του kernel κάνοντας post events. Ο kernel του Contiki kernel δεν παρέχει HAL, αλλά επιτρέπει device drivers και applicationς να επικοινωνούν απευθείας με το hardware. κάθε Contiki service κάνει manage το state του σε ένα private memory space και ο kernel κρατάει ένα pointer για το process state.
The Contiki OS Loaded program Loadable programs Can be easily updated Core Service Communication service Language runtime Program Loader Kernel Core: single binary Usually never modified
Protothreads Protothreads : lightweight threads. interruptible tasks στο event-based programming. Ένα protothread παρέχει ένα conditional blocking wait statement που κάνει block το protothread μέχρι το statement να γίνει true. Όταν το protothread «φτάσει» το wait time, συνεχίζει την εκτέλεση Ένα protothread μπορεί να γίνει invoked οποτεδήποτε το process λάβει μήνυμα από άλλο process ή εξαιτίας ενός timer event.
Protothreads- example For example consider a MAC protocol that turns off the radio subsystem on a periodic basis; but you want to make sure that the radio subsystem completes the communication before it goes to sleep state. 1. At t=t 0 set the radio ON 2. The radio remains on for a period of t awake seconds 3. Once t awake is over, the radio has to be switched off, but any on-going communication needs to be completed. 4. If there is an on-going communication, the MAC protocol will wait for a period, t wait_max before switching off the radio. 5. If the communication is completed or the maximum wait time is over, then the radio will go off and will remain in the off state for a period of t sleep. 6. The process is repeated. Source: Adam Dunkels, Oliver Schmidt, Thiemo Voigt, and Muneeb Ali. 2006. Protothreads: simplifying event-driven programming of memory-constrained embedded systems. In Proceedings of the 4th international conference on Embedded networked sensor systems (SenSys '06). ACM.
Radio sleep cycle code with events Event driven code can be messy and complex Source: Adam Dunkels, Oliver Schmidt, Thiemo Voigt, and Muneeb Ali. 2006. Protothreads: simplifying event-driven programming of memory-constrained embedded systems. In Proceedings of the 4th international conference on Embedded networked sensor systems (SenSys '06). ACM.
Radio sleep cycle with Protothreads Source: Adam Dunkels, Oliver Schmidt, Thiemo Voigt, and Muneeb Ali. 2006. Protothreads: simplifying event-driven programming of memory-constrained embedded systems. In Proceedings of the 4th international conference on Embedded networked sensor systems (SenSys '06). ACM.
Sensor Network Programming Sensor Network programming :node centric ή application centric. Node-centric approaches: software for nodes (on a per-node level). Application-centric approaches : software για ένα μέρος του δικτύου σαν ένα entity. Το application centric programming απαιτεί collaboration μεταξύ διαφορετικών nodes στο δίκτυο για collection, dissemination, analysis και processing των generated και collected data.
The Contiki code Header files #include "contiki.h" PROCESS(sample_process, "My sample process"); AUTOSTART_PROCESSES(&sample_process); PROCESS_THREAD(sample_process, ev, data) { PROCESS_BEGIN(); while(1) { PROCESS_WAIT_EVENT(); } PROCESS_END(); Defines the name of the process Defines the process will be started every time module is loaded contains the process code } Event parameter; process can respond to events Threads must have an end statement process can receive data during an event
The Contiki code #include "contiki.h" PROCESS(sample_process, "My sample process"); AUTOSTART_PROCESSES(&sample_process, &LED_process); PROCESS_THREAD(sample_process, ev, data) { static struct etimer t; static int c = 0; PROCESS_BEGIN(); etimer_set(&t, CLOCK_CONF_SECOND); while(1) { PROCESS_WAIT_EVENT(); if(ev == PROCESS_EVENT_TIMER) { printf( Timer event #%i\n", c); c++; etimer_reset(&t); } } PROCESS_END(); } Process thread names Process thread 1 PROCESS_THREAD(LED_process, ev, data) { static uint8_t leds_state = 0; PROCESS_BEGIN(); leds_off(0xff); leds_on(leds_state); PROCESS_END(); } Process thread 2