 Welcome everyone. Everybody can hear me? All right. I am so, so happy to be here. This is my third time that I'm here in the Red Dot Ruby conference. And the first time when I was here, I was just a beginner trying to learn the ropes of web technologies, the Ruby programming language, and the Rails framework. But it has been a phenomenon and fun journey since then because of many of you in the audience, the Ruby community of Singapore and beyond. Whether it's people like Winston who has been so crucial about programming and teaching, or people like Juanito, you know, like spreading the love and laughter, or even getting some free hardware like this in Red Dot Ruby conference just last year, it has been a fun journey. But being a beginner is not just a story of an individual. It is a story told repeatedly by generations of engineers, experienced engineers, whether it is the integrated circuits of the 1960s or personal computing of the 1980s, or even more recently, the web and the internet. Engineers have always taken on something new, something unknown, something messy, have kind of played with it and made it so usable to the people beyond that it almost became an extension of who we are. And so I thought I should start with a quote. The wheel is an extension of the foot. The book is an extension of the eye. Clothing is an extension of the skin. Electric circuitry is an extension of the central nervous system. Today, I hope to share with you something that is an extension of our very own senses, starting with the senses themselves and some of it I have right here. I want to be taking you down from the extraction layers from the physical world, the real world, all the way to the application layer which all of us are familiar with, and I want to share with you exactly what is changing in each of these layers. So let's start with the sensors. They're pressure sensors, light sensors, humidity sensors. They are becoming cheaper and more compact than ever before, which means it's just much more accessible to us. The next layer is the wireless communication stack, which the sensors will be using to transmit their values, and all of us must have heard of NFC or even Wi-Fi, Bluetooth, and 4G, which is kind of long range. There are newer protocols coming up, such as Bluetooth low energy, or even 5G that will be coming up in a few years, and these are especially important for tiny sensors, low power sensors for machine-to-machine communication. The next layer is the access layer. So all of us who are web developers here are very familiar with these protocols, the HTTP, the HTML, JSON, and so on. I also want to share with you two more protocols in the application layer, which is the MQTT and the Co-App, and these are very important for machine-to-machine communication once again. And of course above these we have the web of things layer which all of you as real developers or web developers will be playing with. Now for today's talk, I will be specifically focusing on the bottom three layers, focusing on the layers that will be communicating with the physical layer, the analog layer, with the digital layer, the application layer. So before I get started, I want to talk a little bit about what is an Internet of Things platform. So, show of hand, how many of you are Rails developers? Wow, that's about 70% of you. I agree with you, not all of us are web developers, so we might be playing with Ruby a lot. So as web developers, as Rails developers, I'll be talking about this framework called Thingspeak. So if you go to thingspeak.com, you can actually connect your sensors and play with it. So it is a hosted platform. But if you want to look at the source code as developers, you can also go to GitHub and you can also download the source code. So just a word of caution. The source code in GitHub is about a year old. So it will be based on Ruby 2.1, and the Rails version is 4.2. But nevertheless, I still feel that we'll be able to catch on a lot of how the controllers are made, the models are made, and get a lot of ideas. So essentially, what is an IoT platform? So it has four key features. Number one, so you have a sensor out there in the wild, and that kind of communicates periodically to your Ruby on Rails server. So that's a key thing about what is an IoT platform. The second thing is when does the sensor send these values? It can be triggered by event, which can be by a human, and it can be by periodic, like every few hours or so. The third key thing is what do we do with the sensor data after it comes to your Ruby on Rails server? Typically, we will plot charts and graphs. So that's a very key function of this. The last attribute is hooks. And I think as Rails developers, we are very good at this. Like when we get a post request or a get request, we might trigger a rake task, or we might generate a PDF or an email. So these are the hooks and triggers I talk about. So now that you know what is an IoT platform, I want to be giving you three demos in the course of this talk. And hopefully with these three demos, they are tangible enough for all of you to take back something home, get excited, and start playing with the physical world. So I have three demos here. We'll be using Wi-Fi wireless protocol for this purpose. I have three kinds of sensors or actuators, and being a red dot attendee, I've used emojis, as you can see. The first one is a switch. The second one is a proximity sensor, and the third one is a temperature. So let's get started with the first one. It will be event triggered. So before I start with the first one, I want to be talking a little bit about the wireless protocol system. So we are in today's world very familiar with two kinds. The Wi-Fi, which is like within a room, or the cellular, which is like 2G or 3G. So it's very important to know where is the device of the sensor and where is the kind of the central device that catches all these values. In the case of Wi-Fi, it is the router. So I have a little router here. So I've kind of flashed the firmware and connected it to the SSID of this little guy. And here is the router, and this is the sensor. So in terms of cellular, it is the huge cell tower. Now what's happening in the last few years is this. We are having more and more chips, which is the connectivity chips available to us. So this is an example of a photon, which is a dev kit. And over here, I have a Wi-Fi chip made by Broadcom BCM. And it's all done up for you in a tiny little PCB that you can explore. I have another example. This is based on the ESP826s. It is a sub-$3 USD chip. Wi-Fi connectivity. Once again, it's available as a dev kit. Same thing you see in the cellular device. Now the best part is the cost, of course. Whenever an innovation becomes more prevalent, is the cost. In terms of Wi-Fi, you can use these sort of little dev kits in sub-$20 USD. Of course, sensors and all, you have to pay a little bit more. And in terms of the cellular connectivity, it's about $70 or $80. But just like our mobile phone, you need a data plan. And cellular is important, you know, because not all our sensors will be in the room. It might be in the urban, in the gardens, or something like that. So I hope that you gave a little bit of a background about what kind of wireless connectivity we are talking about. So let me go on to the very first example. So this is the first example I have here. As I said, I have a little switch here. So if you see this switch here. And this has an STM32 microcontroller. The switch is connected to the microcontroller. And that's where I flashed the C program to kind of say how it will communicate. And then, of course, it has a Wi-Fi chip on board which is talking to this little router here. All right, so that is the thing. And with this Wi-Fi, it kind of talks to my Ruby on Rails server which is running in my laptop. All right, so are we ready to see what it does? Okay, so I'm going to go here. And this is completely wireless. So let's see, I'm going to turn it on. Let's see. Of course. All right, so let's go on. And I'll show you the channels this time. It's going to the switch. So this is where you will see the public switch here. The public view. So this is how... Let me see whether we got it. No, we didn't get it. Oh, well. Well, even if you don't get it, I'll come back here and then I'll show you the channel settings. So what happens every time I turn this on and off? It basically communicates with the Rails server right here. And when it communicates, it gets a post request. So let me show you the API keys right here. So this is the API key you have here. And then the channel settings over here. You kind of set it up, and then you say that in this sensor node right here, you have eight different fields, and one of them is a switch. So let's turn back here. And this is the API key. Now let me move on and show you where this can be used, this little switch. How many of you have heard of Amazon Dash? Many of you. So this is actually using the same Broadcom Wi-Fi chip as the Amazon Dash here. So what it does, every time you kind of switch or push the button, it connects to your router at home, and it basically creates a line item in the e-commerce cart of your Amazon. And the cool thing is, a few months ago, Amazon even released the IoT button. And the IoT button is available as a developer kit, so go ahead and play with it, AWS IoT button. So that's a brief about this, but I want to go to the firmware and the Rails code where the communication happens. So I've basically kind of flashed the firmware right here. And even though this is C code, I wanted to notice three things about this. Firstly, we have slash update. Secondly, we have the API key right here. And thirdly, we have the field, which is the on and off of the field. And of course, it's communicating to the whole thing, which is my laptop here and the port. So with these three things, let's go on to the Rails. And this is something I think all of you are familiar with. So what happens in Rails with slash update, it goes to the routes RB. And it is kind of defined as channels, model, and then the method is post data. So when it gets this data, it creates a new feed. So feed is also a model. And of course, it checks the API key, and then field one, it kind of creates one line off the feed. So that's the meat of it all. So let me go to the second example. That is the periodic part of it. And this time, it will be not triggered by a human being with switch, but it will be triggered by proximity or in terms of every interval. So let me go on to show you this little thing. So here I have a very similar case. So this is the ultrasonic sensor that you see here. And ultrasonic sensor basically means that when you have a line of sight obstacle, it can measure a distance. And this is a little different. Previously, I powered it up with a power bank, but this time I'm powering it up with a LiPo battery. So if you kind of sleep and wake it up every few hours, this can last for, let's say, a month or so. So this is an example of a proximity sensor, but it will not be triggered by me this time. So let's see an example. So I'm going to go to the channels, and let's see, proximity. Let's go to the public view, and let's see what's going on here. And let me turn it on. Let's see whether it works, even if it doesn't work. Well, oh well, it doesn't work. All right, but I will show you something. Let's see once again whether it works or not. No. All right, so I'm going to show you right here. And this part, I want to show you the data. So if you click here, now Thingspeak will give you how you can able to kind of communicate with it. So if you want to do a post request, you can do a slash update here. And this is where they will actually generate the URL to write in the firmware and communicate with the rails. And then this is the feed JSON that you can see here. So I think it might work. Let's see, why is it minus? Ah, it is working. So you see here, it's minus one. Let's wait a bit. And you see 17. 19. All right, so a bit far away. And there you see. So if we come back to the graph right here, number one, if you go to the public view, there you see the plots are being charted with this little guy. All right, wait a bit. Probably have to be very, very near. But you see if I show you one of the queries that it's kind of working with, where is it? Right here. So this is an example of a post request that's being done with the field. It's minus one, it's very, very nearby. So there you see, it's giving minus one. So it kind of updated the chart. Now in this example, let's look at the data here, because IoT platform is all about data. So what I'm going to do is I'm going to export it to CSV file. And as you can see, minus one, minus one, and then 19, and then minus one right here. So it's immediately available in your CSV format. And of course, it's also available as JSON right here. So let me go back and explain a little bit about the rail structure. So ThinkSpeak uses things like device, and whenever gem, and many of the gems that we are very, very familiar with. But I'm going to be talking about three models that are very, very specific for IoT platform. One of them is something called a channel. So channel is something like, this is a sensor node. So it might have one or more sensors. So all these are related to one channel. The second thing is all about the feed. So whenever this sensor or more sensors kind of transmit something, it will record in the database as one feed item. And lastly, of course, is the API key. So let me go and also say that API key in the terms of ThinkSpeak is basically a 16 digit alphanumeric number. And finally is the feed controller. And this is where the data, the meat of the matter is, the data. Here, ThinkSpeak, which I think is really good, is kind of exporting five different types of data. HTML, of course, is for the view. JSON is very important if you want to be using it and kind of hooking up with APIs with other types of applications. And of course, there's CSV if you want to download and do some spreadsheet manipulation and of course text. So let me talk a little bit about applications. So yesterday, if you remember Godfrey's talk, he spoke about SmartCan. So it's the same thing here. So imagine what can happen if you put a proximity sensor, not in a garbage can in a room, but let's say in the huge garbage can underneath the buildings. And there are many of them and public utilities, personnel comes and collects the garbage. And wouldn't it be better if each of these has a little bit proximity sensor connected to a cellular communication and it just gives a ping when the distance becomes smaller than a threshold. And then it says that, hey, you know, the logic six people or the public utilities people, go and go to this area and these are the exact containers, garbage bags that needs to be emptied. So that's the application, the practical application of this. So I have based my example a lot on Thingspeak. Now there are nine platforms I've played with and I think you can also play with it. You do not need to install Rails or anything. These are all hosted platforms and there are nine of them. And whether you say IBM, Microsoft, AWS, Google, they each have an IoT platform of their own. And out of these, guess what? Two are made of Ruby on Rails. So you can imagine some of you in this audience in a few years will be part of an IoT platform building team, working with electrical engineers on the other side and interfacing with the sensors while you all will be working to collect the data and make sense of it. So Adafruit IO is one of them and they also are basing their platform out of Ruby on Rails. I also want to talk about standards that are being done because standards are so important because right now IoT is a very, very new technology. There are so many messy things going around. It's crucial that we also follow standards and follow the conversation. So there's Web of Things standards by W3C. I love to subscribe to their mailing list and kind of look at what they're doing. They will talk about API endpoints and RESTful URL, things that we are very familiar with it and also some new terminology. So go and subscribe to their mailing list. So this is the last example I'll be giving. And this time I'll be using a temperature sensor. And instead of HTTP, I'll be using MQTT. So how many of you have used MQTT? So that's like the last layer of the application stack of the internet protocol. And if you use MQTT, that's awesome. I see a few of you, like about five hands in the audience. So before I go on to the example, I want to explain why MQTT. So like I said, HTTP, MQTT, or even FTP, DNS, these lie on the top layer of the application layer. And MQTT and Co-App are becoming increasingly important for machine-to-machine, low-power communication. And the exchange model is a little bit different for MQTT. It is based on publish and subscription as compared to HTTP, which is a request and response. And I think as web developers, we are very familiar with this. So what publish and subscription model does is that you can do a many to many propagation. So you can imagine many sensors connecting to a single MQTT broker, and that kind of publishes or subscribes to other Rails servers. Now here's the interesting thing. Why is MQTT and Co-App especially suited for low-power sensors? Two reasons. Firstly, look at the header size. HTTP has a huge header size as compared to MQTT or Co-App. And secondly, HTTP is also based on ASCII or text, whereas MQTT and Co-App is based on binary. So that really, really does a huge effect on your battery. So remember, I said, if you're doing a prototype, you're having it at home, sure, you can plug in the battery power and kind of plug it back. But if you're trying to do something urban, like in a waste management system, you have to ensure that the battery probably lasts in the order of years. And that's where using protocols that are made for low-power sensor systems, machine-to-machine communication is so important. So let's go on to the last example, shall we? Here I will be using something different. It's not photon. It's based on ESP8266. And it is the first sub-3-dollar USD chip. There's a Wi-Fi chip, so I have a little temperature sensor here. What do you think is the temperature right now when I'm going to on it? Any numbers? 19. 24. 22. Who is right? Who is right? Let's see. So I'm going to go here and go to my channel. All right. And let's see. So once again, I'm doing it every three seconds, but in reality, probably you want to be doing it every three hours. So let's see. I've oned it. Oh, there you go. It's happening. You know the stage is a little warmer, I think. So there you go. So it's about 24. Who said 24? Winston. Thank you, Mr. I owe you a drink anyway. Thank you for what you did for the community. All right, so that's 24-23. And so one thing about data is that you might want to have a huge dashboard in your office, and that's where WebSockets come in also very handy. So once again, it matters what you do with the data. So I want to talk a little bit about MQTT. So in terms of MQTT, like I said, it is a publish and subscription model. So I'm running a Mosquito server, which is an MQTT broker in my laptop here. So once again, I have already kind of flashed a firmware in my microcontroller here. And the firmware, so here you will also see how the MQTT protocol works. API key slash field, which is very similar. And then, of course, I'm going to my host, which is my laptop right here. And I'm basically doing a client publish. And it's, of course, talking to my router here. And then my rail side will basically subscribe to this MQTT sensor value. And what it does is it will also check exact value, the API key, and the field. And just like the HTTP way, we will create a new feed for this every sensor value. So application. I want to be talking about application. How many of you have seen your home meters? Home power meter. Everybody has one. How many of you have seen it? All right. That's about 10% of you. This is how my home power meter looks like. And by the way, I moved into a new house. And this is the latest, I believe. How do you think meters are red? Pretty manual nowadays. I think they are trying to do it automatically. But I think by and large, it's pretty manual. And this is, you see, it's 2015. This is by last year. But imagine one day, we add a cellular connectivity to this. And every few hours, we just send this tiny little value from your home power meter to your power's utility. And from there, it just propagates as data to all your accounts or all your mobile phones. Imagine how much aware we will be of the energy we are using in every day of our lives. I think that has an impact directly on our behavior and the planet we care for. So IoT, IoT platform, at the end of the day, it's all about data. Sure, we can go and plot charts about it. It will already give a visibility of our usage of our consumption. But what are we going to do with the data is an even more important question. Are we going to stop something, reset something, do a physical manual deployment to the site, notify social media, trigger a rake task, generate a PDF, create an email, trigger something, or change something about ourselves. At the end of the day, IoT platforms have a huge impact on every possible industry around us, whether it's logistics, energy, transportation. And so I thought I should end with a quote. The wheel is an extension of the foot. The book is an extension of the eye. Clothing is an extension of the skin. Electric circuitry is an extension of the central nervous system. The extension of any one sense displaces the other sense and alters the way we think, the way we see the world and ourselves. Let's explore the senses around us. Thank you so much. I would love some questions. Can we have some questions from the audience, please? Are you doing this sort of work professionally right now? Currently it's a hobby. And that's a great question. This graph I showed right at the beginning. So I feel in terms of IoT, we are kind of at an inflection point. And if you remember the era of web or personal computing, there were a lot of hobbies that got started first, and then the industry kind of came together. I said there are a lot of industry protocols being made, but I'm personally doing it as a hobby. Hope to make it a career out of one day. But you know as engineers, that's what we do first, right? Anything new, just go on and have fun. Thanks for the great question. Any other question? Hello. Hi. Okay. I'm a beginner to trying to hack in my way to some stuff. Can you suggest any starter kits to get started? Yes. So you see my slide link here at the end, right? And I have three more slides here. I've linked all the hardware links here, because that's the most frequently asked question. So I would highly recommend you to go to Adafruit or SparkFun. Like I said, there are dev kits here, and it will be so easy to just get started just for yourself. Yeah, check out the links here. My slide link is also here. I hope, if not talk to me. Okay. Thank you. Yeah. Any more questions? Well, I have one comment. Yes. So Sao Xiong, our keynote speaker from yesterday, works at Sing Power, and I would love to have him attach our power meters to the cellular network so that we can hack it. You can tell him. Okay, Sao Xiong has a comment. He started it. So you're going to bring me in again, right? Anyway, I just want to tell you that in the Singapore Power, we have already rolled out like 100,000 smart meters around the island. They are connected, and it should be rolling out to the rest of the island in the next couple of years. So it's going to come true. No more manual. Thank you, Sao Xiong. Thank you. Thank you, Sao Xiong. Thank you.