Connecting NodeMcu to a network using Micro Python

How to Connect NodeMCU to a Network using Micro Python language & Esplorer IDE

In this my blog series dedicated for explaining how to make an Internet of Things project using NodeMCU that aims at reading and sending data to a website and making an action using the same website.
 ESP-12E Development Board will be used. This board is based on ESP8266, integrates microcontroller capabilities and WiFi in one board. It could be coded like Micro Python language using Esplorer.

Here in this blog I have written about to connect to a network using micropython language.
The network module is used to configure the WiFi connection. 
There are two WiFi interfaces
1. one for the station (when the NODEMCU connects to a router) 
2. one for the access point (for other devices to connect to the NODEMCU).
Here we are connecting NodeMcu to a Router.

Step 1: For connecting your NodeMcu to network first open the Esplorer and then connect your board with baud rate of '115200'
Step 2: When the board is connected , write a small python program in the left side window of the Esplorer. We can also write our program on the terminal also.
Micro Python program for connecting it to Router.
........................................................................................................................................
import network
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('<essid>', '<password>')
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
............................................................................................................................................

Once the device is connected we can check  its I.P address by writing this on terminal
>>>sta_if.ifconfig()
('192.138.0.5', '255.255.255.0','192.168.0.5', '8.8.8.8')
After this your NodeMcu will be connected to a router.
In my next blog I will discuss "how to connect your NodeMcu to MQTT broker and
bring your data on Node-Red
" which is one of the important part for IOT project/product development.
 



Comments

Popular posts from this blog

Finding Time elapsed in doing work using MicroPython