Share My Creation Android smart watch ZGPAX and WIFI low cost module ESP8266 for SMART HOME

Discussion in 'Share Your Creations' started by alexhi, Jan 25, 2015.

  1. alexhi

    alexhi Member Licensed User

    I write little app for Android watch (or smartphone) and esp8266.It's not a bad thing for the smart home.Сost module ~3,5$!!!
    module ESP8266
    [​IMG]

    Corresponding Interface:
    SDIO 2.0, SPI, UART
    32-pin QFN package
    Integrated RF switch, balun, 24dBm PA, DCXO, and PMU
    Integrated RISC processor, on-chip memory and external memory interfaces
    Integrated MAC/baseband processors
    Quality of Service management
    I2S interface for high fidelity audio applications
    On-chip low-dropout linear regulators for all internal supplies
    Proprietary spurious-free clock generation architecture
    Integrated WEP, TKIP, AES, and WAPI engines

    Specification:
    802.11 b/g/n
    Wi-Fi Direct (P2P), soft-AP
    Integrated TCP/IP protocol stack
    Integrated TR switch, balun, LNA, power amplifier and matching network
    Integrated PLLs, regulators, DCXO and power management units
    +19.5dBm output power in 802.11b mode
    Power down leakage current of <10uA
    Integrated low power 32-bit CPU could be used as application processor
    SDIO 1.1/2.0, SPI, UART
    STBC, 1×1 MIMO, 2×1 MIMO
    A-MPDU & A-MSDU aggregation & 0.4ms guard interval
    Wake up and transmit packets in < 2ms
    Standby power consumption of < 1.0mW (DTIM3)




    That it is able my app to :
    - read the temperature DS18B20
    - turn ON/OFF relay (button or voice)
    - considered on time relay (save flash memory)
    how it looks like:
    [​IMG]
    setting:
    [​IMG]

    I made a simple development board

    [​IMG]

    PHOTO
    [​IMG]

    I write LUA SCRIPT UDP SERVER for module

    Code:
    counter=0
    GCOUNTER=
    0
    port=
    7777
    stled=
    0
    pinled=
    9

    pin = 
    8
    ow.setup(pin)
    TEMP=
    0
    counter=
    0
    lasttemp=-
    999



    function Init()
    print(
    "LT205WF V1.0")
    pinled=
    9
    gpio.mode(pinled, gpio.OUTPUT)
    gpio.write(pinled, gpio.LOW)
    if file.open("ltimer.log""r")== nil then
    file.remove("ltimer.log")
    file.open("ltimer.log""w")
    file.writeline(GCOUNTER)
    file.close()
    else
    GCOUNTER=
    file.readline()
    file.close()
    end
    end


    function bxor(a,b)
    local r = 
    0
    for i = 031 do
    if ( a % 2 + b % 2 == 1 ) then
    r = r + 
    2^i
    end
    a = a / 
    2
    b = b / 
    2
    end
    return r
    end

    function ShowTemp()
    getTemp()
    t1 = lasttemp / 
    10000
    t2 = (lasttemp >= 
    0 and lasttemp % 10000or (10000 - lasttemp % 10000)
    t2 =t2 / 
    100
    --print(
    "!TEMP" .. t1 .. "." .. string.format("%2d", t2) .."\r")
    TEMP= t1 .. 
    "." .. string.format("%d", t2)
    --print(TEMP)
    end

    function getTemp()
    addr = ow.reset_search(pin)
    repeat
    tmr.wdclr()

    if (addr ~= nil) then
    crc = ow.crc8(
    string.sub(addr,1,7))
    if (crc == addr:byte(8)) then
    if ((addr:byte(1) == 0x10or (addr:byte(1) == 0x28)) then
    ow.reset(pin)
    ow.select(pin, addr)
    ow.write(pin, 
    0x441)
    tmr.delay(
    1000000)
    present = ow.reset(pin)
    ow.select(pin, addr)
    ow.write(pin,
    0xBE1)
    data = nil
    data = 
    string.char(ow.read(pin))
    for i = 18 do
    data = data .. 
    string.char(ow.read(pin))
    end
    crc = ow.crc8(
    string.sub(data,1,8))
    if (crc == data:byte(9)) then
    t = (data:byte(
    1) + data:byte(2) * 256)
    if (t > 32768then
    t = (bxor(t, 
    0xffff)) + 1
    t = (-
    1) * t
    end
    t = t * 
    625
    lasttemp = t
    --print(
    "Last temp: " .. lasttemp)
    end
    tmr.wdclr()
    end
    end
    end
    addr = ow.search(pin)
    until(addr == nil)
    end

    ----------------MAIN FUNCTION-----------------------
    Init()
    srv=net.createServer(net.UDP)
    srv:on(
    "receive", function(srv, pl)
    print(pl)
    if pl=="!SetR1_1\r" then
    gpio.write(pinled, gpio.HIGH)
    stled=
    1
    counter=
    0
    srv:send(
    "!LEDON\r")
    end
    if pl=="!SetR0_1\r" then
    gpio.write(pinled, gpio.LOW)
    stled=
    0
    srv:send(
    "!LEDOFF\r")
    file.open("ltimer.log""w")
    file.write(GCOUNTER)
    file.close()

    end

    if pl=="!GetR_1\r" then
    if stled ==1 then
    srv:send(
    "!LEDON\r")
    else
    srv:send(
    "!LEDOFF\r")
    end
    end
    if pl=="!GetCount\r" then
    srv:send(
    "!COUNT "..counter.."\r")
    end
    if pl=="!GetGcount\r" then
    srv:send(
    "!GCOUNT "..GCOUNTER.."\r")
    end
    if pl=="!GetC_1\r" then
    print(ShowTemp())
    srv:send(
    "!TEMP"..TEMP.."\r")
    end
    if pl=="!ClrCount\r" then
    GCOUNTER=
    0
    srv:send(
    "!GCOUNT=0\r")
    end
    if pl=="!GetIp\r" then
    srv:send(
    "!IP "..wifi.sta.getip().."\r")
    end

    end)
    srv:listen(port)
    uart.on("data",function(data)srv:send(data)end1)
    --
    timer 1
    tmr.alarm(
    2,60000,1, function()
    if stled==1 then
    counter=counter+
    1
    GCOUNTER=GCOUNTER+
    1
    --print(counter)
    end
    end )


     

    Attached Files:

    Last edited: Jan 25, 2015
    f0raster0, ellpopeb4a, daemon and 7 others like this.
  2. JordiCP

    JordiCP Well-Known Member Licensed User

    Wow!

    I just bought a couple of these modules a week ago and find they are really amazing (I have just ordered 2 Es-07 now to have more available pins and play with them) In my case I needed to use them as a serial to wifi modem so I work with the AT version, but would like to use it for other cases.

    Have seen a lot of doc in the web, but still don't have it totally clear. Do you think the LUA firmware version is the best for self-contained apps?

    These modules/chips will make IOT explode soon
     
  3. alexhi

    alexhi Member Licensed User

    With Lua can not use a microprocessor and it's a big +++ :)
    I make transparent bridge UDP<-->UART on Lua
    Code:
    --Init.lua
    PORT=
    7777 pin=3
    gpio.mode(pin, gpio.INPUT)
    tmr.alarm(
    1,50001, function()
    if wifi.ap.getip()~=nil  then
    if gpio.read(pin)==1 then
    tmr.stop(
    1) print("WIFI_UDP_RS232 V1.1 06.01.2015")
    else
    tmr.stop(
    1) print("Telnet V1.1") dofile("telnet.lua")
    end end end)
    uart.setup( 0,96008010 )
    srv=net.createServer(net.UDP)
    srv:on(
    "receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)
    srv:listen(PORT) 
    uart.on("data",0,function(data)srv:send(data)end0)
     
    Last edited: Jan 26, 2015
  4. freedom2000

    freedom2000 Well-Known Member Licensed User

    I like these tiny modules.

    BTW, for the moment I am still more "fluent" with Microchip's PICs but I must admit that hte price and the power of these devices are a must

    Bravo
     
  5. freedom2000

    freedom2000 Well-Known Member Licensed User

    Well I have just ordered one of these modules. I have choosen the 01 version with standard firmware.

    For your application did you reflash the firmware ? and which one did you choose ?

    thanks
     
  6. alexhi

    alexhi Member Licensed User

    Hi, this firmware LUA: https://github.com/nodemcu/nodemcu-firmware
     
  7. freedom2000

    freedom2000 Well-Known Member Licensed User

    Thanks for the link.

    BTW I have seen that this module has a SPI bus embeded.
    Do you know if there is a simple way to use this bus instead of the RS232 one ?
     
  8. alexhi

    alexhi Member Licensed User

    KIA OTE="freedom2000, post: 314945, member: 60910"]Thanks for the link.

    BTW I have seen that this module has a SPI bus embeded.
    Do you know if there is a simple way to use this bus instead of the RS232 one ?[/QUOTE]
    LUA for esp8266 have module for SPI over GPIO. You may use it.
     
  9. freedom2000

    freedom2000 Well-Known Member Licensed User

    Thank you !

    I will have to learn LUA :)
     
  10. alexhi

    alexhi Member Licensed User

    Success! :)
     
  11. freedom2000

    freedom2000 Well-Known Member Licensed User

    Hi again,

    I have finshed a small app to control RGB LedStrip.

    As you can see I would like to remove my MCU board and use the ESP8266 module instead.
    My wish is to use SPI master mode.
    I have not yet the ESP module (China is far away from France !)
    I have read the nodeMCU API and it seems that the clock control is not yet available

    spi.setup()
    Description
    setup spi configuration.

    Syntax
    spi.setup( id, mode, cpol, cpha, databits, clock )

    Parameters
    id: spi id number.
    mode: MASTER or SLAVE(not supported yet).
    cpol: CPOL_LOW or CPOL_HIGH, clock polarity.
    cpha: CPHA_HIGH or CPHA_LOW, clock phase.
    databits: DATABITS_8 or DATABITS_16.
    clock: spi clock (not supported yet).

    Do you have an idea of the current clock frequency ?
    When they say that spi clock is not supported does it mean that there is no clock or a fixed one ?

    I do need a clock for these Leds...

    Thanks again
     
  12. alexhi

    alexhi Member Licensed User

  13. freedom2000

    freedom2000 Well-Known Member Licensed User

    Thank you

    This sounds good !
    I only need MOSI and Clock in master mode.
    GPIO12 - MISO
    GPIO13 - MOSI
    GPIO14 - CLK
    GPIO15 - CS (with an 10k pulldown to ground so the ESP8266 will boot up)

    So GPIO13 and GPIO14 will be enough.

    Could you please give me a link on how to upload this LUA firmware to the device.
    I am a little confused with the documentation... Absolute beginner for this board !
     
  14. alexhi

    alexhi Member Licensed User

  15. freedom2000

    freedom2000 Well-Known Member Licensed User

    Thanks a lot for the zip

    I am still waiting for the device...

    I have read that it would be possible to increase the baud rate above 115200. Did you try it ?

    Another question : if I flasjh the nodeMCU firmware, is it possible to go back to the original one ?
     
  16. alexhi

    alexhi Member Licensed User

    Yes, You can go back.

    Good news. NodeMCU (Lua) support MQTT. I try it. :)
     
  17. freedom2000

    freedom2000 Well-Known Member Licensed User

    Did you try more than 115200 bauds (I mean 230400 or more ?)

    I ordered my ESP 21 days ago... sooo long !
     
  18. freedom2000

    freedom2000 Well-Known Member Licensed User

    Hi again,

    I finally got my ESP8266 and spent a lot of time with it :)

    Currently I have played with AT firmware and successfuly communicated via TCP
    I have also flashed lua, read all the post and found you here : http://www.esp8266.com/viewtopic.php?f=19&t=904 (well was easy !)

    I have also installed the windows C environment ans successfuly compiled examples (but API is not easy for me)

    SO I jumped back to Lua and tried to play with it.
    My feeling is that it is quite easy to have something working
    But the speed is not very fast (interpreted language) and thus not relevant for my use case (where high speed SPI is needed)

    Well I wil go on playing with this chip for some IOT sensors.
     
  19. alexhi

    alexhi Member Licensed User

    Hi !
    You can try node.compile() for fast work programm. I'm doing relay control via the Internet (2G/3G).MQTT broker iot.eclipse.org.Work ОК.
    [​IMG]
     
    freedom2000 likes this.
  20. freedom2000

    freedom2000 Well-Known Member Licensed User

    thank you for the trick "node.compile()". I will try it

    I must say that these devices are incredibly powerfull for the price !
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice