Tinyos-Tutorial.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Embedded computing projects, Learning TinyOS & nesC Rahav Dor Spring 2014 Kevin Klues started this lecture series in 2007. It has been inherited and kept up to date with advancements in TinyOS, nesC, and their development environments by Chien-Liang Fok, Gregory Hackmann, Mo Sha, and now Rahav Dor. Lecture topics Ø Embedded Compu9ng projects Ø Coding style, coherent and useful programming Ø Installing TinyOS and compiling your first app Ø Introduc9on to motes Ø Basic nesC syntax Ø Advanced nesC syntax Ø NetworK communicaon Ø Sensor data acquisi9on Ø Debugging tricKs and techniques 2 Lecture topics Ø Embedded Compu9ng projects Ø Coding style, coherent and useful programming Ø Installing TinyOS and compiling your first app Ø Introduc9on to motes Ø Basic nesC syntax Ø Advanced nesC syntax Ø NetworK communicaon Ø Sensor data acquisi9on Ø Debugging tricKs and techniques Robobees, Harvard university 3 Cool projects out there Ø Good night lamp. Ø Plantduino Greenhouse. Ø TwiQer mood light. Ø LED cube. Ø Shoe that lace itself. Ø Turn signal biKing jacKet. Ø Secret KnocK door locK. Ø Tree climbing robot. Ø Sigh collector. 4 Cool projects in here Ø Compare TinyOS and Conki. Ø Turn your mote into a web server, have it support AllJoin (AllSeen), Bonjour, CoAP, NLNA, MQTT, nanoIP, REST, etc. Ø Empirical study of any number of above protocols Ø Develop you own transport protocol, discovery protocol, … Ø Turn RaspberryPi into a 802.15.4 base staon (this is one of the few projects that are allowed on RPi). Ø Comparave study of security for IoT devices q New ideas? Ø Make your smartphone into a 802.15.4 remote control q Support querying, proximity, and simple commands Ø Develop an IoT search engine 5 Get inspired Ø hQp://makezine.com/ Ø hQp://www.instructables.com/ Ø hQp://www.raspberrypi.org/forums/viewforum.php?f=15 q Note that you cannot use the Raspberry Pi as the main plaorm in this course without my prior approval 6 Projects – requirements Ø Embedded system Ø Design, Code, and evaluaon – evenly divided among team Ø Project scope must be approved by me (Rahav) Ø Can repeat past projects as long as they have a twist q But you need to design and author your own code Ø You will be subject to academic disciplinary ac9ons, including failing this course, if you (see course full policy) q Submit program code wriQen outside this course without proper citaon q Simply copy code not wriQen by you q Use code of another student not on your team q Collaboraon and discussions are great exploraon vehicles and are encouraged, but you must aribute the ideas to their originator 7 Projects – artifacts Ø All ar9facts will count toward your grade Ø Design (diagrams and discourse authored in any tool) q Specificaons q Data flow q Logical interac9ons between the components or func9ons q Design consideraons • What you have considered (op9onal) • What you have decided to do Ø README.txt (or readme.txt) q See the readmeFD.txt example, which includes q A short descrip9on of the app q How to install, compile, and run your project (including a command line sec9on, e.g. java MIG) q Hardware dependencies 8 Equipment Ø Equipment, motes, … must be returned in good condi9on q -10% automac reduc9on otherwise q Physical interfacing must be done via connectors q Past evils can be undone • Up to a full grade leQer (on the project part) of extra credit for good ci9zenship: Soldering, Double sided tape, Cleaning Ø See course site for exis9ng equipment q Within reason and 9me we can buy staff to support your inven9on 9 Header comment (1 of 2) Ø Author a header comment at the top of all source files. Use the following format: Ø The name of the file (e.g., HelloWorldC.nc) Ø The name of the deliverable (e.g., Midterm demo. RFID reader.) Ø Name of the chief author and email address Ø Class: CSE 467S – Embedded Compu9ng Systems Ø WUSTL, Spring 2014 Ø The date on which the first release of the code was ready Ø Invariants 10 Header comment (2 of 2) Ø A short paragraph describing the func9onality. This should include, for example the purpose of the file or its role in the project. Be crisp, precise, and informave. Communicate your approach to solving the problem. Ø Version log with q Date q Who made the change, email address, and why q What was the change 11 Header example HelloWorldC.nc Purpose: Final project. Agent updater. Author : Rahav Dor [email protected] Course : CSE 467S -- Embedded Computing Systems WUSTL, Spring 3017 Date : Jan. 2, 3017 Invariants: 10 Hz <= updateFrequency <= 50 Hz Description: Maintain communication between agents and keep a local state when agents are detached from the hive. If communication channels are open this code guarantees information exchange according to the invariant. Version log: 2/1/2013, Jean-Luc Picard Fixed the remote agent bug. 3/10/2013, Seven of Nine An agent can now be detached from the collective, while still maintaining its basic operations. 12 Lecture topics Ø Embedded Compu9ng projects Ø Coding style, coherent and useful programming Ø Installing TinyOS and compiling your first app Ø Introduc9on to motes Ø Basic nesC syntax Ø Advanced nesC syntax Ø NetworK communicaon Ø Sensor data acquisi9on Ø Debugging tricKs and techniques 13 Style Ø Write self documen9ng code: if (lowTemperature(temp)) work = force * displacement * cos(moteToFloorAngle) Ø Indent 3 spaces or equal sized tab stop Ø Use DESCRIPTIVE_CONSTANTS Ø And self explanatory variablesNames Ø FileNames, ClassNames, e.g q Modules are named FallDetectionC q Configuraon is named FallDetectionAppC 14 Style Ø curlyFunctionBraces { … } Ø if (youFollow) { your are in a good starting place; } else { you start from less than optimal condition; } Ø Func9ons must have specs above them that describe the func9on, invariants if any, parameters, and return value Ø Use inline comments as needed 15 Style – TinyOS / nesC Ø Each app has a Configuraon (the wiring) and one ore more Modules (the code) Ø Wiring file are named: HelloWorldAppC.nc q This file name is the one specified in the Makefile as the source to be compiled Ø Code files are named : HelloWorldC.nc Ø Can also end with a P to denote Private 16 Lecture topics Ø Embedded Compu9ng projects Ø Coding style, coherent and useful programming Ø Installing TinyOS and compiling your first app Ø Introduc9on to motes Ø Basic nesC syntax Ø Advanced nesC syntax Ø NetworK communicaon Ø Sensor data acquisi9on Ø Debugging tricKs and techniques 17 TinyOS community q hQp://www.9nyos.net/ 18 TINYOS INSTALLATION – LINUX The next number of slides go over the general concepts of installing TinyOS (my recommendaons as of Jan. 2014). To install the system use the handout available on the course web site. 19 TinyOS recommended installation Ø We will be installing TinyOS, on Linux, running on a VM, that runs on a Host OS Ø Follow the installaon instruc9ons handout Ø I recommend you do the large downloads while on campus and while connected to a wired networK Ø VMware (Fusion version is the one for OS-X and cost 49$), or VirtualBox (free) q Known problems: Cut and Paste, Bluetooth Ø Ubunto 12.x (LTE) or 13.x (other debian flavors may worK equally well) q Consideraon for 32 and 64 bit versions: Memory, TinyOS will not compile on 64, and OS response 9me 20 TinyOS directory structure Ø Aser TinyOS is installed you will have a new tree branch under your home directory: /$HOME/nyos-main (this must correspond to $TOSROOT) q apps q doc q licenses q README q release-notes.txt q support q tools q tos Ø ChecKout TinyOS README file for details 21 Before motes are connected Ø Learn which devices are aached to Linux before you connect any mote to your machine. It will allow you to iden9fy what is the address of motes when you eventually connect them. Use the ls /dev/tty* command to capture data similar to the following: 22 When motes are connected Ø When you connect a mote, the Virtual Machine will asK you where do you want to connect it – chose Linux Ø The ls command as shown on the previous slide, or the command motelist will show you the aached motes Ø Change the permissions on any nyOS related q serial (/dev/yS<N>) q usb (/dev/s/usb<N>, /dev/yUSB<N>) q or parallel (/dev/parport) devices you are going to use, using the following command: sudo chmod 666 /dev/<devicename> Example: sudo chmod 666 /dev/ttyUSB0 Ø See a beQer alternave in the handout 23 TinyOS installation veriRication Ø To check your TinyOs installaon run tos-check-env Ø If you did everything properly you will see only one WARNING about graphviz not being version 1.10 (it will appear twice) Ø This is actually OK because you will have a newer version (likely 2.x). To check run dot –V Ø Later in this lecture, and on the installaon handout, we will also build Blink to conclude the verificaon 24 TinyOS installation Problems Ø If you try to run make micaz sim and it gives you a long error message star9ng with: ...: error: inttypes.h: No such file or directory Ø then you need to install the C library/header files for your own architecture Ø On Ubuntu/Debian, run apt-get install build-essential 25 TINYOS INSTALLATION – LINUX This concludes the general details about installing TinyOS 26 make System Ø TinyOS includes lots of Makefiles to support the build process Ø Create a simple stub Makefile in your app directory that points to main component, and invoKes TinyOS make system.