Shop OBEX P1 Docs P2 Docs Learn Events
Low cost wifi module ESP8266 - Page 5 — Parallax Forums

Low cost wifi module ESP8266

1235718

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-21 23:35
    Some success...

    I am using PST and my PropPlug connected to the ESP8266-01.

    GPIO0 to 3V3 (tie to GND to program). When nc, it failed.
    CH_PD is tied to 3V3
    RST is nc, GPIO2 is nc
    AT<crlf>
    [I]responds OK[/I]
    AT+GMR<crlf>
    [I]responds with fw revision - mine is 00150900 which is quite old as I have had the board for 6+ months[/I]
    AT+RST<crlf>
    [I]reports lots of info[/I]
    AT+CWMODE=3<crlf>
    AT+CWLAP<crlf>
    [I]responds with a list of available access points[/I]
    AT+CWJAP="..ssid..","..pswd.."<crlf>
    AT+CWJAP?<crlf>
    [I]responds with connected access point[/I]
    AT+CIFSR<crlf>
    [I]responds with allocated IP address[/I]
    AT+CIPMUX=1<crlf>
    [I]set single connection[/I]
    AT+CIPSTART=0,"TCP","www.google.com",80<crlf>
    [I]should connect and respond with OK linked[/I]
    AT+CIPSEND=0,7<crlf>
    [I]responds with ">" and waits for the 7 characters an no crlf[/I]
    GET /
    [I]responds with SEND OK, but no response from google ???[/I]
    
    [I]To close...[/I]
    AT+CIPCLOSE=0<crlf>
    [I]responds with OK Unlink[/I]
    AT+CWQAP<crlf>
    [I]responds with OK[/I]
    [I]can follow with..[/I]
    AT+CWJAP="",""<crlf>
    

    Additional Commands (not tried, but here for reference)..
    AT+CWQAP<crlf>
    [I]quits the access point[/I]
    AT+CWJAP="",""<crlf>
    [I]issue after a reset command to clear ssid/pswd[/I]
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-23 18:16
    Some more code working. This is written in Spin and will connect to www.parallax.com and print out the html of the website.

    You will need to change the router to your particular router and password.

    Spin is working much better than Arduino C. The arduino just can't handle the speed with which the data comes back and misses blocks of the html code. In the arduino uno, if you try to store it as it comes in, it slows things down further. And if you try to store it in a huge buffer, it runs out of ram for other things.

    Spin on the other hand can easily gobble up bytes at 9600, and I have no doubt, even faster.

    Attached code to send an html request to www.parallax.com

    also can upload data to xively. Next step - downloading data from xively. This might seem a bit strange but there is some method to this madness - with setting up local servers it is difficult to get the ip address to stay static. I think there is a new version of the ESP module that can do this but not any I have. So you might set it all up and it works for weeks then you reboot your router and the IP addresses all change and it stops working.

    However this problem is avoided by using xively. Also xively can draw graphs of data, plus the data is global. It is password protected - if you use this then it would help to get a personal free xively account rather than using mine.

    This is all working very well :)
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-23 22:32
    Nice work Drac.

    I have progressed. Today I programmed nodeMCU, then updated to the latest firmware.
    Connected to my AP, connected to google.com to get the time, connected to benlo.com and received the info I sent.

    I am not sure how this all works, but I have a free account at no-ip.com which covers the problem of dynamic ip addresses. I needed this when I was testing the WR703's.
    I presume it maintains a lookup table for your "username" to the current IP. Of course, this relies on your router/device sending its new ip address when it changes.

    I will lookup xively and see if this is similar.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-24 09:06
    I made some stresstesting:

    I uploaded a lua-script that does read a DS1820-Sensor evey 5 seconds.
    then connects to thingspeak.com sending the temperature-data then disconnects.

    -- Measure temperature and post data to thingspeak.com
    -- 2014 OK1CDJ
    --- Tem sensor DS18B20 is conntected to GPIO0
    --- 2015.01.21 sza2 temperature value concatenation bug correction
    --- Stefan Ludwig: 16.03.2015 modified for use with DS1820 (which has 9bit resolution 0.5°C precisision
    pin = 3
    ow.setup(pin)
    
    counter=0
    lasttemp=-999
    
    function bxor(a,b)
       local r = 0
       for i = 0, 31 do
          if ( a % 2 + b % 2 == 1 ) then
             r = r + 2^i
          end
          a = a / 2
          b = b / 2
       end
       return r
    end
    
    --- Get temperature from DS18B20 
    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) == 0x10) or (addr:byte(1) == 0x28)) then
                    ow.reset(pin)
                    ow.select(pin, addr)
                    ow.write(pin, 0x44, 1)
                    tmr.delay(1000000)
                    present = ow.reset(pin)
                    ow.select(pin, addr)
                    ow.write(pin,0xBE, 1)
                    data = nil
                    data = string.char(ow.read(pin))
                    for i = 1, 8 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 > 32768) then
                        t = (bxor(t, 0xffff)) + 1
                        t = (-1) * t
                       end
             t = t * 5
                       lasttemp = t
             print("Last temp: " .. lasttemp)
                    end                   
                    tmr.wdclr()
              end
            end
          end
          addr = ow.search(pin)
          until(addr == nil)
    end
    
    --- Get temp and send data to thingspeak.com
    function sendData()
    getTemp()
    t1 = lasttemp / 10
    t2 = (lasttemp >= 0 and lasttemp % 10) or (10 - lasttemp % 10)
    print("Temp:"..t1 .. "."..string.format("%01d", t2).." C\n")
    -- conection to thingspeak.com
    print("Sending data to thingspeak.com")
    conn=net.createConnection(net.TCP, 0) 
    conn:on("receive", function(conn, payload) print(payload) end)
    -- api.thingspeak.com 184.106.153.149
    conn:connect(80,'184.106.153.149') 
    --- you have to adapt the value behind key=  to your own write API Key on www.thingspeak.com 
    conn:send("GET /update?key=MYWRITEKEY&field1="..t1.."."..string.format("%01d", t2).." HTTP/1.1\r\n") 
    conn:send("Host: api.thingspeak.com\r\n") 
    conn:send("Accept: */*\r\n") 
    conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")
    conn:send("\r\n")
    conn:on("sent",function(conn)
                          print("Closing connection")
                          conn:close()
                      end)
    conn:on("disconnection", function(conn)
                                    print("Got disconnection...")
      end)
    end
    
    -- send data every X milliseconds to thing speak
    tmr.alarm(0, 5000, 1, function() sendData() end )
    

    In parallel I opened five cmd-windows where each window does endless ping'ing
    ping IP.adress -t
    

    the ping-times vary from 3ms up 900ms.
    In changing order each cmd-window has timeouts when ping'ing.
    I guess if the ESP8622 is busy with reading the DS1820 or busy with connecting to the the web
    the pings must wait.
    But the ESP8266 kept on running continously for hours and each cmd-window comes back to get his pings replied.

    Next step would be to establish multiple connections TCP and/or UDP if possible
    or a continous datastream over serial and over WiFi at the same time.

    best regards

    Stefan
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-24 17:38
    Stefan,
    That's a pretty good stress test.
    I signed up for a thingspeak.com free account last night.

    Now to try a few tests and see what I can do. Still running the ESP8266 standalone.

    Once that works nicely, I think it will be time to add a Prop to the mix (with Lua) ;)
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-25 02:37
    Woot!!

    Got data going both ways. Now can twiddle a pot, and anywhere in the world can have it read out on a servo. Two propeller chips/boards, two ESP8266 chips and not much else really.

    This is the xively code to fetch all the feeds
    pub XivelyGet
      ' http://forums.adafruit.com/viewtopic.php?f=22&t=47126
        strings.copy(string("AT+CIPSTART=0,",34,"TCP",34,",",34,"api.xively.com",34,",80",13,10),@string1)  
        esp8266.str(@string1) 
        delayOK   ' will come back with OK then Linked
        gobblebytes(500)
        strings.copy(string("GET /v2/feeds/"),@string1) ' build the string to send
        strings.plus(string("970253233"),@string1) ' add the feed id
        strings.plus(string(".csv HTTP/1.0",13,10),@string1)' add the format of the data to request   
        strings.plus(string("Host: api.xively.com",13,10),@string1)
        strings.plus(string("X-ApiKey: shsCNFtxuGELLZx8ehqglXAgDo9lkyBam5Zj22p3g3urH2FM",13,10),@string1)
        strings.plus(string("Connection: close"),@string1)
        strings.plus(string(13,10,13,10),@string1) ' final crlfs
        commandstring1 ' send this request
        gobblebytes(5000)
    

    and this is the code to upload a feed
    pub XivelySend | n
        strings.copy(string("AT+CIPSTART=0,",34,"TCP",34,",",34,"api.xively.com",34,",80",13,10),@string1)  
        esp8266.str(@string1) 
        delayOK   ' will come back with OK then Linked
        gobblebytes(500)
        strings.copy(string("Sensor1,30"),@string3) ' the sensor value to change, and the value
        strings.copy(string("PUT /v2/feeds/970253233.csv HTTP/1.1",13,10),@string1) ' build the string to send
        strings.plus(string("Host: api.xively.com",13,10),@string1)
        strings.plus(string("X-ApiKey: shsCNFtxuGELLZx8ehqglXAgDo9lkyBam5Zj22p3g3urH2FM",13,10),@string1)
        strings.plus(string("User-Agent: Arduino1",13,10),@string1) ' name of the project
        strings.plus(string("Content-Length: "),@string1)
        n := strings.len(@string3) ' find the length of string3 with the sensor name and value
        strings.copy(strings.integertodecimal(n,3),@string2) ' get the length as a string
        strings.plus(@string2,@string1) ' add the length
        strings.plus(string(13,10),@string1) ' crlf
        strings.plus(string("Content-Type: text/csv",13,10),@string1) ' comma sep data
        strings.plus(string("Connection: close",13,10,13,10),@string1) ' close the connection after send
        strings.plus(@string3,@string1) ' the actual data to send
        strings.plus(string(13,10,13,10),@string1) ' final crlfs
        commandstring1 ' send this command, waits 4s for a reply, closes automatically
    

    Joining xively is free - you can upload data from vb.net or spin or other microprocessors, and also download it. xively can also display graphs which are handy. The above code and password are my site which I have made public, and if you do a read on this you might see whether I have pumps on or off and how many kilowatts of solar I am producing.

    Of course, there are other places to act as a repository of data, but xively is very convenient. I think they would prefer you don't spam the site, so I guess from this I am reading maybe don't send data more than once a minute, so this means if you move a pot, it might take a minute for a servo to move. There might be faster solutions, eg virtual serial links you can set up.

    But for uploading data and storing it for many months, then reading it back, this is very convenient. Sensor nodes don't need local SD card storage. Display nodes can be in a different location, so you could have a node out in the yard measuring the soil moisture, and another node in the shed that disables the sprinkler system if it has rained, and yet another node in the house displaying if the garden is a bit parched.

    The propeller is just perfect for this.

    Ok, next step, get the touchscreen display working with the ESP8266 modules so can walk around the yard turning sprinklers on and off, controlling a drone etc etc
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-25 05:06
    Interesting Drac. I think the same can be done with the thingspeak site.

    I haven't looked at how it's done. I have a few websites with their own ip addresses
    Where I believe I can run cgi or other code. They are hosted in the USA and I don't
    use anywhere my data limits.
    Would be nice to build this into my site.

    Meanwhile, I am using lua on the esp8266, and I then want to use lua commands from the prop
    As lua seem quite simple to send and receive data from the remote website.

    Your thoughts???
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-25 15:47
    Hi Cluso,

    Thingspeak looks simpler than xively eg http://electronut.in/an-iot-project-with-esp8266/

    I don't know anything about lua. Can you explain this for dummies - is it run on the esp module, how does it interact with the existing esp commands etc

    Somewhere along the line we have to think about passwords - joining a wifi access point needs a password, and you can either program this into the propeller, or you have to have some sort of keyboard/touchscreen/menu to type in a password. Maybe a 20x4LCD and a few pushbuttons. I'm getting around this because none of my wifi access points have passwords but I suspect most people will have passwords on their APs.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-25 17:37
    Drac,

    nodeMCU is programmed into your ESP8266. This then runs a lua interpreter. Lua is a simpler language to run or interface to, than the AT+ command set.
    And you can setup a few lua script files stored on the ESP8266 that you can run on command. The script file "init.lua" runs on power up if it exists.
    Here is the link that I used to program nodeMCU into your ESP8266
    http://benlo.com/esp8266/
    http://benlo.com/esp8266/esp8266QuickStart.html

    The only issue I had was with the ESP8266Flasher.exe...
    When you flash the latest nodeMCU, on the Config page...
    * deselect the INTERNAL//xxx 0x00000
    on the following lines, add in (using the locate cog-wheel icon)
    * select /nodeMCU-latest.bin 0x0000
    * select /esp-init-data-default.bin 0x7c000
    * select /blank.bin 0x7e000
    Then Flash the code.

    The latest lua code is dated 18/3/2015 from here (cannot find the github link :( )
    You need the files
    nodemcu-latest.bin 18/3/2015 9:43pm
    esp_init_data_default.bin 18/3/2015 10:39pm
    blank.bin 18/3/2015 10:39pm
    They all came in the file nodemcu-firmware-master.zip
    I can email this if you like.
    Postedit
    https://github.com/nodemcu/nodemcu-firmware/releases/tag/0.9.5_20150318
    and download the source code zip file
    The nodemcu is in the /latest directory and the default and blank are in the /bin directory.


    Here is another lua writeup with examles
    https://github.com/nodemcu/nodemcu-firmware

    Now you can use LuaLoader.exe to interact with your ESP8266 directly with your pc. This will show you what commands you need the propeller to reproduce.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-25 17:58
    Here is a Lua script to list wifi stations found and connect to the best open wifi station
    -- choose the strongest open AP available and connect to it
    -- Autoconnect to strongest AP
    -- tested with NodeMcu 0.9.2 build 20141212 
    
    ConnStatus = nil
    function ConnStatus(n)
    
    status = wifi.sta.status()
    uart.write(0,' '..status)
    local x = n+1
    if (x < 50) and ( status < 5 ) then
       tmr.alarm(0,100,0,function() ConnStatus(x) end)
    else
       if status == 5 then
       print('\nConnected as '..wifi.sta.getip())
       else
       print("\nConnection failed")
       end
    end
    end
       
    best_ssid = nil
    function best_ssid(ap_db)
    
    local min = 100
    for k,v in pairs(ap_db) do
        if tonumber(v) < min then 
           min = tonumber(v)
           ssid = k
           end
        end
    end
    
    best = nil
    function best(aplist)
    
    ssid = nil
    print("\nAvailable Open Access Points:\n")
    for k,v in pairs(aplist) do print(k..' '..v) end
    
    ap_db = nil
    ap_db = {}
    if nil ~= next(aplist) then
         
       for k,v in pairs(aplist) do 
          if '0' == string.sub(v,1,1) then 
             ap_db[k] = string.match(v, '-(%d+),') 
             end 
           end
         
       if nil ~= next(ap_db) then
          best_ssid(ap_db)
          end
       end
    if nil ~= ssid then
       print("\nBest SSID: ".. ssid)
       wifi.sta.config(ssid,"")
       print("\nConnecting to "..ssid)
       ConnStatus(0)
    else
       print("\nNo available open APs")
       end
    end
        
    
    wifi.setmode(wifi.STATION)
    wifi.sta.getap(function(t) best(t)  end)
    

    And here is a script (once you are connected) that will get the time from the google homepage
    -- retrieve the current time from Google
    -- tested on NodeMCU 0.9.5 build 20150108
    
    conn=net.createConnection(net.TCP, 0) 
    
    conn:on("connection",function(conn, payload)
                conn:send("HEAD / HTTP/1.1\r\n".. 
                          "Host: google.com\r\n"..
                          "Accept: */*\r\n"..
                          "User-Agent: Mozilla/4.0 (compatible; esp8266 Lua;)"..
                          "\r\n\r\n") 
                end)
                
    conn:on("receive", function(conn, payload)
        print('\nRetrieved in '..((tmr.now()-t)/1000)..' milliseconds.')
        print('Google says it is '..string.sub(payload,string.find(payload,"Date: ")
               +6,string.find(payload,"Date: ")+35))
        conn:close()
        end) 
    t = tmr.now()    
    conn:connect(80,'google.com') 
    
    And here is one to send some info to a website, after you are logged on
    This will be similar to sending info to xively or thingspeak, etc.
    -- tested on NodeMCU 0.9.5 build 20141222...20150108
    -- sends connection time and heap size to http://benlo.com/esp8266/test.php
    
    print('httpget.lua started')
    Tstart  = tmr.now()
    
    conn = nil
    conn=net.createConnection(net.TCP, 0) 
    
    -- show the retrieved web page
    
    conn:on("receive", function(conn, payload) 
                           success = true
                           print(payload) 
                           end) 
    
    -- when connected, request page (send parameters to a script)
    conn:on("connection", function(conn, payload) 
                           print('\nConnected') 
                           conn:send("GET /esp8266/test.php?"
                            .."T="..(tmr.now()-Tstart)
                            .."&heap="..node.heap()
                            .." HTTP/1.1\r\n" 
                            .."Host: benlo.com\r\n" 
                   		   .."Connection: close\r\n"
                            .."Accept: */*\r\n" 
                            .."User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n" 
                            .."\r\n")
                           end) 
    -- when disconnected, let it be known
    conn:on("disconnection", function(conn, payload) print('\nDisconnected') end)
                                                 
    conn:connect(80,'benlo.com') 
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-25 18:39
    Hi cluso,

    Looks interesting - eg strongest wifi using the propeller involves some string manipulation.

    Can I go back a step - I'm still a bit confused about what lua is running on. Have you reflashed the ESP module and lua replaces the code that was on the module? I'm still not up to speed with this - how you write a script, how you download it, what it is actually running on. I'll go back and reread this thread...
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-25 20:26
    Yes, I reflashed the ESP module. This code then runs totally on the esp module. By running a special terminal program under windows called LuaLoader, you can either click the buttons on the PC screen to do certain things like discovering the stations. Also you can enter you own lua commands to test them. You can also download lua programs (scripts) to the esp module (programs them into flash). Then you can run these on the esp module by calling them from the PC terminal window (or dofile button).

    Below is my testfile called Rays.lua
    The commented lines at the end are not working correctly - still sorting this out :(
    -- display APs
    -- Autoconnect to me
    
    wifi.setmode(wifi.STATION)
    
    wifi.sta.getap(function(t) if t then print("\nVisible Access Points:")
    for k,v in pairs(t) do l = string.format("%-10s",k) print(l.."  "..v) end else print("Try again") end end)
    
    --wifi.sta.config("Ray's iPad MR","password")
    --wifi.sta.connect()
    --wifi.sta.getip()
    --wifi.sta.disconnect()
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-25 22:22
    With the setup described here
    http://randomnerdtutorials.com/esp8266-web-server
    using this init.lua code flashed into the esp module using lualoader.exe
    rebooting connected to my internet gateway (a mobile hotspot) I received the IP details
    xxx.xx.10.5 255.255.255.240 xxx.xx.10.1

    I then loaded my web browser and typed in xxx.xx.10.5 (the IP of the ESP) and voila...
    A webpage with buttons to turn on/off GPIO0 & GPIO2 (remember GPIO0 is the flash enable to GND for Flashing the ESP but not for programing Lua scripts, so the link should be removed!!!)
    All works nicely :)
    wifi.setmode(wifi.STATION)
    wifi.sta.config("Ray's iPad MR","password")
    print(wifi.sta.getip())
    led1 = 3
    led2 = 4
    gpio.mode(led1, gpio.OUTPUT)
    gpio.mode(led2, gpio.OUTPUT)
    srv=net.createServer(net.TCP)
    srv:listen(80,function(conn)
        conn:on("receive", function(client,request)
            local buf = "";
            local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
            if(method == nil)then
                _, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
            end
            local _GET = {}
            if (vars ~= nil)then
                for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
                    _GET[k] = v
                end
            end
            buf = buf.."<h1> ESP8266 Web Server</h1>";
            buf = buf.."<p>GPIO0 <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
            buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>";
            local _on,_off = "",""
            if(_GET.pin == "ON1")then
                  gpio.write(led1, gpio.HIGH);
            elseif(_GET.pin == "OFF1")then
                  gpio.write(led1, gpio.LOW);
            elseif(_GET.pin == "ON2")then
                  gpio.write(led2, gpio.HIGH);
            elseif(_GET.pin == "OFF2")then
                  gpio.write(led2, gpio.LOW);
            end
            client:send(buf);
            client:close();
            collectgarbage();
        end)
    end)
    
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-25 23:03
    Ah, now that is looking very clever.

    Ok - let's jump ahead - there are two spare pins, could they be used as an I2C bus, and then you can get some digital I/O with an MCP23008 and analog inputs and outputs with a PCF8591.

    I think lua can talk I2C - eg http://www.esp8266.com/viewtopic.php?f=19&t=1049
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-26 00:42
    Yes, Lua has an I2C driver. I don't know if all the interfaces are inbuilt, or if you have to rebuild the ROM code and reflash it.

    The ESP-12 are the best modules as they have a single ADC input and a number of GPIOs. The predecessor was the ESP-03 and I have one.

    But you should be able to use GPIO0 & GPIO2 to interface to an I2C device. You only need to reflash the full code, not the lua scripts, so GPIO0 only needs to be grounded for reflashing.
    These are the two pins used for the LEDs.

    BTW I tried my iPhone 6+ with Safari but it couldn't connect - it seems to try and lookup the IP address rather than use it directly. I am also interested to make sure it can be accessed from outside my local internet. My PC is currently logged onto the same network hotspot. Later I will set my iPhone to a hotspot too, and connect my PC to that network to try.

    Here is a nice lua api list
    https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#wifisetmode
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-26 03:23
    @Drac:

    Lua is based on an alternative-firmware. This firmware is called nodeMCU. nodeMCU replaces the original AT-Firmware.
    You have to flash the nodeMCU-firmware into the ESP8266-modules flashrom as described above.

    With the nodeMCU-Firmware everything is done by Lua-scripts. The Windows-App LuaLoader.exe simplyfies things like

    - setup Accesspoint to which the ESP8266-module should connect automatically after powerup
    - query IP-adress given to the ESP8266 after connecting
    - set or query GPIOs
    - upload and start Lua-scripts into the ESP8266-flashrom

    The AT-Firmware means there is a set of AT-commands you can send to the ESP. Each AT-command does a small action and responds
    if the action was successfully executed or not. (with this unconsistent responds that make it hard to catch unsuccessful AT-commands)

    The Lua-Firmware means there are not only small commands but a complete scripting language. This enables to write Lua-scripts which trigger bigger tasks to be executed
    by a single command. With the basic set of Lua-words you can define functions to do whatever you want them to do.


    I guess interfaces like I2C, SPI, onewire etc. are coded in the nodeMCU-firmware. But I don't know.

    Good find this I2C-scanner. I soldered a test-PCB for a PCF8574 (8bit I2C-Port-expander). I tried this I2C-scan-code successfully.
    Though I was wondering why my PCF8574 was found on adress 32 with all adress-pins tyied to ground.
    Can somebody explain this to me? (guess without the scanning code I would have never get my runlight-code to work)

    So after that I wrote a small demoscript for a "running-light" light Knightrider KIT's Eye
    There is a code line inside a wait-loop
     tmr.wdclr() -- call this to pat the (watch)dog!
    
    which I found in some other Lua-code.
    I thought i would be better to insert this.

    heres the LUA-script
    -- example-code how to connect the ESP8266 to a PCF8574 I2C-device
    -- switching ON/OFF each port of the PCF8574 in a knight-rider kit-style
    
    id = 0  -- need this to identify (software) IC2 bus?
    SDA_Pin = 3
    SCL_Pin = 4
    
    I2C_Adress = 32
    
    function WriteToPCF8574(IO_Byte)
    -- the PCF8574 has opencollector-outputs so the anode of the LEDs must by tied to Vdd permanently
    -- switching LEDs ON means to set PCF8574-OutPut to LOW to make a significant current flow
    -- if you are tying LEDs kathodes-to ground and trying to switch on LEDs through setting Output high
    -- the inner circuitry of the PCF8574 limits the current to 0,1mA. 
    -- example LED of Port-Bit 1 should be switched on. So only Bit 1 is LOW all other bits Bit0, Bit2..Bit7 are HIGH
    -- %11111101 decimal 253.   Bit 1 is decimal 2.   255 - 2 = 253 = %11111101
    
      Byte = 255 - IO_Byte                 
      i2c.start(id)
      i2c.address(id, I2C_Adress ,i2c.TRANSMITTER)
      print ("Write "..IO_Byte.."  to PCF8574") 
      i2c.write(id,Byte)
      i2c.stop(id)
    end
    
    
    print("Check for ACK of PCF8574")
    i2c.setup(id,SDA_Pin,SCL_Pin,i2c.SLOW) -- initialize i2c with our id and current pins in slow mode :-)
    
    c = i2c.address(id, I2C_Adress ,i2c.TRANSMITTER)
    if c == true then
      print("PCF8574 found at adress "..I2C_Adress)
    else
      print("PCF8574 NOT found at adress "..I2C_Adress)
        
    end
    
    delay = 1000
    
    for j = 0,10 do
    
      for n = 0,7 do
        Byte = 2^n
        
        for  i = 1,delay do
          tmr.wdclr() -- call this to pat the (watch)dog!
        end
        WriteToPCF8574(Byte)
      end
    
      for n = 6,1,-1 do
        Byte = 2^n
        
        for  i = 1,delay do
          tmr.wdclr() -- call this to pat the (watch)dog!
        end
        WriteToPCF8574(Byte)
      end
    end 
    

    I made an quite extensive comment about how to switch on/off-LEDs with a PCF8574. My opinion about commenting is:
    if it takes me just 10 minutes to write a comment that will help newbies to understand why the code does it that way
    I do it. (It's a piece of learning something extra just by reading at the same playce instead of going on tour to gobble up
    this information criss-cross half the internet.=

    best regards

    Stefan
  • WurlitzerWurlitzer Posts: 237
    edited 2015-03-26 09:59
    I am experiencing an issue with many of the commands/modes where the documentation is very clear as to what the options are but completely devoid of what those options do or how they function.

    Example: wifi.setmode(mode)
    mode: value should be: wifi.STATION, wifi.SOFTAP or wifi.STATIONAP

    Ok, fine so far but what is the difference between those modes and when should they be used? I am new to Lau and never liked C (or any flavor of it) and maybe those mode constants are 2nd nature to programmers using those languages.

    I searched many different sites without finding out what the modes types mean. All I got was the same list of valid modes. Many of the descriptions are like this.

    Sort of like how MS would always use the term you were looking for in their help description of that term.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-26 10:07
    OK Guys, forgive me for being lazy and asking but...where do I get some of these latest and greatest modules?
  • Mike CookMike Cook Posts: 829
    edited 2015-03-26 10:29
    ebay

    put ESP8266 in the search box
  • Heater.Heater. Posts: 21,230
    edited 2015-03-26 10:34
    Thank you Mike,

    Problem is, being an old fuddy duddy who has never bought anything on ebay I go searching for such things and see a bunch of possible sellers. Despite their ratings they all look decidedly dodgy to me.

    OK, I guess given the cost of this thing I should not worry to much about it.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-26 10:37
    @Heater:

    in varying a common sentence: "ebay is your friend:" http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xesp8266+07.TRS0&_nkw=esp8266+07&ghostText=&_sacat=0

    the "07" module has all GPIO accessible and has a connector for external antenna
    though it's not 0,1 inch spacing it's 2mm spacing

    Olimex has a module too. Don't now if olimex is shipping to you
    https://www.olimex.com/Products/IoT/MOD-WIFI-ESP8266-DEV/

    adafruit has one
    http://www.adafruit.com/products/2282

    I clicked once again on the button "Set AP" in LuaLoader.exe
    the response is:
    > wifi.setmode(wifi.STATION)
    > wifi.sta.config("MyAPs Name","MyPassword")

    so mode STATION means connect as a client to an accesspoint
    SOFTAP means the ESP itself acts as an accesspoint (accesspoint realised in software)

    best regards

    Stefan
  • Mike CookMike Cook Posts: 829
    edited 2015-03-26 10:38
    I've purchased two different batches from this guy, without any problems

    http://www.ebay.com/itm/2-69-each-ESP8266-ESP-01-5x-Simple-Serial-WIFIArrive-1-10-BizDays-/281470224472?pt=LH_DefaultDomain_0&hash=item4188eec858

    i
    f your going to do the nodeMCU-firmware then I would get the -07 or-12, more I/O on those.

    Lots of info at esp8266.com, there's even a build environment for Linux so you can make changes to the default AT-Command load, if you desire.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-26 10:45
    Mike,

    Ouch, price plus shipping gets us to very nearly 40 Euros. Seems a bit excessive seeing as a USB/WIFI dongle is about 10 Euro in the stores around here. Almost as much as buying a Raspberry Pi off the shelf.

    I might have to give this a miss.
  • Mike CookMike Cook Posts: 829
    edited 2015-03-26 10:47
    PM me your address and I'll send you two of mine.
  • TorTor Posts: 2,010
    edited 2015-03-26 10:54
    - go for a seller with over 99% positive feedback. Only go below (to 98.x%) if there's no choice
    - if there is a choice between China and Hong Kong and the price difference isn't too big, go for Hong Kong
    - otherwise go for the lowest price (sort on price+shipping lowest)
    - if prices are in the same range, de-select the shop which sells clothing and trinkets as their main product (and not electronics)
    - avoid ordering several different items at the same time, unless you are familiar with the seller and know that they can manage (oh yes)
    - buy from different sellers at the same time if you want to be sure.. usually it will all eventually arrive, but the time can vary drastically. I needed some ZIF sockets and ordered from two sellers. One (well, a pair) arrived today, super-fast. The other probably in a couple of weeks or three from now (that's more common)
    - if it doesn't arrive in time (ebay limits), contact the seller *and* raise it with ebay, even if the seller offers a resend or refund - otherwise the time limit will pass. You can always refund the refund if the part eventually arrives (I've done that several times)

    Remarkably everything I ever ordered actually arrived.. although one item arrived only this January, after being ordered the previous April. And the seller had ceased all communication. That's the 98% positive category. Avoid those.

    -Tor
  • Mike CookMike Cook Posts: 829
    edited 2015-03-26 11:00
    @Heater
    That looks to be ready to use.

    All of mine are the -01 model. I'm using them as Wifi senors with an Arduino Mini-Pro.It transmits various environmental data to a UDP server every 5 minutes, sleep and repeat.

    Next Project will be a little more complicated so I will probably use a Propeller
  • Heater.Heater. Posts: 21,230
    edited 2015-03-26 11:17
    OK Mike, thanks for the offer but I think I'll take a chance on something like that unit I liked to.

    I'm curious to mess with the Lua thing. And there seem to be a bunch of vendors with that same unit.

    Unless someone here has a better idea.
  • TorTor Posts: 2,010
    edited 2015-03-26 13:41
    The ready-to-go is an auction and not buy it now, so the price may end up higher.. but another seller with nearly the same name, probably the same outfit, has it for $9.42 buy-it-now.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-26 13:50
    Thanks, sounds more like it. Still searching around....
Sign In or Register to comment.