 Perfect. Aijo, how are you? So good. Thanks for having me. This is great. Perfect. I'm so happy to have you here. I'm very excited for this talk, and I will let you take it away right now. Love it. Great. Okay. Let me share my screen. Y'all, there we go. I'm going to sing till I get my screen on. Love it. Okay. Thank you. All right, y'all. This gets started. I got like 30 minutes here to like whiz through the fundamentals. So let's do it. Okay. This is an introduction to IoT or the Internet of Toilets. Or in other words, how I built an Internet-connected kitty litter box using JavaScript in my free time. All right. Jump in. Why does this matter? Why the heck are y'all here? Well, did you know IoT is kind of a big deal? I don't know if you knew that, but it really is. And it's just getting bigger. I think we're seeing more and more devices get integrated every single year. And we're seeing more and more ways to start programming with those. I'm sure some of you have an Alexa or Google Home or a smartwatch or whatever. I think that trend is not stopping anytime soon. I do want to say I think some of the trends probably are a little overblown. Whatever. It's fine. But I do think that generally speaking, the trend towards Internet-connected devices is not going to stop anytime soon. The more you know. Okay. So who am I? My name is Joe Carlson. I work for a little company called MongoDB. I'm a developer advocate and software engineer. If you want to hit me up, best way to do that is on Twitter. I make funny videos on TikTok if that's your thing. If it's not, who cares? That's fine. If you want to follow along with any of the slides, videos, resources, links, schemas, source code, whatever, you can go to that little short link there. Or you can scan that little thing in the upper right hand corner, that little QR code. If you ever see that QR code, it's just going to take you to a page with all the resources. So I hope you take advantage of that. Last but not least here, if I say anything controversial today, just know it's me and not my company speaking, these controversial things. I'm just begging you, please don't get me fired. I really like my job. Okay, great, let's jump in. So why should you listen to me? I love making internet-connected devices. This is a little magic mirror I built. It's a two-way mirror, Raspberry Pi, and a refurbished computer to monitor. I sold for my old job, but it shows me calendar, stats, when listening to Spotify, weather, New York Times headlines, and gives me little affirmations, which I need. I have low self-esteem, so I tell my computers to make me feel better, which works. Another fun project I have is my Moodlite. These are 3D printed panels. If anyone's familiar with the Nanoleaf, they're super expensive. It's like 300 bucks for nine of those little things, so I decided to build my own. There's a little web-connected panel in there, so I can actually control the LEDs, you know, just from my web app, which is dope. Anyway, I built that, which is super fun. Okay, again, if you want to follow along, please go check with that link, scan that QR code. You'll love it. Okay, what are we going to talk about today? A couple things. I'm just going to introduce IoT. We're going to go really fast through it. I think most of you guys know about what IoT is, if you're here. I'm going to talk about why you should be considering using JavaScript for your next IoT project. I want to go over some data-best practices for IoT. I want to go over a practical project, my IoT kitty litter box, and I'm going to make wild speculations about the future of IoT and tech. So stick around for that, that'll be fun. You can come back to this like six years, and we can all laugh and point to how ridiculous my claims were. But hey, it's fun to speculate, you know? Okay, what the heck is IoT? Is it anything you put a chip in, people? Come on. But I just want to talk about my favorite parts about IoT R and why I like exploring. I love exploring the boundaries of art and tech. I personally believe that is the artistic, like computers are the artistic medium of our generation. And the people watching this, we are uniquely qualified to explore this medium, right? I think we could do some cool shit with that. In particular, I'm interested in stupid shit that we can build. I love building stuff that is right on the border between being just completely stupid and kind of genius. I don't know. I think that's where creative ideas come out of. And I like exploring that. In fact, I like it so much. I ran a hackathon called A Stupid Shit in Terrible Ideas Hackathon. This is the website. People are building fun stuff. Someone made a web app that, someone made a six foot large fidget spinner. Someone made an app that only takes photos when they shake the camera, so it only takes blurry photos. It's just making fun stuff for their friends, just for us, you know what I mean? Okay, so IoT. I love it. I think it's fun. I hope you love it too. I hope I'm also going to inspire you to maybe explore some new IoT projects by doing this. But why should you be considering using JavaScript for your next IoT projects? I don't know. Let's find out. So did you know that 58% of IoT developers actually self-identify as no developers? Wow, that's a lot. That's a quorum. That's over half, baby. Did you know JavaScript makes a great choice for new developers? I bet you already knew that. But what you may not have known is that job or with IoT projects, traditionally you're using lower level programming languages like C or C++. This is just my opinion. I'm very biased in this regard. But I think that JavaScript is a much easier programming language to develop for newbies. You have to deal with memory management. There's a garbage collector. It does a bunch of cool stuff for RGU. There are reasons when you would want to make a project in C and C++ or low level programming languages like Rust. But if you're just getting started, learning a hardware is hard enough. Just like, why have to learn a new programming language on top of it? Just do, you know what I mean? Easy to update. Traditionally with low level hardware languages, you have to reflash that piece of hardware with your new binary code. You do not have to do that with JavaScript code. All you have to do is get pull an NPM install, and baby, you're done. You did an update. You updated your fleet of IoT devices out in the field, and you're done. You're done. It's easy, okay? JavaScript is already the language of the web. All right, baby. Cool, right? Let's just like keep it going. Why stop there? Let's just keep it going for IoT. Why not? Hey, and did you know there's a ton of existing libraries, tools, and frameworks that already exist to help you make IoT projects using JavaScript? Two big ones today are CylonJS and Johnny5. I personally built my project using Johnny5. I think it's great. Cylon is great. There's a bunch of others, though, too. You can't go wrong. Okay, and JavaScript is great at handling events, driven applications, right? We already have that. We have a whole thing called CBs or callback functions, right? On some sort of asynchronous event, you do something. It's a foundation of node. It's how we handle asynchronous events in the cut cloud. That's how we do stuff, right? And if you think about the architecture of IoT devices, traditionally how they're working, is they're waiting for events to fire off on some sort of sensor. Maybe you have some sort of luminescence event on a light sensor or some sort of moisture level to hit or some sort of carbon monoxide level to hit on the sensor before you want to trigger some code to run, right? The world is just a series of asynchronous functions we're developing code around. Also, events reduce the cost of listening to devices. It's just like we have a single-threaded event loop, right, which we just learned about. Cool, right? You can just reduce the cost if you can just like handle those events when they come up instead of listening and performing things all the time, you know? Oh, yeah. Thank you for posting. I've seen that's Joel posting stuff here. I'm going to post a link. These are the link to all of the resources included in this talk, so I hope you check those out. Okay, so let's do a quick recap here. Why IoT and JS? Most devs are already using it, 58%. Come on. It's super easy to learn from new devs. It's easy to update MPMs or get pull MPMs themselves super easy. Internet already speaks JavaScript. Let's keep it going. Tons of great libraries. JavaScript's event-driven, right? Which is how we architect IoT devices anyways. Okay. All right, so showing my cards here. I'm a MongoDB developer. I'd be remiss if I didn't mention data best practices for making IoT projects. So I'm just going to go over what we do with all the data and things that you, dear listener, should be considering when choosing your database, right? It doesn't have to be MongoDB, but these are just general things that you want to make sure you're considering when picking your next database. So first of all, your database needs to be able to ingest lots of data simultaneously. This is an engine I have a fleet of IoT kitty litter boxes out there, like a million. And all those are sending read or write data every minute back to my home server database. That's a lot of data. Like IoT data massively grows super quickly because typically what we're doing is keeping a time series data, which we'll get to in a second. It also should be event-driven, right? IoT architectures are by their nature event-driven. You want to make sure your database can handle that as well. Flexible schema. Hey, did you know MongoDB is not a schema-based database? It's actually a flexible schema database. You can actually enforce the schema from a database level and you don't need Mongoose. The more you know. But for example, with my project, I added a couple new sensors to my project. Cool. And I was able to update that easily using... What's the word? I was using MongoDB. So I added a new door sensor to tell when I open it. And I just updated my time because I didn't really care about my old time series data. So I could just add that new sensor data and it was not a problem. Super easy. IoT is a specially great use case for flexible schema models. Handles time series data. Typically what you want to do is build your schemas and your databases in a way that you're going to be digesting that data. And typically what we do with IoT devices is we make charts showing sensor data over time. How I built my time series data reflected how I wanted to chart it, which would be like, I want to see the number of times my cat goes to the bathroom a day, how many times it gets cleaned a day, and changes in my cat's weight daily over time. Of course, you can do some more interesting stuff for that too, but you want to make sure you natively can handle it. And I'm going to show you a little bit more about that in just a second. So anyways, I might be biased. I may be biased, but MongoDB is a great choice for considering your next IoT project. Something to consider, right? Does all those things super well and way more, which won't be able to get to in this one. Okay, so IoT best practices, quick review here. You need a database that can ingest data quickly. It should be event driven, just like the architecture of your IoT projects. It should have a flexible schema, so you can add or change sensor data easily. And with IoT time series data, it makes it, you don't really usually care about legacy data or like gets out of date pretty quickly. So it's a especially good use case for flexible schema. And make sure database can handle a time series database schema. Neatly. Okay, great. Let's get to the fun part, everyone. The moment we've all been waiting for. Let's get to something practical. Let's get to my IoT kitty litter box, the titular box. This is actually the box I built. I didn't build like the wood part of it, but it's a mid-century modern box. I know it's a little bit extra. I know it's a little bit extra. It's fine. It's fine. You could just get one of those $20 plastic ones from Amazon. Those are totally fine too. I just like it's out in the middle of my living room because I have one bedroom apartment. I don't have any rest to put it. It's whatever you want. You know what I mean? I know it's extra. Also a fun fact. This is my cat BMO, like Adventure Time. I don't have any Adventure Time fans here. But this is him eating the box while I was building it. Just a word of caution. If you have a cat, they will eat the wires. He's being a naughty boy. I had to get him out of there. But he's loving it. He's eating those load sensors in particular here, which we'll get into in a sec. Also, I know I mentioned I like the stupid shit. Turns out this is actually a real product. Wired gave it an 8 out of 10. And look at this. It costs $500. Why am I not monetizing this? I'm an idiot. I'm an idiot. I don't know what I'm doing. This may actually be a good idea. You guys could take this from me and monetize it if you want. I don't know. Whatever. It's open source. It's totally free. Do whatever you want. OK. So how does my box work? So you got your box, baby, right? What happens is I done a little door. Once that opens up, there's a magnetic sensor in it that determines when I open and close that. So when I open that box up, what I'm doing is either cleaning or adding litter to that box. And I tell you that that goes into maintenance. Right? So either I'm changing the weight of that box. I want to put that lid back on. There we go. There's the lid. The lid goes back on. What we do is we initialize the base weight of that box. So I basically have a smart bathroom scale underneath that box. And it just measures that base weight of the box. Then what we do is we wait. We just wait. We wait for an event to happen, which in this case is a cat-sized object entering that box. I don't actually know if it's a cat. It could be a raccoon. It could be a possum. It could be a small person. But I'm going to assume it's a cat if it's about it. 15 to 20 pound object enters that box. We wait to initialize a little bit. Right? We do some stuff. Cat does its business. Cool. But then what we do after that cat does its business, we record the event. And I passively measure my cat's weight. So when he enters the box, we have that base weight with a cat-sized object. I'm able to determine his weight every single time he uses that box. And I'd save that to a MongoDB database in the cloud using Atlas. Okay, great. So cat does its business. We record the MongoDB Atlas in the cloud, database cloud. Cat runs away and we reset and re-initialize for a new base weight after about a minute. I let it settle down a little bit. And then we just wait for a new event, either a new maintenance event or a new cat using the box event. Either or. I don't know. Okay, cool. If you want to check that code out, oh, I got to update that link there, but whatever. First step for building an IoT project is just making an LED blink. This is the me really building, making the IoT blink, or that LED blink on and off. And what does that look like? With Johnny 5, all you're doing is, Johnny 5 works with a bunch of different processors. I'm using a Raspberry Pi. So I bring in the Raspberry Pi package and I initialize a brand new Johnny 5 board telling it it's a Raspberry Pi. Next thing, once that board's ready and initialized, all I do is I instantiate a brand new LED. I say it's on the 13th GPIO. I couldn't tell you what that was. I had to Google it when I hooked it up. And then there's a built-in function telling it to blink. That's it. It's super. What's the word? Like expressive, super easy to use, and that's all the code it took to get the LED to blink. Pretty dope, right? All right. Let's make a toilet. All right. Easy peasy part. We're going to initialize that board again. The only thing we're going to do differently this time, instead of initializing LED, I'm initializing a magnetic switch on the 16th GPIO pin. And I'm basically, there's two states open or close, and I can change the maintenance mode of the box, depending on the state of that switch. Easy. That's it, right? That's it. Let's see this in action. So I got the box here. You can see a little white thing on the thing there. That's the magnetic switch I got screwed into the board there. I'm open and closing it, and you can see it registering on the laptop that it's being open and closed. In real time. So I can determine the state of the box using Johnny 5 and JavaScript. Pretty dope. All right. Load cells. I got to be honest with y'all here. I had to get a little creative here. It didn't work out of the box. What I did have to use is spawn trial process with node, and I spun up a Python sub-process that was able to actually interface with the load cells I purchased from Alibaba. It's super easy. All it does is take standard output from the Python thread and reads that up. So I just parse float that and then update the average weights. And there's some other stuff you can do with it. I do want to just show you really fast the Python code here. Don't worry about it too much. The most important part is this line, print val. Doing a standard output on the trial process sends the data automatically up to the parent process via spawn trial process. It was amazing, super cool, great. And it's all my problem really elegantly, which I'm very, very proud of. By the way, if anyone has any questions, please hit me up in the chat. I'm going to answer. I'm keeping an eye on the chat over here. I'd love to help you. All right, but let's take a look at these load cells in action. This isn't the best video, but it's all I got, all right? So at Pie Wood, I have the load cells mounted underneath of them. And I'm pressing on that board and just second I'm on pan over here, you can see the weight being registered in real time on my laptop. LED or the load cells are working. So I can start determining the weight of that board instantly. All right, IoT time series data. I'm just going to go fast through this. All right, but if anyone wants any free MongoDB credits, I got $100 there. Hit up that free link or that QR code and hook you up with $100. Okay, time series data. This is what my schema actually looks like. So every single day I produce a brand new document. I have some metadata on it. And then you'll notice I have an array of events. And every time a event, a maintenance or cat detected event happens, I add that to that array. As you can see here, I have two bathroom events and one cleaning event happened that day. And each of those bathroom events, I'm actually keeping track of my cat's weight on there as well. Ain't that dope, y'all? All right, this is the final box assembly here as well. I'm running out of time doing the full plug-in. That's it. Hides away. You can see the Raspberry Pi just mounted the inside. I got some wires that hide away pretty nice. And my dumb cat looking at me. I had to trick him to treat to look at it. All right, quick recap. What did we just talk about? IoT key to their box. We went over the whole world of IoT making the LED blink. Make sure everything's initialized correctly. All right, y'all. Next thing we do, we covered how we program the switches in load cells using Johnny 5, a Raspberry Pi, and some JavaScript. Holy cow, I'm getting a phone call. Then we covered time series schemas for IoT data. Cool. All right. Lastly, this speculate wildly about the future of IoT, huh? So first up, I'm predicting smaller, more powerful devices. No shit, right? We're going to see tighter integration into more things. We're integrating our clothing and tools and everything. We're going to see a lot of that stuff in the future. Next up, we're going to see JavaScript with it continuing to get a smaller footprint. See Rust and C++ continue to have the upper hand on JavaScript in terms of small footprints. But we're seeing more optimized versions of JavaScript for IoT devices already emerging. And I don't think that trend is going to stop anytime soon. Also seeing better hardware support. So again, my load cells didn't work. I had to find a Python library to work with them. But that hardware support is continuing to be better. What's the word? We're seeing better support everywhere. And this is true of everything. Batteries are the bottleneck. As devices get smaller, more powerful, they generate more heat and more energy. Batteries are not where we need them to be to support free roaming IoT devices yet. Lithium is still really expensive. They're not great. We're still waiting on that. So let's do a quick recap recap here. What do we talk about? IoT, it's exploding. I love stupid shit. It's great. Why IoT and JS? IoT developers, 58% of them already stuff identify as no developers. JavaScript is great for new developers. C plus C, Rust and C plus plus are great though as well. They just do different things in the herd to learn. Use what you know. It's easy to update over a network. Get poll, MPM install, you're done. JavaScript is already language of the web, baby. Come on. Tons of great libraries and support. And JavaScript is event driven, which reduces energy intake for a piece of hardware. We covered IoT data best practices, which includes finding a database that can ingest right requests quickly and concurrently. You want one that is also event driven. And you should get one that is a flexible schema, because IoT sensor data and time series data is particularly suited for flexible type schema. Time series data, of course, works best. Try to find a database that can handle as natively as possible. Then we covered my IoT kitty litter box. And the hello world using Johnny 5, making the LED blink. If you're ever going to do an IoT project, make sure you make an LED blink first. Make sure you get it all set up correctly, right? Then we covered how to handle switches and load cells on my project. And we covered IoT time series schema. And then we made wild speculations about the future of IoT, including smaller, more powerful devices, JavaScript with a smaller footprint, better hardware support, and speculation and though we already know what batteries are the bottleneck. Okay, so if I've inspired you at all to become an IoT JavaScript master, how the heck do you do it? Okay, this is going to sound really dumb, but y'all just do it. Watching the talk, like me talk about my project, you're not going to learn how to do something. NBA players don't watch video of other NBA players to get better at it. What do they do? They practice. They go out and do it, right? They get on the, they get on the court. Same thing with developers. I need jobs. If you're interested in IoT, try to make a stupid project. Try to just make an LED blink. It doesn't have to be good. Make it just for you, but try to do it. It's the only way to learn and to fully grok a subject. Boy, I've been talking a million miles an hour. Does anyone have any questions? I haven't seen anything pop up from the chat, but please ask me now. I'll be in the Dev Nation Slack channel if you have any questions. Otherwise, the best way to get a hold of me is on Twitter, as I've said many times. If you want any of the link, the schema, the source code, instructions where to build the stuff, definitely check out this link here. If you want $100 in free Atlas credits, this is also on that page, but you can definitely scan that QR code. Here's some additional resources here as well. I just want to say thank you so much for Joel, for having me here. Thanks to Red Hat for having me here. Thank you all for putting up with me. I love you all so much. You're absolutely incredible. And be sure to follow me on Twitter. If you want more of this, huh? If you want more of this, you should for sure hit the up. Thank you so much, Joel. That was a great talk. Thank you. I'm very informative. Thank you. Thank you very much for that as well. I've got a lot of very good comments here. Would you mind sharing the links in the Slack channel as well? Yes. I'm trying to cross pose because there's confusion between all the different chats. There's chats everywhere. Absolutely. I've tried your Atlas credits link as well. I'm not sure if it works, so you might want to check that one. Maybe I just typed it in a little bit too quickly. I for sure could have messed it up. I'll make sure I get that posted on there as well though. Perfect. Perfect. There is one question by Adan Rodriguez Garcia. Yes, Super. Any micro that you suggest to start up with? Any micro? Like a microchip or anything? Is that the chip they're asking for? I'm assuming microchip. Okay. Yeah, yeah, yeah. Oh yeah, this is great. I saw someone said the ESP8266, which is great. I actually built my Moodlight thing with that. However, what I would actually recommend is using a Raspberry Pi. It's big and chunky, but it's 35 bucks and it has a Unix-like environment on it. It's stripped down version. So it's like an environment we're used to working with. And I was able to troubleshoot a bunch of stuff in there. If you want to get more advanced, you could totally can. Oh, seems like we've lost Joe. But yes, I guess you can definitely use ESP, as he said. It definitely works with Johnny 5 as well. Arduino is also available and works out of the box with Johnny 5 as well. So those are nice options if you want to try them out. All right, so let me just get out of the way for one second. Where is my monitor right here? So you have all the links right there. So for the chat, you can find a chat either in Slack, be part of the community there. We will also post a bunch of different things, and you can also follow what's going on in the multiple tracks as well. You can find information to track channel is JavaScript September 20, and a full agenda for our Dev Nation Day today is available at dn.dev slash dnd agenda.