IoT Platform Training & Workshop: Hannes Tschofenig – LWM2M Intro & MBED Tutorial

yeah I try to keep this interaction short as well so we get more to the sort of hands-on part but a little bit of information adding on top of what your camera D said earlier there’s with IOT devices particularly if you go from sort of like the demo set up to something that is a little bit more sort of production ready also industrial space and consumer space you want to have some way to manage the devices and this is what are lightweight m2m is about and this management comes into multiple different sort of functions one of those functions is to actual configuration and retrieving the values and we are going to see that in in the demos later on island in the hands-on examples from it there are also security functions that you want to do with these devices are such as firmware updates we are not going to do that today or the distribution of key in a bit of a show that dinner in the case of leash are mean and sort of on how you could do that so the couple of basic features that you definitely want for most of those devices and likely them to a mess up as well as the protocol provides you those basic building blocks your him to walk you through that on diagram already this sort of client-server architecture and what we are going to see later on in the demo is the client lightweight m2m client sitting on one of those are small boards and I will hand out the bots later on but just to give you an idea so we have enough for our demonstration purposes we use this freescale developer board and it obviously comes with a sort of application processor there that we are going to program but then it has as it is typical for this developer boards it has lots of breakout connector so you can connect all sorts of sensors and actuators we are not going to do that because often that requires a little bit of first of all the extra hardware which I have a few samples with me to show you how that works but will focus more on the onboard sensors which this device also comes with what is interesting to note about this lightweight m2m as the name already indicates there’s this lightweight nature of the protocol and this is sort of comes from the design but also the reuse of certain technologies that are very focused on smaller devices in terms of memory needs sort of flash memory RAM and also over-the-air transmission so here we use ethernet because it’s easier to work with instead of this almost lap setup but it could as well be a Bluetooth smart it could be some other very constrained radio technology Sean could you click on this leg yep there couple of operations that happen between the between the client and the server and the ones that we are going to see most is what the beginning is we start with registration so you will see that there’s initially when it device boots well you reset the device and it loads its code it starts with a registration procedure to make itself available to the back-end infrastructure to the to the cloud server in this specific case and then as we then use a sort of an API to access the values there would be reads in our case be executed on the value on the board to retrieve later the latest sense of values but we can however also use sort of a publish-subscribe paradigm which is the last diagram here which is observed sort of subscribing to a value and then receiving notifications whenever the value changes all this is this right of cursing in great detail at are at the on a lightweight n2m specification and you have the slides available for download

in case you you want to use them a guess even in PowerPoint format do be good Wow yeah so you can use them click on the links there’s also an issue tracker I would like to make you aware of so in case you play around with the stuff and you can actually then report some some bugs and there’s a wiki page that you’re he mentioned already with lots of more information there’s also a popular open source server I’m sober library leash on that you could make use of and I’m sure I’m going to show that a little later and one important point that I wanted to already sort of mention now which we are also going to see more detail later on is this object model so how do you how do you address specific sort of data on the device so if you have this device it actually has multiple different interesting sort of resources there it has several buttons it has an LED which you could configure and it also has a accelerometer and a magnetometer and in there could be many other sensors attached to it so how do you actually address those in a meaningful way and that this is where the object model comes in so this in in this case and of course there’s also access control lists associated with it so how this works is is as follows so in the likely temptem specification defines have somewhat simple object model by saying that there’s this three two brew consisting of an object ID and object instance and a resource ID so let me show you what that means here’s um here are some examples on already defined objects things that people in the industry considered useful for use with those devices so for example on the device as an as a specific object name which of course itself has a couple of different attributes which are which are called resources so how to describe this specific device and we are going to see how that this device description looks like in later on he have an example from it so in case of a temperature a temperature sensor so there’s no temperature sensor on this device but but I think you get the idea so there’s this object defined it has a specific number so that the object and resources are defined by numbers so you see can I use it is okay that’s why that yeah quick so here for example this has an ID and this means okay this is a temperature sensor a definition for a temperature sensor and it has a couple of attributes and in this specific case it has three attributes namely these number with those numbers the first one isn’t probably the most interesting one is the one with the sense of value itself so like what’s the what’s the temperature value and you can read that value it for this object it only has a single instance it describes the data type and the unit so if you receive the data you actually know what the semantics of that value is there’s a little bit of metadata defined here as well as two additional attributes minimum measured value maximum budget measured value and whether you use that object as only with only one attribute or above all three is up to your application and your needs so it depends that depends a little bit but you can pick and choose from different values and here’s an example of of values are different objects and I’m not showing the different attributes the resources because there would be a little bit too much but there’s behind this link there’s the point that do the registry where you can see all of the standardized objects and in their resources so a lot of lot of stuff and so how how on how are you supposed to use that all together so for example if you have a device like a fridge or here an HVAC as well you can take these different objects and then and in red you see the resources you combine them to describe for example a fridge and that’s something that you you want to

sort of expose to your application how many of them how many of those objects are use really depends on what your application example needs how how did that that description has to be and what you can control and what you can’t so so I think that’s a from an over web overview point of view I think that’s enough about lightweight enter and we see more about these objects and how to set values and so on later on in the examples okay perfect you’re in who’s next now it works good okay so we now get to the to the bad way we do a little bit of hands-on when we worked on so what you will at the end I hope what you have there will be Eddie you will be able to configure the device that it you create some you use the tools to create a firmware image and load the firmware image on the device and then in the firmware image will contain lightweight m2m client that connects to a cloud-based service that’s what we hopefully will have at the end if everything works we’re going to we can use different tools to get there so everyone has different preferences on what they want to use to develop software I will premiere primarily show the use of the command line tools which are also linked on the workshop page so you had a few instructions on how you could use those tools and download them you can also download them then here now if you want for those guys who can’t download anything for whatever reason there is also a web-based version of it some people like to edit code in a web browser okay some others again which i’ll also show they like more professional ide development environment and you’re free to use whatever you want it doesn’t really matter at the end of the day but there are obviously differences in eating an appearance and and the debugging capabilities but before i get there i wanted to tell you a little bit about also the hardware and how we got there where we are today and I wanted to instead of introducing these usual IOT stuff and and all these great predictions about how many devices we would have around I wanted to show you a few projects that we are doing and I thought for example this one is is quite good than the appropriate are for the place where we are in the bbc’s has this project called micro bit where they want to give a small little computer to every 12 year old child in the UK so that they can play around with it and this is how supposed to look like LEDs buttons and there’s a processor there and it’s an arm-based processor and it I think it’s a Nordic semiconductor chip and I’m actually going to pass around the chip because I have a few of those with me and so you can see how that looks like because it’s a it’s obviously oops it’s obviously fairly small needless to say so it’s um it’s a it’s a cortex m0 and that will explain in a second what that means and m0 plus and this device runs very similar software then this this reference architecture of course this one the difference to this one is this is a smart city reference architecture that we have been that’s interesting why um could you remove the bar so this one is another sort of design so all of these designs that I’m showing this I’ve three examples here you can download the code as well as the designs and sort of like when when appropriate that sort of the hardware reference files here we did a smart city reference architecture and you’re using the same pieces but you’re using different radio technology in this specific case use the sub gigahertz i triple e eight on a to that fifteen that for radio different radio technology different radio than the BBC micro which uses bluetooth smart which is very convenient for kids when they have modern our mobile phones in a in a smart

city environment you want the radio that you can use for meshing for mesh for mesh technologies so you’re not not the street lights individual street lights are not connected individually to the internet but they are connected with each other which then go to a gateway and then to the internet as this diagram is showing you so if you go to the embed website you see those theatres another reference design that we looked into the decide about what functionality do we need is a reference design for a variable of Smart Watch and also you can also download this this one runs on on a similar processor and has an eight week battery lifetime use the same software of course it uses are as some additional sensors for example it has a fingerprint sensor it has a GPS sensor and so on its GPS receiver so obviously different applications need different sensors but beyond that sort of the operating system and and the protocol stack is very similar so um what we want to get to is we want to bring IOT until to scale and not just I’m sort of like for prototyping effort even though we do sort of prototyping things here you can then go from that labored to something that is product quality in with the same tools with the same technology with the same stack so you don’t need to sort of like you you don’t develop the prototypes with one set of tools and in development environment etc etc and then when you do want to develop a product it would be completely different that’s not the idea so it’s the same stuff and time-to-market matters and productivity of the developer itself security and connectivity and also the diversity and you see the diversity also with the number of hardware models modules that are available so you write that so we used today the NX be or the freescale k 64 f but you can then as well take a different board next time and for example I I took one with me that SDM stmicroelectronics kindly offered us is this it’s called stm32 f 7 and still it’s a high performance sport it has huge display this development board so you can open it and pass it around it obviously has far more capabilities and it’s much faster and has more memory and everything areas it also has an Ethernet port built in the demo board until you could actually take the code that we develop we use today and then recompile it for use with this with this device without having to sort of like totally throw everything away when we talk about connectivity we talk about a fairly complicated protocol stack because after all you know the IE in the IOT like we are talking about internet so we talk about Internet to the devices that means a lot of different things not not just the radios the radio technologies that I mentioned before but also like the ipv4 ipv6 here we use IP before in this setup because that’s what we got UDP the transport protocol tcp we use the security and I have a separate flight on this because I I believe that’s very important and we use co-op as mentioned before because it part of lightweight into them and in order the the rest api is so we have to fit this like this whole protocol stack on these tiny little micro controller that I just passed around oops this item can you is it for some reason does it work now okay good so if your drill in a little bit on the security side there at least three different components to look into it one instead device security and we are a little bit cheating in that demo here because as you will see later we are sort of mimicking the manufacturing process by simply copying the keys manually so obviously in a real world scenario you would have manufacturer provided Keys different keys for each device but here we just every one of you just copies the key himself and everyone will have a different key for the device um there’s the lifecycle security which OEM a lightweight m2m provides with firmware updates and all these sort of things and as the communication security which are

lightweight MDM also relies on which uses dtls and dealers sort of the regular transport layer security suite and that’s where lots of lots of the code kuntram because this is hardcore crypto when when we talk about IOT devices and what is differentiating a differentiating factor between the different hardware components that we use is we have often limitations in terms of memory ram flash size process of capability speed particularly there’s maybe no user in front of the device and we also care about energy efficiency for many of the for many of the deployments the salt there may also be constraints on a network site people talk about low-power wide area networks we talk about Luke bluetooth low energy and and so on and so on there’s there’s a whole document that talks about this which are reference here below um in in context of arm-based devices so the previous arduino that was shown that was not an arm-based devices it has a the bigger processor that you’ve seen we trans Linux is it’s a mips it’s still a risk based design so reduced instruction set which typically means a smaller number of instructions and more registers the ARM processors are also fall into that category and the ones that we are looking into here are so called the cortex m-class devices they they can easily sort of like from a developer experience and from a product point of view there’s also another category that you may be more familiar with this is the 8th class divides the application processors which you run in your mobile phone tablet and your Raspberry Pi big leap on black and these sort of devices and that’s a different class of devices it’s a different architecture it runs regular Linux or Windows 10 for IOT or whatever so are more sophisticated operating systems and the development experience would be very different but also the the order requirements the hardware requirements and the cost will be very different also the energy efficiency is also very different so you can measure the energy efficiency or the energy consumption of a Raspberry Pi compared to one of those devices and you will see obviously a huge difference um they are different I won’t go into details of the different processor but just to give you an idea what boards you have in front of you the K 64 f is a cortex m4 it’s actually a very capable processor it’s it’s the one one over here it’s often because of its capability for digital signal processing and this singing structure my turbo data with the floating-point unit it’s often used in sort of sensor fusion fusion applications audio processing and these type of things for the chip that I passed around the cortex n0 + that would be low power small instruction set no floating point unit and in this case this specific one it has bluetooth smart radio incorporated bluetooth low energy in the other port from stmicroelectronics that i passed around just open the board and have a look at it the lots of stuff on it this one is the latest one of this series is a quarter sem seven is a very powerful processor it is the first one in this series that offers a cache all the other ones don’t have a cache and what they also are differentiated from from the Raspberry Pi based deployment is the memory is actually on chip so in the same package you have the Flash and the rum is India so there’s no separate for example dee da dee dee dee are run but there’s also no concept of virtual memory like there’s no memory management unit that’s why you can’t run linux on those type of devices you may not even want to because of like the linux would be like we’re talking about megabytes of instant caught here but in this specific case we are not so here i have a few examples um there’s a small one cortex m3 with 120 megahertz and here you see like this is um it’s a pretty oversized chip for many of the IOT deployments but I had chosen them this one for for a good reason not only because it has a

512 kilobytes of flash it has a lot of features also hardware-based random number generation and you see the prices there from last year the wall it’s quite expensive compared to 44 small volumes so if you if you these are if you buy large volumes the prices would be significantly different so you see this is a company final if you if you buy more than 2000 for an IOT deployment like if you have a smart city deployment or something as 2,000 chips is not nothing or for light pipes or so and and so for higher volumes obviously if you buy a million of those the price would be very different but if you look at this one and compared with the next one oops you see something interesting here nuts that’s why I put those there those do so you see this this is why why do I have a disconnect between what I see on my screen and what what is shown on the on the display Oh a little bit um so the stuff that you don’t yet see it has it’s a much faster processor and has more flash has more ram but it’s much cheaper and it’s totally counterintuitive you would think like how is that possible and the reason is some chips are because of manufacturing volumes are more popular and so people buy it more the prices drop the factory once you have a setup costs were for factory and so you you may actually get a very good chip very performant chip for a very low price so you see that and that’s that’s what I’m I was trying to get across here the chips that I passed around obviously much smaller but I’m even from a price wise it’s very different still as you can see on the chart on a diagram it has lots of features it has it implements even even a very basic chip nowadays comes with lots of features debugging capabilities all sorts of different protocols all sorts of different time as real-time drug encryption of cable hardware-based encryption capabilities etc etc so this there’s um just because you have some of those features doesn’t mean that you have to spend a lot of money and also worth pointing out and often see that confusion and when I when I talk to people up and give them the boards is they there’s the belief that the price of the board has something to do with the price of the product but it of course it’s and completely completely unreal this is a development board and so I showed you one development board and I want to pass you around a few others other development boards that have different capabilities different manufacturer are supposed to illustrate something very different and of course the boards can be if they are larger like like this one this is a full-fledged up development board that comes with a separate debug and so on that our colleagues from kylie use and those ports are more expensive but in a real product you’re not going to use the development board and the price of the chip is actually not necessary necessarily the dominating factor and the cost of the overall product so there’s a nice webinar recorded then you can click on the link that explains you some of those relationships and you have the cost of the order bill of material including the packaging you may find that actually the the foil that you use to wrap your final product may actually be more expensive than the chip or 10 times more expensive tenergy you need to think about long-term costs energy efficiency what what the costs are if you actually get an engineer field engineer out to the product derivative software update and also the cost of development if you have something that is highly optimized for some very special architecture it costs you a lot of money you need engineering manpower and to actually do that getting getting to the arm demo that we work with so we are starting from the left hand side so we work with this with the board that has this on-base trip cortex-m chip that I explained it runs an operating system that we develop and give away for free it can be download it’s open source this device will then connect to a cloud infrastructure that we also provide which we call our embed device connector and then that is just a pass through

device if you will there’s in a real service you the company who offers the product and the web service they need to think about what’s the value add so if you have for example variables the value-add is with a sports watches it tells you like how much you ran it visualizes it nicely maybe shows you on a map on where you ran on how much training you did and in how much training you should be doing and how good you are and who knows what and that’s what a value is and so there may be big data analytics and all sorts of things in work and we have sort of partnerships with other companies like IBM with if they’re bluemix and other companies who provide that type of expertise for specific sectors to analyze unlike basically take the raw sensor data and then do something meaningful with it so if you have for example in industrial environment you have a steel factory you have the sensor readings just temperature readings but the whole process is very complicated you need to know you need to understand how steel is manufacturers to actually make sure that the temperature range stays in specific values to produce our optimal product the the connector this cloud-based service is located at this if you have have had a chance to look at the the instructions that we passed around before and that’s what it said so we are going to build the code for the device on on the laptop locally for most of you I’m connected to the device use some use that as a as a way to get the keys and also to do some a little bit of debugging to see what’s going on just as a API included in here to allow cloud-based services to access those the sense of values that’s what we do this embed connector for developers that’s for free if you of course have millions of devices then the story is a little bit different because we need to operate the server infrastructure what is specifically on the on on the code that I’m we are going to look through is you will see a few things first of all you will notice that this is a C C++ API so you it’s something many of the embedded devices and IOT devices are developed in C so that’s why it’s no different here the benefit of doing that is you can reuse a lot of sick sample code so if you have sensors available and some of this company’s manufacturing the sensors they actually provide you the example code and the libraries along with it very convenient in this it comes with TLS automatically so we won’t actually need to do anything the default is transport layer security enabled so you will actually have to figure out on how to disable to transport layer security yeah and then there’s there’s a lot of stuff under the hood which we won’t look at but of course feel free to look at the operating system if you care about these type of low-level eaters it’s written mostly in C therefore performance optimizations there are some assembly files as well for example for some of the crypto good um I mentioned here that the importance of security we use a library called empathy LS which is a an acquisition of an open source library called bola SSL that embedded dls stack that comes so you can use that also for free it and you can the code is available for download has always been also with polar and it implements other recommendations that the specification makes you can also use it for other purposes if you want and this is an shouldn’t be underestimated because the the size of the code for the crypto often exceeds fine exceeds the rest of the code so it’s it’s as a developer you better not want to write that code yourself because that would be very time consuming and requires a lot of expertise good so here here are some of them the links and you should have also seen those links on the workshop page so just for for your reference here’s here’s the board so what the first thing we are going to do is login so this is the ethernet connector plug in the USB

cable interests are into the sport this is the one that we also use for for connecting the debugger yes yeah yeah and there’s the second one so if you plug it in here you also power the device but you’re not using the debugger um this is the chip that I was talking about the cortex ends here it runs at 120 megahertz this is a very this is a device that is really useful for development because you will not have any memory problems like for linux this may be nothing of size wise but for an IOT device this is massive so we we so in example we I just I didn’t select features or deselect features I just dumped everything in there and it’s like nothing also ran by seemed like we could we could do all sorts of things with it um we there’s lots of different both supported so depending on what you want to do and in your project you may need a different board so in this case obviously I selected this board because first it was available second it had ethernet and which is convenient here but if you want to use let’s say some bluetooths or some cellular radio you can add extension shields or you can get other ports and so on so have a look have a look at those links there are two operating systems that we have developed one is what we call classic and the other one is on the new version we’re trying to harmonize and them as we go forward but i will show you how to develop with both of them it doesn’t matter that much for our purpose in fact i should include a link that points you to the linux based version of the same code of the lightweight m2m code so you can actually run it on a raspberry pi but i didn’t took a rasp right by with me so but if you if you have a Raspberry Pi at home you can still do the same stuff but you won’t be you will be working on a class cortex a class process and not n plus different development experience ok good so did you successfully plug in and that what should happen is and that’s the nice thing with these embed enabled boards is that the device should show up as a USB stick essentially so if that work that’s good um that allows you to drag and drop the firmware onto the device in many others so if you if you’ve been developing with embedded devices previously you may know the hassle of connecting a separate independent debugger to the device and figuring out what the memory rangers are and where to copy the firmware and all these sorts of settings nothing of that is necessary here this is sort of the easier development experience there’s a separate chip on it that allows sophisticated debugging good I did that already I connected my device and as you see well or maybe see so there’s a separate it just shows up as a as a device as a say USB device and what we are going to do first is to make sure that we we get something working so the description of how to get not and so the lightweight n2m is not the most basic example on earth you can also if you want your cam you can also take important and oh you have ok could notice this actually drawn right um you need to you need to sign up to the embed connector because otherwise you need to get your key for your port and not my keys right let me see where my so this is um so they’re different I copied us in here’s but so this is the example that we are going to use there’s a github from this github repository so the code is in github for the for the for our new version we use the different repository mercurial for embed OS avoid

up for the embed classic but now we use katha and so if i go to that website you see the code but you also see the description and so this is the but you need to create an account and then you we use the client on on the desktop we use a development environment to build the program so and and of course the software will depend a little bit on what operating system you run okay did you guys set up this already okay oh yeah awesome give me give me a sign when you when you guys are ready or how far you are free time are you I you did you install the stuff already know okay so you run the yota in the mac OS okay the dab it are you you are following along as well i will run around a little bit to see how you guys are doing what we try to do here is we just create the development environment we need the code of the program and the operating system and and there’s a little bit of development environment so for example so i use i can show you what i use i run lynn windows on my my work pc and then I but I prefer to do everything in Linux so I’m actually using running ubuntu in a virtual machine and I’m doing everything there you skit and in order tool stare so your toe is a wraparound see make and it also uses a component management system that is simple similar to MPN and yeah and then um we use a serial monitor to get the debug messages so the plus of using this sort of simple way of talking to the device using and USB sort of stick USB flash drive is it’s just that which is dragging throughout the firmware for debugging I we use a serial monitor so for example I use in an empty dep probably ten different ones around so I use one in Windows that is called Derek term so I’m actually doing the debugging inning in Windows you could also do it in Linux if you want it’s personal preference um let me increase the font size so I also um just to give you while you up clicking around just to give a different view of the same development experience is here I use an IDE from kyle i’m using the same code but i’m just using this graphical editor which provides me so are some people at least more convenience when they develop programs and and also when building programs and debugging programs you can download there’s also a free version of Kyle available that you can download of course there are all sorts of other I IDs that you could use and the details here don’t matter there are lots of files we won’t go through those in this in this editor but I Kylie spelt like yeah yeah yeah some it sir now it’s a German company that developed

and the known the ID actually did develop our operating systems but their primary focuses on developing IDs and the protocol stacks along with it and I’m bought it up probably about 10 years ago so and but there are all sorts of other so it depends on everyone has a different preferences preference when it comes to the IDE like some people like eclipse and some others like vicious to do I have I know people who use visual studio to write the code and then to do i generate the code for these arm devices on base devices I’m actually using visual studio myself as well but for more complicated protocols and then once I’m once the things work then I switch to a different editor because then that advance so that development experience with embedded devices is more complicated because as we previously heard you have to generate code that doesn’t run on this platform natively so we the tools that you download I’m sort of the compiler produces and then the linker produces a binary that would run on the machine locally so that’s why it’s often easier for example if if I I develop and working on a new version of transport layer security and so i can run declined in a server locally on my machine I don’t need to have a device connected I don’t need to sort of mess around with the deep complicated debugging settings just imperative relevant is more complicated like smartphone app development is also more complicated and because you have to deal with the separate device ok but here you can use all sorts of different IDEs when in many of the smartphone development environments you can only use one good talked about that so what’s the situation I me are we good you sign up and you did you successfully install your you can’t install any programs on your machine you can delete it afterwards again it does matter you can reapply you could try it to see what it works so um yep let me show you where is it now let me quickly so here’s the so if you search for github and embed client Quick Start which is the link that you should also see on the on the workshop web page you see a step-by-step version there’s also linked to yata and this is the build program and that there’s some software and the description obviously varies on how to install it depending on which operating system you install it on you