Giter Site home page Giter Site logo

node-esp's Introduction

An ESP8266 command line interface.

Flash NodeMcu firmware on a ESP8266 board, administer the file system and more.

Currently only Mac OS is fully supported.

Prerequisites

This module depends on SiLabs USB to UART bridge drivers. If you don't have them already installed, here you can find and download the driver.

Note that after installing the drivers you will have to restart your computer.

Currently it assumes that you have Python and pip installed.

Install

$ npm i -g node-esp

After installing or any time after upgrading the module, you have to set the name of the serial port we will use to communicate with the hardware.

This should list all available ports:

$ esp port list
┌────────────────────────────────────────┬────────────────────────────────────────┐
│ Port Name                              │ Manufacturer                           │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.Bluetooth-Incoming-Port        │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.Bluetooth-Modem                │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.gPhone                         │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.SLAB_USBtoUART                 │ Silicon Labs                           │
└────────────────────────────────────────┴────────────────────────────────────────┘

The last one is the SiLabs driver we installed, so, to set it:

$ esp port set /dev/cu.SLAB_USBtoUART
Port: /dev/cu.SLAB_USBtoUART

Installation Errors

Here are some common errors during the installation process and their quick fix.

npm i -g node-esp fails:

It could be a permissions issue. Regardless, if you run the following command on your terminal you wont break anything. Then install node-esp again.

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}`

If you see a similar error output to this, you might have to install pip.

Checking dependencies for esptool.py
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pip
child_process.js:518
    throw err;
    ^

Error: Command failed: python -c 'import pip; packages = pip.get_installed_distributions(); package_list = ["%s" % (i.key) for i in packages]; print(package_list)'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named pipo

    at checkExecSyncError (child_process.js:475:13)
    at execSync (child_process.js:515:13)
    at Module.module.exports (/Users/peperone/node-esp/scripts/postinstall:15:31)
    at Object.<anonymous> (/Users/peperone/node-esp/scripts/postinstall:25:8)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)

Just run the following command from terminal:

sudo easy_install pip

If you see a similar error, but the package is pyserial:

ImportError: No module named pyserial

Just run the following command from terminal:

sudo easy_install pyserial

Usage

To show a list of available commands and their description:

$ esp --help

The basic command format is as follows:

$ esp <command> [subcommand] [options]

Commands

port

port set

Sets the name of the serial port to use in future commands.

$ esp port set /dev/cu.SLAB_USBtoUART

port get

Displays the current port that is used.

$ esp port get
Port: /dev/cu.SLAB_USBtoUART

port list

Shows a list of all available ports:

$ esp port get
┌────────────────────────────────────────┬────────────────────────────────────────┐
│ Port Name                              │ Manufacturer                           │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.Bluetooth-Incoming-Port        │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.Bluetooth-Modem                │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.gPhone                         │                                        │
├────────────────────────────────────────┼────────────────────────────────────────┤
│ /dev/cu.SLAB_USBtoUART                 │ Silicon Labs                           │
└────────────────────────────────────────┴────────────────────────────────────────┘

file

file list

Lists the sizes and names of all files on the module.

$ esp file list
┌────────────────────────────────────────┬────────────────────┐
│ File                                   │ Size (bytes)       │
├────────────────────────────────────────┼────────────────────┤
│ hello_world.lua                        │ 24                 │
└────────────────────────────────────────┴────────────────────┘

file write <local_filename> [<remote_filename>]

Writes a file from the local file system to the module.

If a second filename is given, the local file will be renamed to this value on the device, else it will keep its local name.

$ esp file write ./app_init.lua init.lua

file push <local_filename> [<remote_filename>]

Alternative to esp file write that compress the file if they are of any of the following types:

  • Lua
  • HTML
  • JavaScript
  • CSS.
$ esp file push ./webserver.lua init.lua

file read <remote_filename>

Displays the content of a file from the module.

$ esp file read hello_world.lua
print("Hello World!")

file execute <remote_filename>

Executes the content of a Lua file on the module, returns the output.

$ esp file execute hello_world.lua
Hello World!

file remove <remote_filename>

Removes a file from the module.

$ esp file remove test.lua

restart

restart

Restarts the module.

$ esp restart

run

run <lua>

Runs Lua code on the module, returns the output.

$ esp run "print 'And all the insects ceased in honor of the moon.'"
And all the insects ceased in honor of the moon.

monitor

monitor

Displays the data received from the serial port.

$ esp monitor
Displaying output from port /dev/cu.SLAB_USBtoUART
Press ^C to stop.

fs

File system commands.

fs info

Shows information about the file system.

$ esp fs info

Total : 3381221 bytes
Used  : 502 bytes
Remain: 3380719 bytes

fs format

Formats the file system removing all user files.

$ esp fs format

info

info heap

$ esp fs format

info flash

Available flash memory.

$ esp info flash

info build

Build information.

  • majorVer (number)
  • minorVer (number)
  • devVer (number)
  • chipid (number)
  • flashid (number)
  • flashsize (number)
  • flashmode (number)
  • flashspeed (number)
$ esp info build

info chip

Returns chip id number.

$ esp info chip

wifi

wifi restore

$ esp wifi restore

wifi getip

$ esp wifi getip

esptool

Provides a helper command to flash a board using esptool

esptool flash <firmware>

The <firmware> parameter should be a valid path to a NodeMCU binary file.

$ esp esptool flash <firmware>

Roadmap

Use: https://github.com/inikulin/elegant-status

Add features:

  • repl (figure out if monitor is the same?)
  • compile lua files to lc (is luac -o app.lc app.lua the same as if we do on ESPLorer?)
  • Handle errors
  • Lua:
  • Restore WiFi settings: node.restore()
  • Handle Esptool python error: busy port
  • For HTML/CSS/JS files we might want to keep dir structure.
  • Move scripts/esptool.py to it's own directory scripts/esptool/esptool.py.

License

MIT

node-esp's People

Contributors

goliatone avatar paulcuth avatar abkonsta avatar mscolly avatar

Stargazers

Rizqy Prastya Ari Nugroho avatar Martin Muzatko avatar Taejun Kim avatar Konstantin Burkalev avatar Aleksandr Murin avatar

Watchers

 avatar James Cloos avatar

Forkers

hmarcano

node-esp's Issues

esp port busy notice

esp file write boot.lua
Ensure your port is not busy

Fix message, also, we need to stop spinner and return CLI.

python error

main() File "/Users/goliatone/.nvm/versions/node/v0.12.4/lib/node_modules/node-esp/scripts/esptool.py", line 575, in main esp = ESPROM(args.port, args.baud) File "/Users/goliatone/.nvm/versions/node/v0.12.4/lib/node_modules/node-esp/scripts/esptool.py", line 66, in __init__ self._port = serial.Serial(port) File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg/serial/serialutil.py", line 282, in __init__ File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg/serial/serialposix.py", line 289, in open OSError: [Errno 16] Resource busy: '/dev/cu.SLAB_USBtoUART'

file push: HTML/CSS/JS preserve directory structure on name

For HTML/CSS/JS files, we might want to mimic filesystem so that if we upload folder, we should have option to keep directory structure.

So, if directory structure:

- src
 | init.lua
 | app.lua
 | - public
     | - index.html
     | - style.css

Then, inside app, we can do file.open('public/index.html').

Command: esp file upload all

We want to be able to upload all lua files in an application directory.

Also, --watch option, and re-update? Or keep cache?

NodeMCU unresponsive to filesystem commands after flashing

I can't seem to reproduce this issue, but at some point between reloading/rerunning scripts the filesystem became unresponsive (e.g. esp file [...] and esp fs [...] would never complete).

Reflashing with esp flash [nodemcu firmware] didn't seem to solve the problem either. I was able to recover by manually flashing the firmware with esptool.py as follows:

python esptool.py -p /dev/cu.SLAB_USBtoUART -b 115200 write_flash 0x00000 [nodemcu firmware]

After this, the board started responding as expected and node-esp was able to successfully reflash the same firmware without issue.

Increase the speed after booting

On panics, monitoring sometimes outputs crap. See if it's related to baud rate.

NodeMCU serial interface uses 9600 baud at boot time. To increase the speed after booting, issue uart.setup(0,115200,8,0,1,1) (ESPlorer will do this automatically when changing the speed in the dropdown list).

If the device panics and resets at any time, errors will be written to the serial interface at 115200 bps.

Use easy_install

Currently the postinstall script tries to install PySerial using pip if the dependency is not met. pip might not be installed. We should either account for it or use easy_install.
Not directly related to this issue, buy maybe...

Handle esptool error when port is busy

Check the port is available before issuing the esp flash command- new issue.

PYTHON ERROR:
Traceback (most recent call last):
  File "/Users/goliatone/.nvm/versions/node/v0.12.4/lib/node_modules/node-esp/scripts/esptool.py", line 724, in <module>

PYTHON ERROR:
    main()
  File "/Users/goliatone/.nvm/versions/node/v0.12.4/lib/node_modules/node-esp/scripts/esptool.py", line 575, in main
    esp = ESPROM(args.port, args.baud)
  File "/Users/goliatone/.nvm/versions/node/v0.12.4/lib/node_modules/node-esp/scripts/esptool.py", line 66, in __init__
    self._port = serial.Serial(port)
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg/serial/serialutil.py", line 282, in __init__
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pyserial-2.7-py2.7.egg/serial/serialposix.py", line 289, in open
OSError: [Errno 16] Resource busy: '/dev/cu.SLAB_USBtoUART'

New command: remove init after reset connection

We have a deep-sleep mode, the init file has a one second delay between routines. Ideally we would have a routine to break the init loop.

We could do it by sending an specific command:

$ esp fs uninit

The idea is to send a reset command, and then as soon as we are connected and we can send commands, we send a file.remove("init.lua").

Currently we can use an IDE to do the same but it's tricky, and to do it through the CLI is more complicated since we have to have perfect timing which is hard...

postinstall: check for pip

We are relaying on the user having pip installed, we should check and if its not present then try to easy_install it:

  • check to see if have which pip, if null:
    • check to see if we can run easy_install without sudo
      • if we can, run easy_install pip
      • else sudo easy_install pip which will require a password.

Use update-notifier

In cli.js:

var pkg = require('../package.json'),
    updateNotifier = require('update-notifier');

/**********************************
 * NOTIFY IF WE HAVE NEW VERSION.
**********************************/
updateNotifier({pkg: pkg}).notify();

Handle esptool error when RST plugged to D0

Is there a way we can check to see if RST/D0 are wired together?
We should at least check for this error and provide better error messages and direct the user to check if the pins are connected... else provide a link to the repo and ask them to submit a ticket.


If we are in deep-sleep mode, then we have RST connected to D0, if we try to flash, then we get this error:

$ esp flash bin/nodemcu-master-9-modules-2016-04-12-21-59-18-float.bin 
Connecting...

A fatal error occurred: Failed to connect to ESP8266

The full esptool error:

$ esptool.py --port=/dev/cu.SLAB_USBtoUART write_flash -fm=dio -fs=32m -ff=40m 0x00000 bin/nodemcu-master-9-modules-2016-04-12-21-59-18-float.bin 
Connecting...
Traceback (most recent call last):
  File "/usr/local/bin/esptool.py", line 4, in <module>
    __import__('pkg_resources').run_script('esptool==0.1.0', 'esptool.py')
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-12.0.5-py2.7.egg/pkg_resources/__init__.py", line 696, in run_script
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/setuptools-12.0.5-py2.7.egg/pkg_resources/__init__.py", line 1621, in run_script
  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/esptool-0.1.0-py2.7.egg/EGG-INFO/scripts/esptool.py", line 532, in <module>

  File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/esptool-0.1.0-py2.7.egg/EGG-INFO/scripts/esptool.py", line 159, in connect

Exception: Failed to connect

esp port list

Add a column to esp port list to indicate if there is a port set, √, and if none set and we recognize one, suggest to use that port.

Maybe try to be smart and autoset? Or suggest on esp port get failure?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.