 Hello everyone and welcome to my presentation, JavaScript-powered smart home with almost no code. So today I'm going to talk a lot about IoT devices. I'm going to talk a little bit about code, but mostly I'm going to talk about how you can avoid doing code. Not that as software developers, that's actually what we usually want to do. We usually like to write some code, but sometimes there are shortcuts that are really nice to use. So let's start by talking a little bit about IoT devices, and why should we care about them? I mean, sure, we've all heard about different internet-connected things, but I don't know if you've ever realized the amount of IoT devices that are available out there. It is actually expected by 2025 there will be 75 billion devices that will be working and will be connected to the internet. That is a lot of devices. And I was looking at that graph and I was thinking, how is that even possible? So I charted with the world population, trying to see if the world population followed the same trend, and not at all. I mean, it's just that we tend to have more and more devices. As a matter of fact, I looked at the number of current devices, which is around 50 billions, and divided that by their current world population, and that gave me something like six devices per person. But there's no way I have six connected devices in my home. So I started thinking a little bit. Okay, well, first of all, I've got two laptops. We've got a laptop for the family. My wife has her home laptop. So that's four connected devices. Of course, we each have our cell phones. And this is a household of two. We each have a tablet. Now, some people might argue that those are not IoT devices. They're connected to the web, but they're not IoT things per se. So I started thinking, okay, well, do I have any connected devices? Well, I certainly have a thermostat. Oh, right, I've got my smoke detectors. So I've got two of them. I've got, oh, I've got a smart TV, which is also connected on the internet. I've got, well, I've got some smart bulbs, which I'll get back to that. They're not that great. I've got some connected plugs. I've got three of them. I actually use them to turn on and off my Christmas lights and various things outside. And I've got connected speakers. So my speakers are connected to the internet so that they can stream music. And all right, my home assistants. I've got a bunch of those around the house. So I've got three of them. My door locks. I've got, yeah, front door and back door. They both have smart locks in there. And I have a vacuum, an internet connected vacuum because, well, you know, everybody wants to start the vacuum when they're not at home. So I started counting at that. And that's like 18 devices. That's nine per person. So I guess for someone who thought I didn't have that many, I still do have a lot of them. So IoT devices, why shouldn't you care? Well, probably because they're all over the place. And you probably have a bunch of them at home. And in your professional career, there's a fairly good chance that at some point you'll actually have to deal with some IoT devices. So this is what I'm going to talk about today. So hi, my name is Joel. I work as a developer advocate for MongoDB. If you ever want to get in touch with me, Twitter is always, always, always the best way. So Joel underscore, underscore, there's two underscores there. So Joel underscore, underscore, Lord is the way to reach me. You know, just to talk about anything, whether it's databases, connected devices, or just to say hi, if you've enjoyed this presentation, feel free to tweet. I always appreciate a Twitter notification. So before we get started, and before we jump into our actual topic, I just wanted to let you know, and just to take a second to talk about this, I'm a hacker. I like to tinker with stuff. I have a bunch of little connected sensors and various microprocessors that I just enjoyed that type of stuff. But I've never worked on a professional project with them. So whatever I'm going to say here, those are my opinion. I mean, there's definitely probably, most likely, better ways to do things than what I'm going to introduce. But if you want to hack around it and play around, I think that there's a lot of the content that you'll find here that can actually be interesting. Speaking of content, this is what I'm going to cover today. So I'm going to talk about IoT and JavaScript. So how can we use JavaScript to build IoT stuff and connect devices to the world? So we're going to look at that. Typically, we tend to think about C++ to build embedded stuff, but it turns out that you can actually do pretty a lot of cool stuff with JavaScript. I'm going to talk about local interfaces as well. Low code is kind of a trending thing. We see more and more of those interfaces where you don't actually need to code. And finally, I'm going to introduce you to IoT and low code. So I'm going to show you how I've managed to solve a few of my problems around my home by using both some IoT devices and some local interface. So IoT and JavaScript just like PB and J. As I mentioned already, we don't always think of JavaScript as the main language to program various devices that will connect to the internet. We tend to think of C++ typically, but it turns out that you can do a lot of things. As a matter of fact, just a few years ago, I was at a presentation where I had the privilege of presenting this tiny robot that was controlled by a Kinect sensor that you can see right there. It gets my skeleton and I can do gestures and the robot would fly off. So I was able to do all of that using JavaScript. So all the Kinect sensor, the detection of gestures, the actual little robot there, everything in there is all built with JavaScript. Let's see that again. There it goes. Okay, so getting started. How do you get started and start programming different devices using JavaScript? Well, I'm going to talk about many two different devices that you can use for IoT to get started, the Esprino and the Raspberry Pi. The Esprino is this tiny little device right there that you can see. It's based on the Arduino open hardware. A few years back, we talked a lot about the Arduino. There were ways to use the Arduino with JavaScript, but that wasn't really easy. The Esprino really, you can use JavaScript out of the box on the microcontroller. It uses the ESP8266 chip. That is a programmable microcontroller that also has a Wi-Fi connection on it. So this tiny devices goes for about 35 Canadian dollars, I think at the moment. So you get them for pretty cheap and you can do some really powerful stuff with that. So the Esprino Wi-Fi is the one that I've just shown you is a tiny USB and Wi-Fi enabled microcontroller. That can be programmed in JavaScript. So just plug it into your computer and get started in seconds with the Web IDE, no software installation needed. So that's from the Esprino website. You can find out more information there and that's actually one of the places where you can actually get your devices. So this is what the IDE looks like. So you can actually, there's a website, you can just go to that website and in theory you should be able to connect to your sensor. Now this one is running inside my presentation, so inside an iframe, so it gets a little bit tricky. But I actually have the IDE right here, right in the back. There it is. And I've got this little code that will just blink a LED. I've got a little tiny microcontroller right here that you can see. Let me just make that a little bit bigger. So you've got the microcontroller here. So what I can do from this UI, I can actually connect. I can connect to my Esprino board. There we've got it. I'm missing a semicolon here, thank you IDE. And now I can flash my device. Now that I flashed the device in just a few seconds, you should see the LED starting to blink. Pretty cool, isn't it? Yeah, so there it is. And we also have the status so you can see right there in the IDE, the status being updated on whether the LED is on or off. So that's a very tiny little example. That's kind of the hello world of IoT devices. Of course, I wanted to build some things a little bit more complex. And we've got here, you might have noticed that I do have something connected to it which is this tiny sensor right here. It's a temperature sensor. If I just go ahead and of course, I won't write all of the code for it but I'll just copy and paste this code here right here. And I can flash my device again. So next time that it starts, it will actually have that code on it. And what this will do is it'll actually connect to my Wi-Fi and it will, now you have my Wi-Fi password, there it is. And it will start making a call to a UI, so to a URL, so this URL right here. And I'll get back to that in just a few minutes. So now what it's doing is that it's actually just getting the temperature and humidity levels and just sends that over the Wi-Fi connection. All right, so let's take a look at the original code that I've shown you. So this is the blink, so the hello world of IoT devices is always a blinking LED. Usually there's a LED available on board that you can use. That is true for most little microcontrollers that you have access to, as well as the Raspberry Pi's or some versions of it. So the other microcontroller that you can use is the Raspberry Pi, and I actually have one right here, I'm not sure if it will let me just disconnect, nah, I won't disconnect it because it does take a few minutes to reboot but this is actually the actual picture of my Raspberry Pi. So that's the Raspberry Pi 4, which was just released recently. And Raspberry Pi's are actually a tiny dual display desktop computer and robot brains, smart home hub, media center, network, AI core, factory controller and much more. So that's also from the Raspberry Pi website. But basically what the Raspberry Pi is, is that it's a tiny computer on a board and it's tiny, it's about this big, it's very, very small and it's very powerful. That little device has eight gigabyte of RAMs, it has a hard drive that you can add afterwards, it uses an SD card for that. So it's a tiny computer that you can use and it has a bunch of little pins that you can use and connect devices on them or sensors or different things. So in the case of my tiny device here, I've actually plugged a LED on it and let's actually take a look at some of the code. So in order to be able to, oh, and another interesting thing, and let me actually show you the UI very quickly. So this is my Raspberry Pi and it's connected right now. And you can see that it's a computer, it runs Linux, it runs a version of Debian and it actually has Node.js pre-installed on it. It actually has a bunch of little tools that you can use. But you can see here that I have a terminal window and I can actually use it to do some different things like I can edit some code. This is my blinking code. I'll come back to the actual coding here in just a few minutes, but then I can actually run this code and run this, whoops, not this one, but I can run my Node.js application and it will just start blinking my LED pretty much similar to what I did with the Esprino as well. So in order to be able to program on your Raspberry Pi, you will need two libraries. You'll need Johnny 5. You actually don't need Johnny 5, but it does make your life a lot easier. And Raspi.io or Raspi.io that will be used to control the different pins on your Raspberry Pi. The code that I've just shown you in my terminal was exactly this code. So first of all, you required the Johnny 5 library, required your Raspi, and then you just initialize a new board. Now it's an event-driven type of programming. So you will have events like board on ready. This tells you that the board is initialized and ready to use. Once it's ready, I can initialize or declare a new LED. So by using the pin number, then I can use the method blink and it will just start blinking my LED. All right, so what should you use? An Esprino or Raspberry Pi? Well, they're both pretty cool. Actually, they're both pretty amazing little devices, but they do have some very different use cases. The Esprino is great for being tiny, tiny, tiny and I can just easily connect a little sensor on it. And there you go. I can just put that. I can connect the battery on it and just throw it somewhere and forget about it. And it just works and it's very, very power efficient. So I can just forget about it. The Raspberry Pi on the other hand, not as an energy efficient, it's actually a full computer. If you need to access it while you'll need to connect a keyboard on it, then you'll need to connect the display on it. But it can be very useful. If you wanna build a media center, then you can actually use that Raspberry Pi and then you can use those external pins for additional sensors or to add different little things to it. So it really depends on your use cases, but both of them can be very useful. All right, so I've talked about IoT devices. Now let's talk about the local movement. What exactly is low code or sometimes called no code? Well, local development platform provides a development environment used to create application software through graphical user interface instead of traditional hand-coded computer programming. A local platform may produce entirely operational applications or require additional coding for specific situations, enabling accelerated delivery of business applications. All right, so why should we care, right? We're software developers, we know how to code, so why should we care about local interfaces? Well, there's a few good reasons for that. Mainly you don't want everybody to rely on you as a software developer all the time, right? So sometimes you can use local interfaces to make it easier for other people in your team that are not as technical savvy to be able to contribute to your project. So using a local interface you can give access to some sort of reporting tool to your managers and then they'll be able to just, you know, add new sources of incoming data and they'll be able to generate new charts and stuff. So local interfaces can be very, very useful for that type of thing. But it can also be really helpful when you're building IoT ecosystems and you need different interface and you don't want to build everything from scratch every time. So there's a lot of tooling that you can actually use to help you with that. I'm gonna talk about two here, there's a lot more. IFTTT is a product that is available really made for makers, it's really, really simple to use. And I'm gonna talk about Node-RED, which is a project that I've recently discovered and I think it's an amazing product and definitely worth talking about. So IFTTT helps all of your apps and devices work better together. It makes it easy to build applets connecting various services. So you can find out more information on ifttt.com but what does it mean? Well, basically you've got if this then that so that's the IFTTT. So you can just create, connect a bunch of different services so you can say things like, well, if I've got a new follower on Twitter then start vacuuming. And that's actually running on my IFTTT account. So if you wanna follow me on Twitter you'll help me to have a clean floor cause it'll start my robot. But most of the time it's actually a fun thing. So I just know that I have a new follower when the vacuum starts. So you can see the type of services that then there's a lot of different services that you can connect to and you can see how you can just integrate each one of them together and create some of those flows. The other one that I wanted to talk about and actually just before I leave let me just switch back here, not here but I actually had my little, a tiny little device here which is probably still running. I don't have any, oh yeah, yeah, I just saw that link. So in a minute it will do another readout on my temperature sensor and it's actually connected to IFTTT as well and I forgot to put it. So let me just push this window right here and every time that it gets a new event every time it detects a new temperature so every minute or so it actually inputs a new day, a new row in here so I can actually see that the temperature right now is 27 degrees. It's a little bit hot here today. That's Celsius and 45% humidity. And if we wait and if I just talk a little bit more and I'm not sure what I'm gonna say but in just a few minutes you should see another row being added because it'll do another reading every minute. Should we wait? There it is, coming. Meh, let's just leave it there. I'll put it in the background so we might be able to see it in just a few seconds. All right, so let's talk about NoRED. NoRED is a programming tool for wiring together hardware devices, APIs and online services in you and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed in a runtime in a single click. All right, NoRED.org, you'll find more information there. By the way, I was very excited but I didn't want to start reading but you saw that I got a new reading while I was reading this little presentation here. Okay, so back to my presentation. NoRED, how can you get started with NoRED? Well, if you have Docker installed, it's actually very easy. Just run this command and you're good to go. So it starts a web server on port 1880 and it will have NoRED installed and ready to be used. So what is NoRED? Well, this is the UI. So if you are running, and I'm actually running it in Docker right now and so you can see that I have it on localhost 1880, what can we do with that? Well, there's a lot of things that we can do. So first of all, let's start with the basic Hello World type of thing so we can inject something. I'll try to make this a little bit bigger. So there you go. And then I'm gonna use a debug statement. So a little bit like, you know, when we do console logs, when we were trying to do some JavaScript programming, I wanna see what's going on. We can use the debug right here. So we've got those two nodes. I can link them together and let's actually change here. So we won't send a timestamp. We'll actually send a JSON object. We can use the visual editor. So say I'm not, you know, very familiar with JSON or JavaScript programming. So I can say, okay, well, we'll send a message and the message will be Hello World. There you go. So I'm gonna send a message Hello World. And in here, I'm going to debug the payload. So I've got my debugger up and running. So right here, you should see messages. Let's deploy this application. There it is, missing Twitter credentials. Ignore that for now. But we can see that whenever I trigger this little node here, so I can click on the button and we get the message Hello World being displayed. Pretty cool, isn't it? Well, okay, well, maybe it's not that cool, but there's a lot of things that we can do with that. We can say, well, okay, let's change this and say we'll trigger Hello and we'll add another field. So let's use the visual editor again because I think it's pretty cool. Actually, let's just use the JSON. And we'll, you know, person will be Joel. So now we can send this object and we can still trigger it. Let's just deploy this again. We can trigger it and we get this new JSON object so you can see that there's a little bit more information in it. So that's good so far, but we can add a switch. And now with my switch statement, I can connect this to my switch and I can say, well, if it's equal to Joel, you know, output to node one and anything else. So if it's different from Joel, do something else. And let's not use message.payload, but message.payload.person right here. Okay, so now this should be triggered. Let's remove this link here. I'll add my debugger at the end. And in another case, we will create a function and let's open this. We will change the message. We'll say message.payload equals message you are not Joel. Okay, so I've got this new payload and now I'm going to output this as well to the same node right here. So if the person is Joel, it's going to output directly the exact payload. And if it's not, then I'm gonna output some other message. So let's deploy this application. There it is, let's click on this. Hello world, this worked. Let's actually change the name of the person to someone else, someone else. There you go, redeploy the application and boom, you are not Joel. So there you go. So you can start to create those more complex flows and you can start to add some conditional statements and so on. Another interesting thing that you can do is that you can actually go to manage pellet here and you can search for different things. So say you want to connect to Twitter. Well, you can actually go to Twitter and add the node red Twitter node. So that's a node that enables you to talk to Twitter. As you've seen, I already have it installed but my credentials are not valid here. If you want to connect to a MongoDB database, well, you can use the one right here, which is installed and it's a node to communicate with a MongoDB database which is pretty interesting as well. So we can actually go in here and I don't know if you want to give access to someone to your application or to build applications and you want to show them how to, or you need to show them how to connect to a database. I mean, that can be complicated. What I'm gonna do here is I'm going to add a insert operation on my MongoDB database which is already configured in the collection flow data. So there it is. And now whatever is the payload of my message, I'm actually going to just send the payload directly into my database and that should add a new statement to my database. So let's deploy this. We can see that we're connected and now if I trigger this whole flow, we can see that it worked. And if I show you, I actually have an interface to manage my MongoDB database right here. And we can see that we've just got our payload that was added right here as a message person, someone else as I've just typed. And if I change the inject here to actually say hello to Joel instead, there you go. Re-deploy this application, re-trigger this application and we should be able to see a new entry right there, hello world person, Joel. Cool, so you can start programming your applications and maybe you start to see where this can get really, really powerful. So it's really easy to integrate a lot of different services together into this application. So I'm already able to add some information into a database, do some conditional statements and all of that in just a few minutes on a graphical interface. All right, but the whole thing, the whole goal and one of the things that really led me to this presentation was I have some smart devices in my network, but they're not really that smart. I've already hinted at my smart bulbs and there's a few cases. So I wondered if I could make things a little bit smarter by using those technologies. So some of the problems that I have, the thermostat temperature is kind of inconsistent. Well, not that it's inconsistent, but it's in the middle of the hallway. And when we sleep at night, well, I like to keep the temperature a little bit lower, but I want to measure the temperature in the room, not in the middle of the hallway. My smart bulbs, they're great, but I actually have to open up my phone and press on, on or off, which is kind of annoying. I'd rather have a switch in that case. I managed to connect it to my home assistance, which this definitely makes it easier, but what if we could make that a little bit smarter? My air exchanger, I've got this big, huge devices, device that exchange the air, but it's a stupid device. Actually, there's a switch that I need to flick to, on or high or off, so not that great. So I wondered if I could make that a little bit smarter. And of course, my plans, they're not connected to the internet. So I figured, what if I could actually do that? Well, let's go back to our Node-RED interface here. So first of all, for my thermostat, what I did here is that I actually have exactly this type of device. So I've got my ESP, or my Esprino, connected to a temperature sensor, and it just sends the temperature every minute or so to my temperature sensor, or to my Node right here. So that's an HTTP, it creates an HTTP endpoint that I can actually ping. And then I'll check for the hour. So if it's during nighttime, then it will actually move on or check the time. And if it's not during nighttime, it just ignores the request. But if it is, it'll check the current temperature and based on the temperature that the sensor picked up, it'll either turn on or off. So it'll set the value one or zero, and then it will send an outgoing request to another web service. And of course, I wanna save that into my Mongo database as well. So you can see that I've just created this whole flow. And now, thanks to this tiny little device that was programming JavaScript and this little flow that I've just shown you, I can now control the temperature based on, depending on the time of the day, and I can actually pick up the temperature in my room instead. For my lights, well, I didn't really care about turning them on or off. What I wanted really was to end their exterior lights. So I wanted to base that on the sunset. So I've added this little node here, sun event inject. And this actually happens whenever there's a sunset, it triggers this event. I wait for an hour, because I want about an hour after sunset where it's really dark, then turn on the lights. And I use this trigger node here, which is really cool. It'll actually trigger something and then it will wait for four hours and then it will trigger another event. So the first time it has a one, the second time it has a zero, and then I'm able to send an HTTP request to my service that controls my lights using IFTTT, and it will turn it on or off based on the value that I've just sent it. Of course, same thing. Also save that into my database so I can actually see what's happened. It helps me to debug when I see or notice that, oh, the lights didn't turn on yesterday or things like that. My air changer. So I added a tiny little relay on it. So I'm actually able to turn it on or off now. And now I use an intro valve. So every hour I started for about 20 minutes. I do that only during daytime. So I don't want to do it at night because it's kind of noisy. So I do my check time as well. It's similar to what I did earlier. I triggered for 20 minutes and I just send the HTTP request to my little relay that I have plugged on my device. Now, if I have a, or not if, but I do have a little air quality sensor as well that I have in my kitchen. So if I burn something, the theory is that, but that never happens, right? So, but if I do, the theory is that it will actually send a request right here to this bad air URL. And that will actually trigger another 20 minutes of my air changer. So it will automatically clean the air in my kitchen. And what else do I have? Well, of course, my plants. I wanted to know when to water my plants. So I've added a little hygrometer that I put in with an aspirino. I changed the range. So it sends me a value from zero to 1,024 or 23. I changed that from zero to 100. And then based on the critical amount of water that it needs, whether it's under 25% or under 10%, it'll actually either send me an email or send me a tweet because I, you know, I'm more often on Twitter than I am on my emails. So it actually sends me a tweet when it gets critical. And then I save this event to my database again. So you can see how I can connect all those different services. I can send emails, connect to Twitter. And there's a lot, a lot, a lot different things that you can do with Node Red. And that's just, you know, a little preview of what it can do. So IoT and JavaScript. Can you use IoT with JavaScript or JavaScript with IoT devices? Well, it turns out that you can. It actually works out really, really well. It's nice because I don't have to learn new language. I don't have to learn anything new. I can just use my current knowledge and immediately start programming IoT devices. Local interfaces, really fun for a lot of different things. If you want to, you know, make it a little bit easier for different people to be able to add and contribute to your projects, then that's definitely a good way to go. But it's actually a lot easier as well than to have to program all of it. So IoT and local, they go well together, especially that this one is really event-based. So it waits for incoming HTTP requests and it just works so well with the whole IoT ecosystem. So this is what I had for today. So thank you very much for attending. This was my talk, JavaScript Power Smart Home with almost no code. There's a little bit, but not too much. Thank you very much for being here. And if you want more information, easy URL to slash JS no code. And you can find me on Twitter at Joel underscore underscore lord. Thank you very much.