Kassian's IoT Hour
Presented by: Kassian Rosner Wren
Originally aired on February 12, 2021 @ 3:30 AM - 4:30 AM EST
Let's dig into how you can use Serverless to supercharge your IoT projects! We'll walk through setting up a remote sensor and LED with Cloudflare Workers, Workers KV, and a Raspberry Pi.
English
Tutorials
Transcript (Beta)
Awesome. All right. Good morning. So today, what we're gonna be doing is we're going to be working on that same Raspberry Pi setup that we did last time where we set up a Redis instance with PubSub.
And we had, you know, one Raspberry Pi is kind of the parent that sends all the messages to the children.
And so what we're going to do is we're going to add a third Raspberry Pi to that today.
And that's gonna be this one.
And as you can see, it's got the unicorn hat, the unicorn LED hat on it.
And what we're going to do is start making it receive messages that'll make that make it light up from the parent.
So first thing we're going to do is share screen.
All right.
I'm sharing my screen here. And what I was doing before anything else happened is my card reader was being kind of finicky and not starting up.
And so I'm going to try to figure out why that's not happening so I can reflash this card.
Worst of worst, I think it has a working operating system. So we can probably get into it.
Yeah, it doesn't seem to want to light up anywhere.
All right.
So what we'll do is we'll just work with the operating system that we've got on here.
Pre-search still on pi.local. And what I did was I bought a bunch of power supplies for Raspberry Pi's because the Raspberry Pi 4 is a bit finicky about where it gets its power from.
It doesn't like it doesn't like cell phone chargers or anything like that.
So I'll move this up here.
All right, my lab's a bit of a mess. So plug this in. We got it plugged in.
And we're going to try to SSH into it. And we're going to SSH into the other ones as well.
So that's our normal tab.
So to SSH. And then we're going to tab to.
There we go. SSH. Push to local. We're going to create a new tab.
Bigger so you can see it.
H. We don't do Raspberry Pi.local anymore.
Which it isn't. Maybe it's this one.
I don't know where I left that one at.
Okay, so hmm. That's something.
I have an idea.
I'm going to scan with my phone on my Wi-Fi what's going on here. And so we do that.
Okay.
Scanning. Okay, so it's found a couple of pies.
Okay, let's see if those are the same as the pies here.
This is 1.111.
And this is 1.108, which is what I see here.
Don't see it on here.
It's not under those tabs.
Hmm. Maybe it's not going to do it, which would be concerning.
I'm going to try the card adapter one more time here on my computer.
Pardon if there's some gibberish on the screen for a second.
It's still not lighting up.
Not lighting up on any port with or without the card.
So, hmm.
Interesting. Let's try something. No, that doesn't work.
Okay. My card reader slash hub is DOA, which is unfortunate, which means we can't burn any new cards.
So, what I'm going to do is, hmm.
This is interesting. I have not run into this problem before.
Let's see. You don't burn any chance of a card reader, do you?
No, you do not. All right. Hmm. What to do here? Well, what we could do is we could take the shield off of this and put it on the other push IOT one, and then have that receive messages that will light it up, and then I'll figure out the card reader situation.
Time. So, I will do that. I will put the shield over here on the push one.
Okay.
Well, either way, it's on there now. So, what I'm going to do, I'm going to close this window.
Okay. So, I've got IOT push two. I'm going to install the library on it.
It's right here. So, first we're going to do this.
Reboot IOT push two.
Come on.
You can do it. Ah, there we go.
Connection refuses is a good thing because that means it's actually getting there.
All right. All right. All right. Let's install.
Install. There we go.
There we go.
All right.
So, it's successfully installed Unicorn Hat HD, which means we can pull this down.
So, we're going to go into Unicorn Hat HD, go into examples, and we're going to say Python 3 demo.
So, let's install that one.
There we go.
Question check. Okay.
So, So, install it.
There we go.
Okay.
Let's try just a different one. There we go.
There we go.
There we go.
Okay. So, let's try this one. Robust so we can figure out what's going on. Okay.
So, I will turn on the video so you can see. So, right here you've got the push to running a Unicorn Hat HD sketch.
So, now we can start working on a sketch or a Python program that will allow us to receive messages from the parent and do different colors based on that.
So, let me share the screen.
Okay. Okay. Okay. Okay. Now we've got that done.
Okay. So, we're going to learn how to set up a Python web server so that we can get messages from.
So, let me go back to my desk.
Stalls.
Stalls.
Stalls. So, we're going to do is we're going to CD out of here.
We're going to go into. We're going to make a directory.
So, we're going to do is we're going to create our Python module.
Now we're going to go to VS code.
We're going to create a remote.
Oh, sorry. So, we're going to create a remote. Okay.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder. I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder. I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder. I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I'm trying to figure out how to do a different folder.
I have an idea. We're going to open up the Casiens. There we go, awesome, all right, now we can start working on.
Okay. Okay. Okay.
Okay.
Okay.
Hmm.
Oh.
No, that's not it.
Okay. Export, right?
Yeah. Hmm. Okay. Okay.
Okay.
Okay, that's better. All right.
I don't know what this means. Okay. Nope, nope, nope, nope, nope, nope, nope, nope.
This is not good. This is why I do my searches in the window.
So. What to do now. Okay. Okay.
Okay.
Trying something a little different here. Cool.
Okay. Okay, let's set correctly.
Nope, that didn't work.
Okay. Okay.
Okay.
Okay.
Okay.
Okay.
Okay.
Let's try something here. Okay. Oh, that's right here.
Okay.
Nope, still not working.
Hmm. Hmm. Hmm. Hmm. Okay.
Okay. Okay.
Okay. Let's try this.
Let's put that over here. There we go.
Okay. Okay.
Okay, so now we've got that. And then we go back to the browser. Okay, so I'm going to go in here, I'm going to make this port 8000.
I'm going to add a terminal, and I'm going to add a...
Okay, we actually have the server running.
Fantastic. So we're going to go to... Okay, that's good, because it's still getting the Python server.
Let's see what the code says.
I don't know where to go. Oh, Rob is hello. So we're going to do... Hello.
Fantastic. So we now have a working Python... Server.
So let's get this to where we can send it requests. There we go. Okay, so one thing I can see about doing here is a dynamic route.
So we'll do here. And then we'll pass the color.
Actually, we'll do status, because we'll use colors to represent statuses.
Okay, so we'll do status.
String. Like that.
So we'll do this. Close this.
Redo it. Open it. Oh, forgot the...
Okay.
So now I can go over to here. Okay, so we do have to have a status.
It's not optional. That's fine. We will get that set up with the unicorn hat HD.
I, however, need to take just a minute. I'll be right back.
Okay.
So now I can go over to here. Okay. So now I can go over to here. So now I can go over to here.
Okay. Okay. Okay.
Okay.
Sorry about that. All right. So, we now have the status and so we can add the colors in.
So, to do that, we're going to pull up the unicorn hat. Yes, buddy. You want to be heard, I hear you.
All right, and then we are going to look at the examples.
So, we are going to bring in Unicorn Hat HD.
So, is that all pixels?
Excuse me, Ace, you are not...
Cat thought he belonged on the desk, but he's not belonging on the desk.
So, now I have to set all of them.
Okay. The last of the Python, so for x and range.
So, make sure this is all over.
Okay, let's see if this compiles or runs.
Okay, so it says it's working.
I'm gonna push the button. That's a test, no lights.
Let's see what happens when... Oh, that's not what I meant to do.
Test, kernel server error.
Okay, so I did that wrong.
Oh, set underscore pixel because it's Python.
Right. It did not change the...
It did not set the pie up, the Unicorn Hat up the way it's supposed to.
it should be changing the status because it says test status set.
Oh, silly me. There it goes.
Okay, I'll show you on camera if I can get this. Cord pulled up. It is now green.
And it was made that way by that request. So we're gonna add a couple different colors and then that will be it for the day.
And we'll start working next week on connecting it to the Redis PubSub and getting messages from Redis and from workers.
So we'll just add a few more colors here. First, let's break this out into its own function.
Nope, this is not JavaScript.
Okay.
This needs to be...
Let's make sure this all still works.
Test status set, still green.
Awesome. So let's write some more code. Okay.
Just a warning color here.
Oh, I'm not sharing my screen anymore. Sorry. So what I did was I set this its own function.
So it's got set hat color and tested it and it worked with tests.
So I'm adding a warning status, which should send a hopefully yellow color.
It's been a while since I've done my RGB mix. Hmm, it did not change color.
Maybe it's because I didn't reset it.
Ah, invalid syntax, okay.
Oh, it's all working.
Okay. Okay, there we go.
Here, and I will show it.
It's a lime green, kind of. So it probably needs more red to be yellow, but that's okay.
It's kind of yellowish color going on here. Looks more green in my view than in yours, but that's okay.
So share screen, one, okay.
We're gonna add one more color and then we'll be pretty much done for the day.
I'll review what we did and get cleaned up because that's always a thing. Nope, five minutes remaining.
Okay, so. And now it's red, fantastic.
So let me show you. It is now red. So you can now set, let me change it to test and then show you.
Test changes it green.
And I can go back to show you error.
When I refresh error, it changes red. When I refresh test, it changes green.
So we've got that working. Now we're gonna clean up Git and review for the day.
So what is this? Git status. Add this directory.
Git status. Color indicator.
Yeah, Oh, right, no longer using master, git push version main.
There we go, okay.
So to summarize, what we did today was we got Python running on a Raspberry Pi, not the one we intended, but you know, it worked out.
I will get the card readers issues sorted and get a third Pi up by next time.
Oh, I didn't share screen for that, sorry.
So yeah, that will be for next time. We will connect the Pis together, use Redis to use the PubSub and get some more workers going.
So we'll continue building out this Pi network next time. So I hope you enjoy the rest of your day and I hope you enjoy the rest of Cloudflare TV for the day and stay safe, everyone, bye-bye.
♪♪♪ ♪♪♪ ♪♪♪ ♪♪♪ ♪♪♪ What is caching?
In caching, copies of files are saved in a temporary storage location, known as a cache, for quick and easy retrieval.
In the context of a content delivery network, or CDN, a website's files are cached onto a distributed set of CDN servers.
Imagine a user in Tokyo trying to access a website hosted in Los Angeles.
The user's request will have to travel over 5,000 miles to reach the web server, and the response will have to cover the same distance.
That can take a long time.
A globally distributed CDN can cache the website's files in CDN servers around the world.
This way, when a user in Tokyo wants to access a website 5,000 miles away, they can minimize latency by getting the files from a CDN server close to them.