iHome- Internet based load controlling using NodeMCU

We have seen how to use MQTT on nodeMCU in previous post, But in that post we didn’t do any thing useful. In this post we will build a home load controlling system using nodemcu (Home Automation using nodemcu) and on client side we will use android app. We will be using MQTT to transfer the messages between nodemcu and android app.

Setting up MQTT

First we need a MQTT broker. If you already have a broker then you can skip this step.

1. Goto https://www.cloudmqtt.com/plans.html, try the free plan.

2. Create a user and set the ACL’s to the newly created user

Please refer this blog on how to create the MQTT broker.

Now we have the MQTT broker if you want play with the the MQTT , use the mqttspy app to publish/subscribe to the channels.

Loading Scripts :

Now we will load the scripts to nodeMCU. We have four lua scripts that needs to be loaded to the nodeMCU.

config.lua -> In this file we will store the wifi details , mqtt user details
setup.lua -> This script is responsible for making the wifi connection
app.lua -> This file contains the actual application logic
init.lua -> NodeMCU will execute this file on startup, we will use this script to bootstrap our application

The Only file you need make changes is the config.lua, you need add your wifi details and mqtt account details.


local module = {}

module.SSID = {}
module.SSID["wifiname"] = "wifi password"

module.HOST = "mqtt broker host name"
module.PORT = mqtt broker port
module.USERNAME = "mqtt account user name"
module.PASSWORD = "mqtt account password"
module.ID = node.chipid()

module.ENDPOINT = "/nodemcu/"..node.chipid()
return module

All the source files are available on github along with the android application. Install android application and login to the app.

Once you have updated this file, you can upload all the four files to the nodeMCU. you can refer to this blog if  don’t know how to upload the scripts.

https://youtu.be/XXb2kavvTlo

 

Add a Comment

Your email address will not be published. Required fields are marked *