NodeMCU Config: Difference between revisions

From Network Security Wiki
Content added Content deleted
Line 14: Line 14:


*Check the firmware integrity:
*Check the firmware integrity:

import esp
<syntaxhighlight lang="python">
esp.check_fw()
import esp
esp.check_fw()
</syntaxhighlight>


== Connecting ==
== Connecting ==
Line 23: Line 26:


*Via REPL(web):
*Via REPL(web):

import webrepl_setup
<syntaxhighlight lang="python">
import webrepl_setup
</syntaxhighlight>


*If you disabled automatic start-up on boot, you may run configured daemon on demand using:
*If you disabled automatic start-up on boot, you may run configured daemon on demand using:

import webrepl
<syntaxhighlight lang="python">
webrepl.start()
import webrepl
webrepl.start()
</syntaxhighlight>


* Upload data using Serial Port
* Upload data using Serial Port
Line 36: Line 45:


*Checking filesystem:
*Checking filesystem:

import os
<syntaxhighlight lang="python">
os.listdir()
import os
os.listdir()
</syntaxhighlight>


*Create directories:
*Create directories:
<syntaxhighlight lang="python">
os.mkdir('dir')
os.mkdir('dir')
</syntaxhighlight>


*Remove Files:
*Remove Files:
<syntaxhighlight lang="python">
os.remove('data.txt')
os.remove('data.txt')
</syntaxhighlight>


*Reading data:
*Reading data:
<syntaxhighlight lang="python">
f = open('data.txt')
f = open('data.txt')
f.read()
f.close()
f.read()
f.close()
</syntaxhighlight>


*Writing Data to files:
*Writing Data to files:
<syntaxhighlight lang="python">
f = open('data.txt', 'w')
f.write('some data')
f = open('data.txt', 'w')
f.write('some data')
f.close()
f.close()
</syntaxhighlight>


*Checking Machine Frequency & Overclocking:
*Checking Machine Frequency & Overclocking:
<syntaxhighlight lang="python">
import machine
import machine
machine.freq() # get the current frequency of the CPU
machine.freq(160000000) # set the CPU frequency to 160 MHz
machine.freq() # get the current frequency of the CPU
machine.freq(160000000) # set the CPU frequency to 160 MHz
</syntaxhighlight>


*Check AP Name:
*Check AP Name:
<syntaxhighlight lang="python">
import network
ap = network.WLAN(network.AP_IF)
import network
ap = network.WLAN(network.AP_IF)
print(ap.config('essid'))
print(ap.config('essid'))
</syntaxhighlight>


*Change AP name and password:
*Change AP name and password:
<syntaxhighlight lang="python">
import network
ap = network.WLAN(network.AP_IF)
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.active(True)
ap.config(essid='MyESP8266', authmode=network.AUTH_WPA_WPA2_PSK, password='mypassword')
ap.config(essid='MyESP8266', authmode=network.AUTH_WPA_WPA2_PSK, password='mypassword')
print(ap.config('essid'))
print(ap.config('essid'))
</syntaxhighlight>


*Turning off AP:
*Turning off AP:
<syntaxhighlight lang="python">
ap = network.WLAN(network.AP_IF)
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.active(True)
</syntaxhighlight>


== Boot Process ==
== Boot Process ==
Line 82: Line 110:
but instead it’s recommended to keep your application(s) in separate files, and have just the following in main.py:
but instead it’s recommended to keep your application(s) in separate files, and have just the following in main.py:


<syntaxhighlight lang="python">
import my_app
my_app.main()
import my_app
my_app.main()

</syntaxhighlight>


= Lua =
{{UC}}





Revision as of 13:18, 26 January 2018


Micropython

Installation

  • Flashing Micropython

Download firmware file from micropython.org

sudo pip install esptool
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 ~/Desktop/esp8266-20171101-v1.9.3.bin
  • Check the firmware integrity:
import esp
esp.check_fw()

Connecting

  • Via Terminal:
sudo apt install picocom
picocom /dev/ttyUSB0 -b115200
  • Via REPL(web):
import webrepl_setup
  • If you disabled automatic start-up on boot, you may run configured daemon on demand using:
import webrepl
webrepl.start()
  • Upload data using Serial Port
sudo pip install adafruit-ampy
ampy --port /dev/ttyUSB0 put ~/Desktop/main.py

File System

  • Checking filesystem:
import os
os.listdir()
  • Create directories:
os.mkdir('dir')
  • Remove Files:
os.remove('data.txt')
  • Reading data:
f = open('data.txt')
f.read()
f.close()
  • Writing Data to files:
f = open('data.txt', 'w')
f.write('some data')
f.close()
  • Checking Machine Frequency & Overclocking:
import machine
machine.freq()                # get the current frequency of the CPU
machine.freq(160000000)       # set the CPU frequency to 160 MHz
  • Check AP Name:
import network
ap = network.WLAN(network.AP_IF)
print(ap.config('essid'))
  • Change AP name and password:
import network
ap = network.WLAN(network.AP_IF)
ap.active(True)
ap.config(essid='MyESP8266', authmode=network.AUTH_WPA_WPA2_PSK, password='mypassword')
print(ap.config('essid'))
  • Turning off AP:
ap = network.WLAN(network.AP_IF)
ap.active(True)

Boot Process

As a final step of boot procedure, main.py is executed from filesystem
This file is a hook to start up a user application each time on boot (instead of going to REPL). 
For small test applications, you may name them directly as main.py
but instead it’s recommended to keep your application(s) in separate files, and have just the following in main.py:
import my_app
my_app.main()

Lua

        This section is under construction.



References





{{#widget:DISQUS |id=networkm |uniqid=NodeMCU Config |url=https://aman.awiki.org/wiki/NodeMCU_Config }}