Cloudflare TV

Kassian's IoT Hour

Presented by Kassian Rosner Wren
Originally aired on 

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.


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.

Worse to worse, 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 Pis because the Raspberry Pi 4 is a bit finicky about where it gets its power from.

It doesn't like cell phone chargers or anything like that.

So I'm going to move this up here. Sorry, my lab's a bit of a mess.

All right. So plug this in. All right.

So we've 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 we're going 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.

SSH. It may not be 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.


Scanning. Okay.

So it's found a couple of Pi's. Okay.

Let's see if those are the same as the Pi's 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 numbers.


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.

Still not lighting up.

Not lighting up on any port with or without the card.

So, hmm.


Let's try something. Let's take... 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... This is interesting.

I have not run into this problem before.

Let's see. You don't by any chance have a card reader, do you?

No, you do not. 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'll light it up.

And then I'll figure out the card reader situation. So I will do that. I'll put the shield over here on the push one.

Oh, it's because I have a heat sink.

Okay. Well, either way, it's on there now. Um, 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. Okay. Let that install.

This back board belongs.




Okay, so it's successfully installed Unicorn Hat HD, which means we can pull this down.

Okay, so now we're going to go into Unicorn Hat HD, go into examples, and we're going to say python3 demo .py.

Okay. Okay. Check the questions thread along here.

Question check. Okay, so install it.

Maybe it needs sudo.

Okay, so we'll find out. Okay. Okay, let's try just a different one.

Okay. Okay.


Okay, thank goodness that error message is 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.

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 my screen.

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.

That's why I know it was Flask.

Okay. Okay. Okay.


Okay. Okay.

Let's get out of here.

We're going to go into... We're going to make a directory.

IOT push. So, now what 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. We're going to create a remote. I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

I'm trying to figure out how to get to a different folder.

Okay. Now, we have folders. Open folder.

Casting the IOT hour. Pycode. IOT push child. Close the console.

And we're going to open. I think this isn't the right folder.

What the heck?

I think this isn't the right folder.

So, close. I have an idea this time.

We're just going to open up Cassian's IOT hour folder. There we go.

Awesome. All right. Now, we can start working on... Okay.

Thank you.

Thank you.

Thank you.



No, that's not it.

Okay. All right.

That's strange.

Let's see if this works.

Let's see if this works. Okay.

That's better. All right.

I don't know what this means. I don't know what this means. No, no, no, no, no, no, no, no.

This is not good. This is why I do my searches in the window.

What am I going to do now? Okay. Okay.


Let's try something a little different here. Still the same problem.

Cool. Cool. Okay. Let's check correctly.

Nope, that didn't work.

Okay. Okay.




Okay, let's try something here.

That's not the one I needed.

Oh, pass right here. Nope.

Still not working. Why is this doing this?

It's driving me up. So hang on. I'm going to try. Okay. Okay.

Okay. Searching.

Let's try this.

Let's put that over here. There we go.

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 8,000. Terminal.


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 know where to go. Okay.

Fantastic. So we now have a working Python server. So let's get this to where we can send it requests.

Okay. 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.

So we'll do status.

And then we'll do string. Okay. So we'll do this.

And then we'll do this. Not good syntax.

Oh, forgot the... Okay.

So now I can go over to here. Oh, not found.


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.



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.


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. So it's a warning color here.

Oh, I'm not sharing my screen anymore, sorry. Let me do that real quick.

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 shows Sunday, hopefully yellow color.

It's been a while since I've done my RGB mix.

Hmm, it did not change color.

It's because I didn't reset it.


Ah, invalid syntax, okay. Oh, it's all working there, okay.

Okay, there we go, down 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.

Okay, yellowish color going on here.

Looks more green in my view than in yours, but that's okay. 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. Yep, five minutes remaining.

Okay, so. Okay.

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 show you.

Test changes it to green.

And I can go back and show you error.

When I refresh error, it changes to red. When I refresh test, it changes to green.

So we've got that working. Now we're gonna clean up Git and review for the day.

So what is this? Add us. This directory.

Add us. It's, add us.

Color indicator.

Oh, right, I'm no longer using master.

Git push engine 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 issue 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, you know, use the Pub Sub 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. Have fun.

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.