Kassian's IoT Hour
Presented by: Kassian Rosner Wren
Originally aired on April 17, 2021 @ 11:00 AM - 12:00 PM EDT
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.
into and then that should okay.
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 we're going to go to the directory we are, we're going to, oh, right.
Great.
Just 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.
Okay.
Yes.
And install, and then we'll set up the username and user email. So we can push commits without it yelling at us.
Let's take a bit on both machines.
Oh, wow. IOT2 push was done sooner. Git config global user.name.
Git config global user.email.
The one I use for GitHub is my botanist email. I'm going to do this one.
Okay. So now that these are configured, we can git clone. We'll git clone 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 git status. Git status. Git commit.
IOT push parent. Oh, I forgot the dash M.
Git 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. IOT push at third.local.
And then I want the password.
I'm going to open a folder.
We're going to open Cassian's IOT hour. Whoa. So we'll be working a little bit more on this and kind of fleshing it out.
And 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 actually create that folder on the child.
And make a directory for a IOT push.
Do you know it?
Oh, you know what we're going to do?
We're going to get full origin name. Little pull in push parent.
We just want to have it here just in case we need it. And then we're going to do an npm init.
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 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 this npm i Redis.
And we're going to npm i router. I also added this to Argo tunnel.
This is now push2.nodebotnest 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.
And 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 pi iot push2.local.
I want my password.
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 go.
Here's our push parent. Okay, subscribe iot push temp data.
All right. So we're going to pull up the Redis documentation.
Okay.
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 got that. Now we can start writing our code. So Redis. Redis. Browser.
Browser.
Browser.
Then we will so we're creating a parent here.
And 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 we can do all our logic in there once we're done.
And then problem.
So now on push child.
Using node in x.js. Pecan refused.
Okay.
Something here.
Okay.
Okay. So I have an idea. I'm going to Google this off screen. Okay.
Okay. So we're going to have to change some stuff in parent. Get this done.
So we're going to have to do.
Okay.
Let's see if that works. Nope.
Still econ confusing. Okay.
Okay.
Oh, okay. So I don't have a universe firewall. So that's fine. I don't need that much.
But Oh.
Well, for one, on the parent, I have to restart the server.
Okay.
You know what we're going to do? We're just going to reboot that and pop it.
Come on.
You can do it. 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 pops 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. Here is a parent .subscribe.
IOT push.
Now if we look at the parent code.
Okay.
So we can do this. Save. Function.
Channel1 message.
And what we're going to do here is we're going to...
Okay, so then...
It's connected to parent.
And now when I go into Power, iCode, iotpushparents, node1, index.js...
Oh, I know what's going on here.
There's running, and we should see, no, we don't see any messages.
So let's check the parents, and...
Oh, that's right, we have to get...
So we have to go to the browser and open a tab, and we're going to push...
Message published, message to main, and iotpushmain.
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 iotpush, 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.
Oops. There we go.
What exactly did we change?
Let's save it anyway.
And then it should send another set of messages. Oh, I can save.
Set 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 go to the front of it. I can't wait. And there's another iotpush main message.
Now we've got that. So let's start fleshing out this parent a little bit and start cleaning things up.
Okay.
What to do, what to do. 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. Okay.
parent publish. Shall we see access? And then Let's save this.
Make sure it's still running. Http is not defined.
We need to pull in http. There we go.
So we've got this set up.
It helps if I put these in strings.
Okay. So now we go to Chrome.
Chrome. Chrome. And we go to push2. This push2 don't know about this, so that's not the problem.
Was that an 8000?
It was 8000.
Okay, so that's why. Okay. Oh.
Wrong number of arguments for publish command.
Okay. Oh, okay.
So the child can't publish. Okay. That's strange.
Okay. Okay.
There we go.
Okay, so I was writing the head wrong. All right. We've got all that. Oh, Martin, you need to get a stretcher.
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, I think 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. Okay. Okay.
All right.
There we go.
Yes, you're getting something rebase.
Now we're going to make sure the code is updated on child.
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. And then log that access as a timestamp.
Okay.
Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay. Okay.
Okay. Okay. Okay.
Okay.
Okay.
Okay. All right. So. Priority.
Push. Local. Flash. Report. Maybe. On the parent. Okay.
Okay.
Slash.
Child. I'm just keeping like I have new messages but I do not have any new messages, just making sure I know the questions.
Okay. Okay, so, and then we're going to save this, I'm going to go to the parents.
Okay, so, I'm going to go to the parents, I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents, and I'm going to go to the parents.
I'm going to go to the parents.
I'm not even getting that far.
I'm not even getting there. Hmm. Hmm. Hmm.
Hmm.
Hmm.
Hmm.
Hmm.
Hmm.
Hmm.
Hmm.
Hmm. Hmm. Hmm. Hmm. Hmm. Hmm. Hmm. Hmm. Hmm. Well, it's Right.
Okay. Yes. Yeah.
Thank you. And then I got one.
Okay. 8,000 is open. Okay, so it's not that 8,000 is closed per se.
Okay. What's going on here. Have an idea.
Okay, so.
Okay.
And gateway. Oh. Okay.
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 you're either gonna get all this stuff.
So, Okay. Server.
I'm referring to server that way.
Okay. Really. Go here.
That's fine. Okay.
Okay, sweet.
Okay. Okay. Let's change the push just so we can see.
Okay. Okay.
Okay, but it's working, but it's saying bad gateway. That's really strange.