How to create an office or studio status indicator and doorbell with NodeMCU Part #3

Author:

Anders Kitson

This is part 3 of the series on how to create a status indicator. We are going to start by creating a secondary device where we run through many of the same steps as before.

Here is the video walk through

So step 1 is to plug you development board into your breadboard we again are using the keeyees node mcu esp8266 development board .

Then we will want to open up mos from our terminal mos

Then inside of mongoose os you can clone the demo-js repo

mos clone https://github.com/mongoose-os-apps/demo-js wispy-series-2

The name of the directory we created is chosend because we are working on the second board

Next we want to hook up the red led with a 100ohm resistor to from the positive end of the led, generally the longer end to the positive strip on the breadboard and then a jumper cable from the positive end to the 3v3, and then from the other end of the led a jumper cable to pin d5. As seen below

red led breadboard setup

Open up your init.js file of this project in your code editor

Once inside your code editor we are going to try and write a 0 to pin 14. Add the following code in your init.js

//...

GPIO.set_mode(14,GPIO.MODE_OUTPUT);
GPIO.write(14,0)

//...

After you have saved you will want to run

mos build

mos flash

and you red led should turn on

red led is on

Next we are going to hook up the button.

  1. Connect one corner of the button to the ground
  2. The other end of the button to pin d3 which is the flash button

button breadboard setup

To test that it's working you can press the button and you should get a not connected in your serial console, that means the button is hooked up you are just not connected to aws IoT.

Next is to hook up to wifi and aws with the following commands in mongoose os

mos wifi wifiname password

mos aws-iot-setup --aws-region us-east-1

Once that is setup we will get a online true in our serial console and if you hit the button we will get a publishing message.

Go back into init.js and edit the setLED function

We are adding a boolean state check on our red led so we can send a request to it from the other device and eventually both ways.

Add the following line to the setLED function, and delete the previous GPIO.write(14,0) we had setup.

let setLED = function(on){
  //...
  GPIO.write(14, on ? 0 : 1)
} 

Then you are going to want to run the following commands in mongoose os

mos build

mos flash

mos wifi wifiname password

mos aws-iot-setup --aws-region us-east-1

desired state

Next we want to go to aws console -> IoT core -> things -> our new board -> shadows -> classic shadow -> edit and add the following state.

{
  "desired":{
    "on":true
  },
  ...
}

The red led should turn on. If you want to turn the red led off you change the state to false.

What this allows us to do is hit the interact url see below and change the state via shadows and update the led. You have to ido it with a authenticated post request, I am going to use a IAM user auth.

Interact URL

Next create a EC2 instance in aws console (ubuntu server 18.04) free tier

You can choose t2.micro is just fine, you can leave the storage and you can give a Name tag if you like to identify it better, and you will need to add a security group of HTTP port 80 source anywhere seen below.

Security Groups

Click launch and create a new key pair with a descriptive name

Next launch the instance open it up it aws console and copy and past it's public IPv4 DNS address

Copy this address from your instance

Connect to our instance

open up your ssh config at ~/.ssh/config

write the following replacing your ip address you just copied

HostName ec2-52-7-131-103.compute-1.amazonaws.com
  User ubuntu
  port 22
  IdentitiesOnly yes
  IdentityFile ~/.ssh/wispy-api.pem

move you downloaded *.pem file to your ~/.ssh directory and chmod it with the following

sudo chmod 600 ~/.ssh/wispy-api.pem

then you can connect to your instance with

ssh ubuntu

That's it we will continue this is the next part of the series