 Hi, can everyone hear me? Great. My name is Vinay Kirti and I'm going to talk... Well, I'm going to talk about MicroPython. And I'm going to talk about a project I did for myself. I call it Shelfie. And long story short, I have a bookshelf and it runs on Python. There are two kinds of reactions I get whenever I tell people this. Usually, they say, what do you mean your bookshelf runs Python? They ask if I have way too much time, whether my company is paying me for doing my own personal work or if I'm workaholic. I am, but that's a different point. Some of them say, oh, and then they go by their own way. Trust me, I've had even interviewers ask me what the hell I mean when I say my bookshelf runs Python. I own over 1,000 books. Logistically speaking, this is a very big problem for me. It's really hard to keep count. Once I crossed 250, I knew that I had a problem, a problem that was not really easy to solve. And it doesn't help that I'm not really that organized. People have told me several things. They said, could you not use physical notebooks to track what books you have? I don't want to carry them around. They said, don't you have spreadsheets? And I said, boo, I don't want to use Excel and Google Sheets on the phone is a nightmare. Then there is Goodreads. Honestly, I have a few choice words I would like to say to Amazon about the Goodreads API. It's really horrible. There is library thing, which is really good, but you have to pay once you hit the 250 books limit. I've tried them all. And I also own a lot of tech. I own several Raspberry Pi's, several of these chips, which I'll be talking about, a lot of LEDs, and more Raspberry Pi's. I don't know what to do with them. I keep ordering a lot of electronics. I have a hoarding problem. So I ended up with a slightly over-engineered problem. Not exactly the kind you would find at someone's house, but then there is this. My bookshelf runs this entire stack. So what did I do? Very simple terms. Let me show you. Oh, one moment. This is my bookshelf. When I ask it for a book, it tells me where the book is. How? This way. It points a book or a series of books, and it tells me where my books are. How did I do this? Well, it was one part easy and two parts insane. Where's my mouse again? Yeah. Micro-Python. If you listen to Jake Wanderplatz's keynote, he said, this is the era of wasm on Python. I have another point to make. This is the era of Python on embedded devices. Until now, if you wanted to program on a tiny chip, you have to use C. C, I have a friend who likes to say C is the only real programming language. I say boo-hoo, where Python is to us. I want to code Python even on a tiny, I want to code Python on my washing machine. So what is Micro-Python? Micro-Python is Python for microcontrollers. Seriously, you can code Python on a very tiny chip. How tiny? It's so tiny that I can carry two of them with me everywhere I go. I never leave home without my Micro-Python chips. And the subset of Micro-Python that runs includes most of the C-Python libraries. It is syntactically similar. There's a little more electronics knowledge that you would need. So how do you get started? You buy one of these chips. All the links will be available later to you. You flash the Micro-Python firmware on them. And what do you do? What is this thing I've noticed about people who own Raspberry Pi? A lot of developers own a Raspberry Pi and you ask them what are they doing with it? It's probably gathering dust on their shelves. Similarly with Micro-Python, a lot of people buy the Micro-Python boards and they don't really use them for anything. They use them once or twice. And then they're like, huh, this was a fun side project. How do I productionize this? They have no clue. This is how they productionize the entire thing. Step one, the NodeMCU. The NodeMCU is the easiest Micro-Python board you can get anywhere in the world. You can go to Aliexpress or you can go to Amazon and buy them. They cost less than four euros. You can get them for anywhere from 140 rupees to 500 rupees depending upon your luck. It's sale. The chip has many pins which you can use. If you're coded on the Raspberry Pi, you've heard of GPIO pins. The GPIO pins are the pins which you can control. You can do a lot with these pins and, well, I'll show you what I do. Then the NodeMCU. This is the spec. ESP8266 is a Wi-Fi socket on chip. What it does is it basically gives you something very similar to an Arduino with Wi-Fi inbuilt into it. It runs Lua out of the box. Lua is a very nice scripting language which is mostly familiar to people who have been hacking around Civilization 6. You can install Micro-Python for the last few minutes. It supports the 2GHz Wi-Fi band. It has 128KB of RAM and 4MB of ROM. Trust me, that makes a huge difference when you're coding. It uses a USB interface. The biggest problem with coding on embedded devices is learning to deal with the serial port. But this board solves the problem for you. It uses the USB port. Like I said, it's extremely cheap. How long does it take to actually run Micro-Python or install Micro-Python? It doesn't take very long. You would think it would take a few minutes. It's lesser than that at 60 seconds. It's so easy to install Micro-Python that all you need to do is create a virtual environment, pip install ESP tool, then source your virtual environment, use the ESP tool command to format your Micro-Python board, flash the Micro-Python firmware onto it using a very simple command and within a few seconds you have the Micro-Python REPL and it's the REPL we all know and love, the same Python REPL. It is syntactically similar to Python 3, thankfully Python 3.4 but it does not have F-strings, it does not have the Walrus operator and it does not have many other things but we can live with it. It is really, really easy to use and as you're even watching this GIF that's flashing one of the boards right now. Alright, I'm not going to wait for this entire GIF to finish. Now, until now you've been seeing the terminal, you've been using a terminal to get into Micro-Python but what if you don't want to do that? I'm a Node.js guy, I don't like terminals, I like browsers, I live in JavaScript. You're showing me a terminal, I'm not going to code in your boring old terminal. I'm fine with that. I'll give you the web REPL. You can open up your browser, access Micro-Python on it almost very similar to the Jupyter terminal and it is extremely easy because the board runs a Wi-Fi access point so how do you activate it? Again, fairly simple. You just import a module called web REPL underscore setup and it enables the entire thing. It asks you for password and it is not really secure since it shows you what my password is right on the screen. So once you're done with that, you get this screen. In your browser, you get a web page where you can actually start using the Micro-Python REPL or you can upload and download files directly into it but honestly speaking, this is not deployment friendly. Instead, I would rather use a CLI tool. I would use a CLI tool which would push files into my Micro-Python boards. Fairly easy to do. What is a Micro-Python program? It's not as simple as having a simple app.py and running it. No, it's very similar to how Arduino does it. You have a boot.py. A boot.py sets up your entire Micro-Python. You can pass it a config. You have an optional file which you don't need to worry about and then the main.py. If you have ever used Arduino before, the main.py runs on a loop. So whatever you put on it, usually you have a while-true loop sitting inside it and to save power, you also have options where you can put the node MCU onto a sleep mode. So, what is Shelfie? Shelfie is me taking three of these boards, five Raspberry Pies and putting them on my bookshelf. I have snakes on my bookshelf. The hardware I need is PSP8266 boards, the node MCU, the Raspberry Pi 3+, four Raspberry Pi 0s, a cluster hat and an LED strip. The way my application works is fairly simple. You have a Flask API. You have a Postgres database. You have a Postgres database. You have something called mosquito MQTT. I will explain more about that later. Three node MCUs which are listening for commands. So, what is MQTT? MQTT is a PubSub model. If you ever use RabbitMQ, fairly similar, but it's much more lightweight. It is ideal for IoT. It was made in 1999 and the Eclipse Foundation released something called Eclipse Mosquito which is one of the best MQTT servers out there. And it is fairly easy to use. Documentation is available everywhere. So, what does my bookshelf really do? What it does is I have a queue. I write to a topic. I give it a position and inside, it reacts. Inside my MicroPython chip, it reacts. That's all it does. It's fairly simple. But the LED strips now, what are these LED strips? The WS2812B strips are addressable strips. You can pass it an integer and you can say I want to light this place up with this RGB value. You can individually connect each and every one of the LED points. You'll see what I've done fairly soon enough. So, I use Flask for this. Why Flask? Flask is lightweight and it has modules for everything. My entire database is just one table. It's a very, very simple table. It has a list of books and it knows where every book is. I have Flask admin setup so that I have a UI. I don't need to write CSS or HTML. I have a UI setup already for me. This is like Django admin. Much more lightweight. And I can also enter books into it. Now, if you see this field slots has a value of 1 is to 6.5. What that means is if you have a position called m is to n.x, it means that my book sits at LED number m and goes to LED number n and it is at row number x. I'll explain soon enough. The idea behind my entire project is this. I am not organized. But I want my bookshelf to be organized for me. I want to be able to take a book from anywhere in my bookshelf and ask my bookshelf where I want to put it back. I don't want to bother about remembering where my book was. I don't need to put all my books in one spot. I can just say I can just tell my bookshelf that I put it at this location and it will remember. It enables my lack of organization, so to speak. So, what are the phases? The phases were fairly simple again. I am not playing a YouTube video but so that was stage one. I just made something blink. That made me really happy. But then I instantly ran into problems. I instantly ran into problems. I have no idea what the capacitor is. I am not an electronics student. I don't know why you would use one in a circuit like this. So instantly I ran into this problem. My lady would light up and partially it would stop. It would stop randomly at some place. Turns out I needed a capacitor for this. I have no clue. Then I made a little more progress. I had better control. The control I am talking about is this sort. So I have a progress bar. Every time something is happening around my house on my desktop this thing has a progress bar. I set it up. That worked really fine. I solved all my voltage problems. I solved all the other problems that I had. Fairly simple. But soon I had another problem. How do I start indexing? I have to manually count things. I have to count my books. How do I count them? This is how I counted them. I highlight every 10th LED and I have an easy way of counting things. I can just say this is at 10, 20, 30 and I can say it is at LED number 30. Fairly simple. And then the first video I showed you earlier. Oh I am not audible. Sorry. Maybe I bend this. Now? Still closer? Oh wow. Okay. Sorry. So the first video I showed you. I will tell you. I will explain what happened in that video. So my bookshelf database knows that these books are here. I am asking for this box set. This box set. And once it knows that, it highlights it. It tells me it is here. But how am I asking my bookshelf this? Well, sort of boring. I am using curl. I have no interface. I am using curl and I am sending a request. I am giving it the title of a book and it says okay fine. This is where your book is. And to be honest with you, I have had friends told me that is such a boring thing. They are like really? Are you curling for books? Every time you need your book, you are going to open a terminal and you can't just remember where your books are. Well, from the beginning I have been saying something. I have been saying I wanted to ask my bookshelf where my books are. Not curl where my books are. So, I hooked it up with a voice server. How? Alexa. My idea was fairly simple. I wanted to ask Alexa where my books were. I wanted Alexa to show me where my books were. Whether that would be possible is a totally different thing. So, Flask Ask is a very nice module for working with Alexa. So, the final missing part of my architecture was an Alexa skill. I wanted to say Alexa. Ask my bookshelf where X book is and it would say how? I know where that is. All code samples are online on GitHub so you don't need to worry about any of this. You don't need to take photos or anything. So, the thing about Alexa is you have to configure your skill online on the Alexa page on Amazon developer and you have to configure every phrase that you are going to enter. And the main part of this is you have to ask it to give you the raw query string. Once you do that, you are able to access the raw query string in your app. So, in your Flask view, it comes as the first argument. It comes as the first named argument. And what that does is fairly simple. How do I hopefully? Alexa. Ask my bookshelf to show me where did I keep my books by Neil Gaiman. One Neil Gaiman collection coming right up. I'll show you this again. Alexa. Ask my bookshelf to show me where did I keep my books by Neil Gaiman. The phrase which I entered was syntactically any structure in the Alexa skill. Coming right up. The Alexa skill sits on my Raspberry Pi. It knows where my book is and it highlights where my books are. I don't need it. That's step one. Step two, I had different problems. My bookshelf didn't end there. Alexa, ask my bookshelf to show me where are my Hemingway books. How do I structure the other bookshelves? I found books by Hemingway. Let me show you. I have bookshelves which are even structured vertically. How do I show that? Fairly simple. And am I sure that it is exactly showing me the right book until then? Look at the LEDs that it has highlighted. It is highlighted from position X to position Y where these books specifically are. Then, how do I highlight a single book? Sometimes I want to ask it just for one single book. Alexa, ask my bookshelf to find a Christmas Carol. Your copy of Charles Dickens's A Christmas Carol. It's right here. Lights up. It has the accuracy of one LED which is specifically, well I have to index my books and say my book is X LED's thick. Sometimes that helps. It's a little hard. That part is actually a little annoying. But then, the Alexa API allows you to do so much more. Since this is a flashcap, I can tie it up with my same Postgres database. And because of that, all I need to do if I had to ask for a specific book and get more data out of it, I could even channel in additional behaviour for a specific book. Suppose you have a book for which you want a specific response. You want to add an easter egg. You want to add a joke. Fairly simple. All you have to do is code it. Alexa, ask my bookshelf where are my Harry Potter books? Your Harry Potter collection? You are lucky I'm your Marauders map. Say it with me. Mischief managed. There's something interesting in this problem. I have books behind books. How do I index? How do I find them? I control the colour of the LEDs. The LEDs are pink when it is the first row. They are orange for the third row. They are blue for the second row. And I think they are white for the fourth row. So I can index books no matter where they are. Whether they are horizontally sleeping. Whether I place them vertically. I can even index books which are at an angle. I can say they start at this point and at that point. So what does this show us? This entire application has deployment scripts. It has scripts for pushing code into micro-python chips. It has Unicorn script. Unicorn based engine configurations. So that this is load balanced. So even if all of you started connecting to my Alexa skill right now and try to spam or DDoS my bookshelf. It would be able to take it. I turned off my skill before I came here by the way. Don't try it. So and this is the thing. When you get started with micro-python the possibilities are endless. You have so many things you can do but it ends up such that you have very little examples of anything beyond a simple blinking LED or some weather stations or a nice hat or some shirt. They are all amazing projects. But what if you wanted to push micro-python into production? What if you wanted to take a micro-python board and actually have a start up around the entire thing? How would you do that? Partially this is how. I'm not saying this is completely production grade. But I have a pipeline. I have documentation. It helps because you will not remember what code you wrote 6 months later. The first person you document for is yourself. So at the end what do I want to do later? I want to build a web UI. Without writing an inch of JavaScript. I want to write a telegram bot much easier than Alexa. And I want metrics. I want to say Alexa, show me all the books I have not read in the last 6 months. Show me all the books I have purchased and I've never read. I want it to be able to do all of this. And I want connected dialogue flow for Alexa. I want to be able to have constructed dialogue so that I can say Alexa do I have this book? It says no. I want to order it for you from Amazon. I want to say not right now but order it when the price has dropped. That's what I want. Eventually I'll get there. Eventually I'll get to a point where Alexa tells me that hey that book which is on your wish list is actually on sale and you don't seem to have it. Do you want me to order one copy for you? I say yes and it orders. And finally I want to use Spacey for the NLP part. There are 2-3 modules which I've considered and Spacey seems the easiest to use. So who am I? I've said my introduction for last. My name is Vinay Kirti. I'm a mechanical engineer. I'm not a developer. I'm not a software developer. I learned programming on my own and I work at Visa Incorporated. I'm a senior software engineer there. I work on Python, a little bit of Node.js and a little bit of HTML. I am Stone Chariteer everywhere online. You can find me on any website and my website is stonechariteer.com The entire source code for Shelfie is at github.com slash bookshelfie. That's an organization. So there are 4 projects under it. You can find the entire source code there and if you have any questions related to it please raise an issue. These are links for everything on this page. So you don't really need to take a photo of this because the entire site is online. You can just go to bookshelfie.github.io and these slides are online. Alright? Thank you so much. Do we have time for questions? 2 minutes. I need water. Excuse me. You mentioned MQTT, right? Yeah. What do you use MQTT for? MQTT is a message queue. I was running out of time so I skipped over that part. MQTT is a message queue so I have 4 topics. Each of the Node MCU chips subscribes to a topic. So I have a shelf A, shelf B, shelf C. All 3 of those subscribes, all the shelves subscribe to those topics. I actually did show you a slide there where MQTT was working. Is it wireless? Yes, it is wireless. All of this is wireless. The only wires there are the wires which I soldered. Very poorly. I burnt my hand the first time I soldered by the way. It's a really nice project and interesting one. Being an electronics background I found out what I can do with all the different electronics that are there. My question is is it possible to code MicroPython directly into an edge board like TX2 or Raspberry Pi? You don't need MicroPython for the Raspberry Pi. If you are going to write anything directly into the Raspberry Pi, you will have to write an OS. So you don't need that. Just use Raspbian and use normal Python. Please stay away from MicroPython and Raspberry Pi because MicroPython is for when you actually have to worry about one of the problems I had during this entire project was I would import a library that I wrote and it would say malloc error. I have never heard of a memory allocation error in Python. I am like what on earth is this? So you understand what I mean. MicroPython is for chips where you have very little memory and very little is this thing. For tiny footprint. So I am trying to get into MicroPython source development. So you can compile MicroPython for any laptop that you have and run it on your laptop just to test it out. But I would recommend getting a board. You can order one. It's very very cheap. Thank you. Anymore? Catch me later. I will be in the hall. Thank you so much.