GithubHelp home page GithubHelp logo

middelbh / nodemcu-firmware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nodemcu/nodemcu-firmware

1.0 1.0 0.0 4.48 MB

lua based interactive firmware for mcu like esp8266

Home Page: http://nodemcu.com

License: MIT License

Makefile 1.37% C 93.97% C++ 3.09% Lua 1.57%

nodemcu-firmware's Introduction

NodeMcu

version 0.9.5 ###A lua based firmware for wifi-soc esp8266 Build on ESP8266 sdk 0.9.5
Lua core based on eLua project
File system based on spiffs
Open source development kit for NodeMCU nodemcu-devkit
Flash tool for NodeMCU nodemcu-flasher

wiki: nodemcu wiki
home: nodemcu.com
bbs: 中文论坛Chinese bbs
Tencent QQ group QQ群: 309957875

Summary

  • Easy to access wireless router
  • Based on Lua 5.1.4 (without io, math, debug, os module.)
  • Event-Drive programming preferred.
  • Build-in file, timer, pwm, i2c, 1-wire, net, gpio, wifi, adc, uart and system api.
  • GPIO pin re-mapped, use the index to access gpio, i2c, pwm.

To Do List (pull requests are very welcomed)

  • fix wifi smart connect
  • add spi module
  • add mqtt module
  • add coap module

Change log

2015-01-18
merge mqtt module to new branch mqtt from https://github.com/tuanpmt/esp_mqtt.
merge spi module from iabdalkader:spi.
fix #110,set local port to random in client mode.
modify gpio.read to NOT set pin to input mode automatic.
add PATH env with C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\Python27 in eclipse project. resolve #103.

2015-01-08
fix net.socket:send() issue when multi sends are called.
NOTE: if data length is bigger than 1460, send next packet AFTER "sent" callback is called.
fix file.read() api, take 0xFF as a regular byte, not EOF.
pre_build/latest/nodemcu_512k_latest.bin is removed. use pre_build/latest/nodemcu_latest.bin instead.

more change log
更多变更日志

##GPIO NEW TABLE ( Build 20141219 and later)

IO indexESP8266 pinIO indexESP8266 pin
0 [*]GPIO168GPIO15
1GPIO59GPIO3
2GPIO410GPIO1
3GPIO011GPIO9
4GPIO212GPIO10
5GPIO14
6GPIO12
7GPIO13
#### [*] D0(GPIO16) can only be used as gpio read/write. no interrupt supported. no pwm/i2c/ow supported.

##GPIO OLD TABLE (Before build 20141212)

IO indexESP8266 pinIO indexESP8266 pin
0GPIO128GPIO0
1GPIO139GPIO2
2GPIO1410GPIO4
3GPIO1511GPIO5
4GPIO3
5GPIO1
6GPIO9
7GPIO10

#Build option ####file ./app/include/user_config.h

// #define FLASH_512K
// #define FLASH_1M
// #define FLASH_2M
// #define FLASH_4M
#define FLASH_AUTOSIZE
...
#define LUA_USE_MODULES
#ifdef LUA_USE_MODULES
#define LUA_USE_MODULES_NODE
#define LUA_USE_MODULES_FILE
#define LUA_USE_MODULES_GPIO
#define LUA_USE_MODULES_WIFI
#define LUA_USE_MODULES_NET
#define LUA_USE_MODULES_PWM
#define LUA_USE_MODULES_I2C
#define LUA_USE_MODULES_TMR
#define LUA_USE_MODULES_ADC
#define LUA_USE_MODULES_UART
#define LUA_USE_MODULES_OW
#define LUA_USE_MODULES_BIT
#endif /* LUA_USE_MODULES */

#Flash the firmware nodemcu_latest.bin: 0x00000
for most esp8266 modules, just pull GPIO0 down and restart.
You can use the nodemcu-flasher to burn the firmware.

Or, if you build your own bin from source code.
eagle.app.v6.flash.bin: 0x00000
eagle.app.v6.irom0text.bin: 0x10000
esp_init_data_default.bin: 0x7c000
blank.bin: 0x7e000

Better run file.format() after flash

#Connect the hardware in serial baudrate:9600

#Start play

####Connect to your ap

    ip = wifi.sta.getip()
    print(ip)
    --nil
    wifi.setmode(wifi.STATION)
    wifi.sta.config("SSID","password")
    ip = wifi.sta.getip()
    print(ip)
    --192.168.18.110

####Manipulate hardware like a arduino

    pin = 1
    gpio.mode(pin,gpio.OUTPUT)
    gpio.write(pin,gpio.HIGH)
    print(gpio.read(pin))

####Write network application in nodejs style

    -- A simple http client
    conn=net.createConnection(net.TCP, 0) 
    conn:on("receive", function(conn, payload) print(payload) end )
    conn:connect(80,"115.239.210.27")
    conn:send("GET / HTTP/1.1\r\nHost: www.baidu.com\r\n"
        .."Connection: keep-alive\r\nAccept: */*\r\n\r\n")

####Or a simple http server

    -- A simple http server
    srv=net.createServer(net.TCP) 
    srv:listen(80,function(conn) 
      conn:on("receive",function(conn,payload) 
        print(payload) 
        conn:send("<h1> Hello, NodeMcu.</h1>")
      end) 
      conn:on("sent",function(conn) conn:close() end)
    end)

####Do something shining

  function led(r,g,b) 
    pwm.setduty(1,r) 
    pwm.setduty(2,g) 
    pwm.setduty(3,b) 
  end
  pwm.setup(1,500,512) 
  pwm.setup(2,500,512) 
  pwm.setup(3,500,512)
  pwm.start(1) 
  pwm.start(2) 
  pwm.start(3)
  led(512,0,0) -- red
  led(0,0,512) -- blue

####And blink it

  lighton=0
  tmr.alarm(1,1000,1,function()
    if lighton==0 then 
      lighton=1 
      led(512,512,512) 
    else 
      lighton=0 
      led(0,0,0) 
    end 
  end)

####If you want to run something when system started

  --init.lua will be excuted
  file.open("init.lua","w")
  file.writeline([[print("Hello, do this at the beginning.")]])
  file.close()
  node.restart()  -- this will restart the module.

####With below code, you can telnet to your esp8266 now

    -- a simple telnet server
    s=net.createServer(net.TCP,180) 
    s:listen(2323,function(c) 
       function s_output(str) 
          if(c~=nil) 
             then c:send(str) 
          end 
       end 
       node.output(s_output, 0)   -- re-direct output to function s_ouput.
       c:on("receive",function(c,l) 
          node.input(l)           -- works like pcall(loadstring(l)) but support multiple separate line
       end) 
       c:on("disconnection",function(c) 
          node.output(nil)        -- un-regist the redirect output function, output goes to serial
       end) 
       print("Welcome to NodeMcu world.")
    end)

####Use DS18B20 module extends your esp8266

    -- read temperature with DS18B20
    t=require("ds18b20")
    t.setup(9)
    addrs=t.addrs()
    -- Total DS18B20 numbers, assume it is 2
    print(table.getn(addrs))
    -- The first DS18B20
    print(t.read(addrs[1],t.C))
    print(t.read(addrs[1],t.F))
    print(t.read(addrs[1],t.K))
    -- The second DS18B20
    print(t.read(addrs[2],t.C))
    print(t.read(addrs[2],t.F))
    print(t.read(addrs[2],t.K))
    -- Just read
    print(t.read())
    -- Just read as centigrade
    print(t.read(nil,t.C))
    -- Don't forget to release it after use
    t = nil
	ds18b20 = nil
    package.loaded["ds18b20"]=nil   

nodemcu-firmware's People

Contributors

alonewolfx2 avatar baracudaz avatar dvv avatar follower avatar funshine avatar ghx111111 avatar iabdalkader avatar javieryanez avatar kmpm avatar rkoffer avatar tobiebooth avatar vowstar avatar

Stargazers

 avatar

Watchers

 avatar

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.