Kassian's IoT Hour
Presented by: Kassian Rosner Wren
Originally aired on February 21, 2021 @ 6:00 PM - 7:00 PM 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
Transcript (Beta)
Good afternoon everyone or morning or evening depending on where you are. Welcome to the IoT Hour.
I am Kassian and so today I did get a power supply for another Raspberry Pi.
So last week what we did was we had a Raspberry Pi running Redis and it started, we put an HTTP interface around it and we got it to where we could start talking to other Raspberry Pis with Redis PubSub.
And so since we have a second Pi powered up today I got it all set up.
We're going to first do some housekeeping and clean up the IoT Hour GitHub repository and then we're going to start communicating between the two Raspberry Pis with Redis PubSub.
So let me share my screen and we'll get started with some housekeeping.
Okay so here we go we've got our, I was just doing a little bit of housekeeping myself and so we got here is everything's all set to go.
Oh right.
Okay so now we're going to go to the repository here and check it out.
We do have a dependency issue that we may work on as well and so we've got in Pi code we need to clean this up and make it a folder called temp so we can add a folder for IoT push and IoT or IoT push parent and IoT push child.
And then in our worker code we've now got IoT dashboard, IoT push, intro temp.
So let's start by getting that Pi code cleaned up so that we can go into the Pi.
I've already added shh keys into the Pis so that we can handle that that way.
We're going to go into Pi code, we're going to mkdir temp and we're going to move next.js modules package.json and package lock.
So we're going to go into and then that should okay subfolder cool.
Now everything is clean and set up. Awesome, awesome. So now I created a folder called IoT push.
I'm actually going to remove it here because we're going to create it on the IoT push bot.
So everything's up to date. So I'm going to go ahead and create a new folder here.
So we're going to go to IoT push and we're going to google, we're going to copy you make sure we're in the right directory.
We are. We're going to oh right.
Great.
I have to set up a little bit more.
And while that's installing on this Pi, I'm going to get it started on this Pi, too.
Yes.
Let it install and then we'll set up the username and user email so that we can push commits without it yelling at us.
Let's take a bit on both machines.
Oh wow, IoT push was done. It's sooner. Get config global user.name.
The one I use for GitHub is my vietnam botanist email.
All right, this one as well. Okay, now that these are configured, we can get cloned.
Okay, we'll get cloned on this, too.
Okay, it's cloned on both.
Fantastic. We can now go into Cassian's IoT hour. We're going to go into Pi code.
And we're going to create IoT push parent. And we're going to cd into it.
And we're going to copy the root folder IoT push star.
And I want to make this recursive into here.
Cool. So then get status. Get status. Get commit.
IoT push parent. Oh, I forgot the dash m.
It's push main.
Fantastic.
We don't have any child code yet. So we're not quite there yet. So what we're going to do is we're going to take a look at where we were at the parent.
And then we're going to do some work there.
And then we're going to work on the IoT push child.
And we'll have them communicating with each other. So I also named them IoT push one and push two.
Push one is the parent. Push two is the child. And then I have a local terminal here.
So I'm going to go to code. This is the IoT hour locally.
So we're going to shift p. And we're going to say IoT push. And then I lost the password.
Okay.
And open a folder, we're going to open Cassian's IoT hour. Whoa. Open high code and IoT parents.
Okay. Cool.
So this is our HTTP server where we get and post.
Okay. Cool. So we'll be working a little bit more on this and kind of fleshing it out.
We'll add a ping and a pong kind of thing so that the children and parents can message each other.
And then what we're going to do next is we're going to open a folder on the child.
And make a directory for a IoT push.
I know we're going to get full origin name.
A little pull in push parent. We just want to have it here just in case we need it.
Yes. Okay.
So we're not going to need Redis on this child node because the Redis database is running on the parent node.
We will need the Redis JavaScript client in order to make all of this work.
So in order for the child to subscribe to the Redis PubSub is what I meant to say.
So let's get this moving. We're going to do MPMI Redis. And we're going to MPMI router.
I also added this to Argo tunnel.
This is now push 2.node bot nest. Just so we can have an HTTP interface for it if we like.
So what we're going to do is we're going to touch index.js.
Then we're going to open this in code. Oh, I should probably be in the right window for that.
So this time we're going to say pi at iot-push2.local.
So it's setting up and downloading.
That's why I did this early. It'll take a little while.
So while we're doing that, while that's cooking, let's look at the push parent and get everything set up to...
Here we go.
Here's our push parent. Okay, subscribe, iot-push, temp data.
All right. So we're going to... Okay, so we're going to pull up the Redis documentation.
So this is what we're going to do is the create client options and we're going to need to set the host.
Okay, so we've got that.
Now we can start writing our code. So let's Redis. Redis. Browser.
Browser.
Then we will...
So we're creating a parent here.
And then the options object is the host is pi iot-push.local.
The port and everything stays the same. This should work. So then what we're going to do is...
Okay, and we can do all our logic in there once we're done.
And then...
Problem. So now on push child, using node-index.js.
Pekan refused.
Okay. Try something here.
Hmm.
Okay, so I have an idea. I'm going to Google this off screen. So...
Okay, so we're gonna have to change some stuff in parents. Get this done. So we're going to have to...
Okay.
Okay.
Okay, let's see if that works. Nope, still econ confusing.
Okay.
Okay.
Oh, okay. So I don't have a universe spiral. So that's fine. I don't need that much.
But... Oh.
Well, for one, on the parent... I have to restart the Redis server.
Okay.
Okay, you know what we're gonna do? We're just gonna reboot that and pop it.
Close this tab now.
Come on, you can do it.
Hmm?
Taking its sweet time. Just out of curiosity.
Oh, hey, that did work.
So we now are connected to the parent. Oh, and of course now this boots up.
So we can now connect to our parent. And that means we can subscribe to events, and we will do that.
So let's do that now. And we'll say parent .subscribe.
IOT push.
IOT push. Now if we look at the parent code...
Okay, so we can do this.
And we can say... Parent.one message.
Parent.one message.
IOT push. Okay.
Okay.
So then...
It's connected to parent.
And now when I go into... Power. My code. IOT push parent.
Node one. Index.js. Oh, I know what's going on here.
Okay.
We're running, and we should see... No, we don't see any messages. So let's check the parent and...
Oh, that's right.
We have to get... So we have to go to browser and open a tab.
And we're going to push. Message published.
Message to main. And IOT push main. So now our child is getting messages from our parent.
So our two Raspberry Pis are communicating with each other in the sense that when a parent publishes a message to IOT push, the child recognizes that message and outputs it.
So now what we can do is we can start adding functionality to this, and we can start adding HTTP servers to this.
And we can start making this act as a, you know, IOT kind of mesh for, say, a house or something like that.
So you wanted to push data in between each, you know, Raspberry Pi.
Let's say you had one with an LCD so you could put the output... Pardon me. Of temperatures across the house.
So let's start fleshing that out a little bit. So we're going to look at the parent.
And we're going to do this.
What exactly did we change? I'm going to save it anyway. And then it should send another set of messages.
Oh, I can save it for E. That's not good. Where is it?
Oh, there it is. Now, since the servers are running, we won't see another message unless we refresh this page.
We'll just look under it. I can't wait. And there's another IOT push me message.
Now we've got that. So let's start fleshing out this parent a little bit.
I'm going to start cleaning things up. Okay.
Let's see. Let's actually start working on the child. I'm going to do this by creating a router.
There we go.
There we go.
First of all, let's move this here. That makes more sense.
There we go.
Okay.
All right.
Parent published. And then let's save this.
Make sure it's still running. HTTP is not defined, so we need to pull in HTTP.
There we go.
There we go.
It helps if I put these in strings. All right.
So now we go to Chrome.
Chrome. We go to push2. push2. So that's not the problem.
Was that an 8000?
It was 8000.
Okay. So that's why. There we go.
Wrong number of arguments for publish command. Okay. So we got to. There we go.
Oh, okay.
So this. So the child can't publish. Okay.
That's strange.
There we go.
Okay. Okay.
So I was writing the head wrong. All right. We've got all that. Okay.
So in order for the child to send messages back to the parent, I guess it has to have its own Redis instance, which instead of doing that, we just have it HTTP access the parent with a message that will then get published out, et cetera, et cetera.
So what to do next?
Well, We should clean up the repository for one.
Okay. Okay.
Okay. That's not what I wanted to do.
Let's hang on. Let's. Let's see. Okay. Okay.
Okay.
This is not what I needed. Okay. Okay. Okay. Okay.
You guys are getting something rebase. Now we're going to make sure the code is updated on child.
Okay.
Okay. Okay. Now what do we do? We've got about 15 minutes left. Let's finish that access where we send an HTTP request from the child back to the parent to say, Hey, I've been accessed in the parent case.
Okay. Okay. Okay. And then log that access as a timestamp.
Okay.
Listen here. We're going to do. You're going to wait. It's going to make sure I'm not missing any questions.
Nope. Not missing any questions.
Cool.
All right. Okay. Okay.
Okay.
It's a slash.
Child. Okay.
Just making sure I know the questions.
Okay. So. And then we're going to save this. Okay. Okay.
Okay. Okay.
Okay. Okay. Okay.
Okay.
Now we're going to restart both these servers.
All right.
Okay. Okay.
The parent.
Server is running. And we're going to do is we're going to go to. Okay.
Okay. Problems. Oh, right. I'm thinking. Okay. My apologies. Okay.
Okay. Okay.
But what's the replacements. Okay. Right.
Okay. So. Okay.
Here. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay.
Okay.
Okay.
Okay.
Got that.
Okay.
All right. So the parent.
That. Okay. Okay.
Okay.
This should work.
Who's running one is running. Okay.
And we're not getting any response.
So let's see what's going on. London protocol.
Okay. Okay.
Okay. Okay.
Okay.
Nothing fine. Okay. Okay.
Okay.
Okay. All right.
Okay. Okay.
Okay. Okay.
Okay.
Okay.
Okay.
Okay. Okay. Okay.
Okay.
8,000 is open.
Okay, so it's not the 8000 is closed per se. Okay. On here. Have an idea.
Okay. So.
Okay.
Oh.
Right. Right. Okay.
Okay, it's getting access. Great.
So, I've got two minutes remaining. This is bad gateway still. Okay, it's not logging the success.
So, Okay. That's it.
I get all this stuff. Okay. So, Really.
Go here.
That's fine. Okay.
Okay, sweet.
Okay. Okay. Let's change the push just so we can see.
Okay.
Okay, but it's working, but it's saying bad gateway.
That's really strange.
Anyway, it's 2pm so have a good rest of your week and next week we'll continue to work on this.
So, have a great one.