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

Low cost wifi module ESP8266

145791018

Comments

  • Igor_RastIgor_Rast Posts: 357
    edited 2015-06-11 10:03
    xanadu wrote: »
    Igor_Rast, what firmware version are you using?

    Have you considered flashing NodeMCU? Lua works much better than the AT commands because with the AT firmware the command formatting changes.


    After running the AT-GMR command . it looks like im running
    AT+GMR

    0018000902-AI03

    OK

    I have read about flashing the firmware , but didnt get a chance to do it with mine, have the modules for some time already
    this is the first time I tryed to do anything with it , so flashing it with newer firmware may not be a bad idea after all .
    I do have to read in to get it done


    @Heater . Thanks for your help
    short anwser ,. the extra \r\n didnt make it work , but havent read into it yet , so im gonna do that before I ask more questions that may sound silly
    flashing a new firmware may also be a good idea , so I will try getting both done . if it still doesnt work ill post my not working results :p

    Igor

    Manny thanks
  • xanaduxanadu Posts: 3,347
    edited 2015-06-11 13:11
    Interesting firmware version, it would be hard for anyone not on the same version to test anything. I believe that is why a lot of people have issues and end up using Lua. If you want to stick with the AT command set I used v0.9.5.0 AT firmware which could be more recent and worked much better than what it shipped with.

    I just got the v12 boards today, nice to be able to access all of the pins and the little RF shield over everything is nice too!
  • xanaduxanadu Posts: 3,347
    edited 2015-06-13 13:55
    Setup for reading the ADC and controlling one GPIO:

    IMG_1012.JPG

    http://iotcopter.dynalias.com:8000

    Working on the header to allow all browsers to access it. Currently working on Chrome the best. I also added a viewport line so it is readable on mobile devices. The page refreshes which is annoying for the on/off but great for the ADC reading. Will fix that eventually.
    wifi.setmode(wifi.STATION)
    wifi.sta.config("xxx","xxx")
    print(wifi.sta.getip())
    led1 = 4
    gpio.mode(led1, 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
            vbatt = adc.read(0);
            vbatt = vbatt / 10;
            buf = buf.."<html>";
            buf = buf.."<head>";
            buf = buf.."<meta charset='UTF-8'>";
            buf = buf.."<META HTTP-EQUIV='refresh' CONTENT='2'>";
            buf = buf.."<meta name='viewport' content='width=device-width, initial-scale=.75'>";
            buf = buf.."<title>IoT Telemetry</title>";
            buf = buf.."</head>";                
            buf = buf.."<body>";
            buf = buf.."<h1>IoT Copter v1.1";
            buf = buf.."<p>-------</p>";
            buf = buf.."Voltage:  " ..vbatt;
            buf = buf.." %";
            buf = buf.."<p>Lights <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><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);
            end      
            buf = buf.."</body>";
            buf = buf.."</html>";
            client:send(buf);
            client:close();
            collectgarbage();
    end)
    end)
    
  • Cluso99Cluso99 Posts: 18,066
    edited 2015-06-13 15:37
    Works with IE11 and Windoze 8.1 :)
  • xanaduxanadu Posts: 3,347
    edited 2015-06-13 16:06
    Cluso99 wrote: »
    Works with IE11 and Windoze 8.1 :)

    Thanks. Safari on mobile is daunting. I'm about to put wireshark between the two. The only thing I get is "Safari cannot open the page because the network connection was lost." I've uploaded the same html file to apache and it loads fine on Safari mobile. Blarggggg.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-06-13 17:22
    Firefox on Linux gives me raw HTML
    <html><head><meta charset='UTF-8'><META HTTP-EQUIV='refresh' CONTENT='2'><meta name='viewport' content='width=device-width, initial-scale=.75'><title>IoT Telemetry</title></head><body><h1>IoT Copter v1.1<p>
    </p>Voltage: 37 %<p>Lights <a href="?pin=ON1"><button>ON</button></a> <a href="?pin=OFF1"><button>OFF</button></a></p></body></html>

    Chrome displays the voltage with each refresh and On/Off buttons - it works!!
  • dr hydradr hydra Posts: 212
    edited 2015-06-13 19:03
    The esp8266 looks very interest...I am not 100% how they work...I am a complete noob with wifi modules and not sure it will work for my project. I am looking for a way to wireless connection the propeller to a raspberry pi using uart. I am looking for devices that are pretty much plug and play one connected to propeller the other connected to the raspberry pi uart gpios sending serial info back and forth between the devices wireless...will the esp8266 modules fit that bill...and hopefully just work plug and play...
  • Cluso99Cluso99 Posts: 18,066
    edited 2015-06-13 21:58
    xanadu wrote: »
    Thanks. Safari on mobile is daunting. I'm about to put wireshark between the two. The only thing I get is "Safari cannot open the page because the network connection was lost." I've uploaded the same html file to apache and it loads fine on Safari mobile. Blarggggg.
    Just verified Safari doesn't work on my iPhone6+ either - similar message.
  • Cluso99Cluso99 Posts: 18,066
    edited 2015-06-13 22:00
    dr hydra wrote: »
    The esp8266 looks very interest...I am not 100% how they work...I am a complete noob with wifi modules and not sure it will work for my project. I am looking for a way to wireless connection the propeller to a raspberry pi using uart. I am looking for devices that are pretty much plug and play one connected to propeller the other connected to the raspberry pi uart gpios sending serial info back and forth between the devices wireless...will the esp8266 modules fit that bill...and hopefully just work plug and play...
    It should work but I haven't tried it and you can bet there are some tricks too.
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 01:13
    I have not played with these modules yet but I'm reading that the amount of Lua you can get in there is very limited.

    Just thought I'd mention that most browsers will cope with a minimal amount of HTML
    client:send("<body>Hello world!</body>");
    
    Would be sending a perfectly workable page.

    Of course if you need some header or meta tag you can add those as well.
    local buf = "<META HTTP-EQUIV='refresh' CONTENT='2'><body>";
    buf = buf.."<h1>Hello world!</h1></body>";
    client:send(buf);
    
    I have no idea if that kind of cheat saves a worth wile amount of space in Lua but there we go.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-06-14 02:00
    @ dr hydra,

    what is the distance that you want to send the data wireless?

    of course you can send "serial data" using ESP8266 but not just plug and play
    If your definition of "plug and play" is you have a serial cable (RS232) which connects your propeller to a Raspery Pi by copperwires
    and now instead of plugging in the cable you plug in a pair of wireless tranceivers . This can't be done with the ESP8266.

    this kind of plug and play can be done with modules like Xbees which have a mode which is called transparent serial transmission.

    I have made such a wireless serial-cable replacement with the pololu Wixel
    https://www.pololu.com/product/1336

    costs a bit more than a ESP8266 but works as a almost drop in replacement of a serial copperwire

    If you want to do it with the ESP8266 you have to write some additional routines:
    - connect ESP8266 modules to Wifi-Network
    - passing SSID and password.
    - Establish an UDP or a TCP/IP connection between propeller and RPi's ESP8266
    - send and receive data.

    So if you describe what you want to do in the end. (What's the final purpose of your project) and what distance and where (inside a house with many walls in between or free sight outside but still a short distance)
    the community can give a more detailed advice.

    @heater:
    limited memory with Lua. Do you (or anybody else here) know any kind of project where somebody hit the memory limit using the Lua NodeMCU firmware? Of course it is limited. But the real interesting thing is

    Can you do f.e. a web-connected refrigerator which logs open and close of the door and transmits the temperature of the room and the temperature inside the refrigerator. Will such a small project already cause an out of memory error or not?

    What projects are you thinking of where you fear a memory limit?

    best regards

    Stefan
  • MJBMJB Posts: 1,235
    edited 2015-06-14 03:01
    StefanL38 wrote: »
    Can you do f.e. a web-connected refrigerator which logs open and close of the door and transmits the temperature of the room and the temperature inside the refrigerator. Will such a small project already cause an out of memory error or not?

    What projects are you thinking of where you fear a memory limit?

    best regards

    Stefan
    from what I see the refrigerator control should be no problem space wise.

    And if you want to have more complex / larger web pages you wound NOT store them in LUA code, but as a file in FLASH memory
    and then transmit them - maybe substituting some placeholders with values.
    This keeps LUA code space / and heap consumption low(er).

    After start nodeMCU has about 24k of heap free -
    quite a lot in Propeller-terms

    AND you can run LUA scripts and unload them when done so the GC frees the heap again.
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 03:51
    Actually I have no idea how much functionality one can squeeze into these modules with Lua. I look forward to getting a few and finding time to try this out. It's just that I thought I had read here, or elsewhere, that people had hit the limit of memory space pretty quickly. Also the guys that built the Electric Imp card switched from Lua to Squirrel at the last minute of development because Lua was too big for them. If what you want to do can be fitted in there that's excellent.

    Now, I'm imagining that if I were to have a bunch of these modules around the house they would not be serving up web pages designed for humans anyway. Rather they would be delivering JSON objects containing sensor data and so on. That JSON would consumed by a central server created with node.js, perhaps running on a Raspberry Pi, that in turn serves up a "console" were I could monitor and control all of them from one place.

    In that case I would be looking to use the minimum of HTML and extraneous gunk. Thus minimizing processing time and network usage. Might help if using battery and/or solar supplies.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-06-14 04:03
    Power consumption is a limiting factor. The Wifi-part needs around 200mA
    0.2A * 3.3V = 0,66 W. Not much for a house but a lot for a battery.

    Otherwise if you imagine IoT where dozens of devices have Wifi
    quite some current in summary. That's why battery-operated devices like Z-wave, EnOcean, etc. do not use Wifi but something that needs much much less current to make a battery last 1 year or so.

    I haven't read the specs of the ESP8266 modules in detail.
    Is there a possability to keep the wifi-connection alive but reduce Tx-Power?
    otherwise reducing would only work through "PWM" switch on Wifi only a few seconds every 10 minutes to do a check if data should be exchanged.

    As long as I have the Wifi-device in my special shoes generating electricity with each step through piezo-chrystals I'll have enough energy ;-)
    But I don't want to do physical exercises on all my thermostatic radiator heads three times a day ;-))

    best regards

    Stefan
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 04:10
    Is it possible to shut WIFI down and put the thing into a sleep mode?

    I would do things the other way around, wake up, make a WIFI connection, make a POST request to my server that delivers the JSON data, go back to sleep.

    That is still a lot of power consumption, perhaps expecting battery operation is not realistic.
  • MJBMJB Posts: 1,235
    edited 2015-06-14 04:23
    Heater. wrote: »
    Is it possible to shut WIFI down and put the thing into a sleep mode?

    I would do things the other way around, wake up, make a WIFI connection, make a POST request to my server that delivers the JSON data, go back to sleep.

    That is still a lot of power consumption, perhaps expecting battery operation is not realistic.
    there is a deep sleep mode - 78uA they say, 10uA in other place ..., where only the wakeup timer is running and then generates a RESET/Restart of the module
    - need to do my own measurements later

    there is also a WIFO-off mode nice for local data logging where you do not need the Wifi -
    but I did not see this new API included into LUA yet.
  • MJBMJB Posts: 1,235
    edited 2015-06-14 04:27
    I read rumors about the ESP8268 the next gen ESP8266 with now ~200k RAM

    this will immediately solve most of the LUA heap space problems for the usual application.

    I am having a lot of fun with my ESP8266-12 module and NodeMCU/LUA
    Connected 1-wire DS18S20 temp sensors, and PING sensor.

    was up with data stored on thingspeak.com in few hours (mostly download and install of all the tools and docs)
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 05:37
    Sounds better and better. I can imagine apps that spend most of their day asleep, occasionally measuring something and even less occasionally firing up the WIFI engine to dump the log to a waiting server.
  • xanaduxanadu Posts: 3,347
    edited 2015-06-14 06:10
    The browser support issue is lack of HTTP response from the ESP. I had assumed these were somehow built into the server. The difference between the HTTP header and the HTML header is the line termination. I will add that today.

    I think it is something like this, the x-www-form is supposed to be required for POST forms but I'll experiment.
            buf = buf.."HTTP/1.1 200 OK\r\n";
            buf = buf.."Content-Type: application/x-www-form-urlencoded\r\n";
            buf = buf.."Connection: close\r\n\r\n";
    
  • dr hydradr hydra Posts: 212
    edited 2015-06-14 06:19
    Thanks for the replies...

    Stefan you are correct...I am looking for a simple wireless direct replacement for serial cable uart...I have looked at the Xbee but they are pricey....I have also looked at using an hc05 and Bluetooth dongle...but the esp8266 looks very interesting

    My project is to hookup a nes controller to the propeller and then send wireless uart commands to the raspberry pi for game emulation...so the distance would be less then 30ft...I have been looking to buy the olimex esp8266 modules...however the documentation states the modules starts in flash mode and soldering is necessary to enter uart mode...once in uart mode it looks like I would need to program the two modules to talk to each other? i am not sure I understand the different protocols and steps needed to make this happen
  • xanaduxanadu Posts: 3,347
    edited 2015-06-14 06:22
    https://nurdspace.nl/ESP8266#Power

    POWER: (you do not need no stinking high power)

    People that said switching power supplies solved their problem most likely needed a reboot. Takes 80ma to run and program these, you won't hit over 0.1A without sending a lot of data. Using it as a wireless serial port over the TCP stack would be an example of where you'd hit 200ma.

    Using it on 802.11g, OFDM 54Mbps, POUT=+16dBm 145 mA (max)
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-06-14 07:11
    @dr hydra,

    I did some research on a wireless UART-module and found this
    http://www.seeedstudio.com/depot/Bluetooth-V20-Serial-Transceiver-Module-33V-p-1731.html

    seems to have UART transparent mode. To make sure you should read the datasheet or ask the support of seeedstudio

    as written above: the ESP8266 is NOT a drop in replacement for a UART-copperwire.
    You would have to write additional routines. If I remember right the ESP8266 has a peer to peer mode.
    which means connect two ESP8266-modules directly without a WiFi-router.

    best regards

    Stefan
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 09:25
    This is totally off topic here but as I mentioned using minimal HTML generation I thought I'd also mention why I was thinking about that anyway...

    You see I basically hate HTML and have been thinking about how to get rid of it for ages. Today was that day, ...nearly.

    Basically I have a file, noHTML.html, that only contains two script tags. No html, head, body or other gunk. It looks like:
    //<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script><script>
    ...
    ... A bunch of JavaScript that uses react.js...
    ...
    //</script>
    
    When viewed in a browser it creates two nice looking buttons. When run under node.js it ouputs the string:
    <div class="center-block" style="color:green;width:100px;">
        <button class="btn btn-sm btn-block btn-danger">Motor start</button>
        <button class="btn btn-sm btn-block btn-primary">Motor stop</button>
    </div>
    
    See attachment.

    I was thinking this might be useless but I'm quite proud of it :) and it just occurred to me that this kind technique be very helpful for use with these WIFI modules.

    What one could do is put the bulk of that JavaScript into a library served up from a nearby Raspberry Pi or whatever server. That library could build an arbitrarily large and complex web page. Perhaps with graphs, histograms all kind of fun stuff. The WIFI module only need respond to requests with a very small piece of JS in a script tag containing one call, to render the page, and the data required to populate the page elements.

    Edit: If anyone takes an interest in that file it should be noted that it can be made a lot smaller, simpler and easier to read by using the JSX preprocessor that comes with react.js. I did not want to use it here as I wanted this to run under node.js as well.
  • xanaduxanadu Posts: 3,347
    edited 2015-06-14 12:48
    Heater I am very interested in node.js. I have to stick to HTML for now because I'm also new to Lua.

    Here is a working Lua example of a "thing" that reads the ADC, has an LED on/off, AND talks to Thingspeak once a minute.

    There are three places with the X's. wifi.sta.config("xxxxxx","xxxxxx") and conn:send("GET /update?key=xxxxxxxxxxxxxx&field1="..vbatt.." HTTP/1.1\r\n"). Wifi SSID, wifi password, and Thingspeak API key all need to be filled in.

    The Thingspeak info also shows up on the webpage, and will refresh on its own.

    http://iotcopter.dynalias.com:8000
    wifi.setmode(wifi.STATION)
    wifi.sta.config("xxxxxx","xxxxxx")
    print(wifi.sta.getip())
    led1 = 4
    gpio.mode(led1, gpio.OUTPUT)
    tmr.alarm(0, 60000, 1, function() sendthings() end )
    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
            vbatt = adc.read(0);
            vbatt = vbatt / 10;
    
            buf = buf.."<!DOCTYPE html>";
            buf = buf.."<html>";
            buf = buf.."<head>";
            buf = buf.."<meta charset='UTF-8'>";
            buf = buf.."<meta name='viewport' content='width=device-width, initial-scale=.75'>";
            buf = buf.."<title>IoT Telemetry</title>";
            buf = buf.."</head>";                
            buf = buf.."<body>";
            buf = buf.."<h1>IoT Copter v1.1";
            buf = buf.."<p>-------</p>";
            buf = buf.."Voltage:  " ..vbatt;
            buf = buf.." %";
            buf = buf.."<p>Lights <a href=\"?pin=ON1\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF1\"><button>OFF</button></a></p>";
            buf = buf.."<iframe width='450' height='260' style='border: 1px solid #cccccc;' src='http://api.thingspeak.com/channels/42279/charts/1?width=450&height=260&results=60&dynamic=true&yaxis=%25&title=LiPo%20Voltage' ></iframe>";      
            local _on,_off = "",""
            if(_GET.pin == "ON1")then
                  gpio.write(led1, gpio.HIGH);
            elseif(_GET.pin == "OFF1")then
                  gpio.write(led1, gpio.LOW);
            end      
            buf = buf.."</body>";
            buf = buf.."</html>";
            client:send(buf);
            client:close();
            collectgarbage();
    end)
    end)
    
    function sendthings()
    vbatt = adc.read(0);
    vbatt = vbatt / 10;
    print (vbatt);
    conn=net.createConnection(net.TCP, 0) 
    conn:on("receive", function(conn, payload) print(payload) end)
    conn:connect(80,'184.106.153.149') 
    conn:send("GET /update?key=xxxxxxxxxxxxxx&field1="..vbatt.." 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
    

    Time to connect it to the Propeller!
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 14:33
    That is cool.

    I've been slowly building a web console with buttons and indicators and charts for use with a Prop connected to the net via a Pi and WIFI dongle.
    It's here:
    http://45f83947e567edecea6388c0fe11355520ff7dd8b1effcf25e0fa45d47ac92.devices.resin.io/
    All busted at moment as I gutted it for a rewrite recently.
    You can say "Hello" via the chat tab at the bottom :)

    All in all you have a much smaller, simpler and working solution!
  • xanaduxanadu Posts: 3,347
    edited 2015-06-14 14:56
    Very nice, the second row down is interesting, is that a plot? It's the gltail of IoT interfaces!
  • MJBMJB Posts: 1,235
    edited 2015-06-14 15:12
    MJB wrote: »
    there is a deep sleep mode - 78uA they say, 10uA in other place ..., where only the wakeup timer is running and then generates a RESET/Restart of the module
    - need to do my own measurements later

    there is also a WIFO-off mode nice for local data logging where you do not need the Wifi -
    but I did not see this new API included into LUA yet.
    http://41j.com/blog/2015/01/esp8266-sleep-modes/
  • Heater.Heater. Posts: 21,230
    edited 2015-06-14 15:14
    I got your message, did my reply come back to you?

    You mean the row with all the flashing red dots?

    They are all instances of the same react component that is just drawing a "bubble chart" in svg using the d3.js library. Just randomly generated x, y, z data for now.

    The idea is that each such little window can hold a different widget created as a react component.

    The big window at the top was a nice rolling graph of analog values until I decided to get into this react thing and broke it. I have yet to see the best way to use svg with react components.

    In the tab window at the bottom I have a VT100 serial terminal that should one day be connected to a Prop connected to the Pi.
  • Cluso99Cluso99 Posts: 18,066
    edited 2015-06-14 18:13
    This discussion is getting interesting...

    FYI (first up) There are now larger flash memory versions of the ESP-01 now available for a few cents more. I haven't seen the ESP-12 with larger memory yet, but I am sure that will come.

    I agree that the power is not as bad as it seems because IoT should not be transmitting all the time.

    Here is what I am attempting to do...

    1. A number of ESP modules that monitor various sensors (voltages, currents, temperatures, switches/alarms, etc). They report back at periodic intervals, plus alarm exceptions.
    2. The data is stored in an MySQL database on a server.
    3. The server is able to send out email and SMS messages in the event of an alarm(s).
    4. Any browser equipped device (PC, Tablet, Smart Phone, etc) can view the database.

    Now, if I want the ESP based IoT to be more complex, I will add a propeller with a uSD card. The prop can interface to a number of complex sensors, etc, and it can run Lua scripts (either Lua files on the ESP, or by sending Lua commands from the prop to the ESP).

    Currently we can do a basic server database by using ThingSpeak. But I have my own paid hosted website and I would like to have (and control) my database here.

    Currently we can solve the dynamic IP addressing by using No-IP. Again, I would like to control this via my website.

    I want my website to be able to "serve up" web pages of my database with some gauges and graphs. Google's gauge is a good start here.

    Currently, I am happy that the ESP will solve my IoT sensor problems, without/with a prop attached.

    So, I am off looking at what I need to do for my hosted website to house my database and serve up the data. For that I have been reading up on MySQL, PHP, Python, etc. I actually have no idea how I achieve this, but I am reading lots!
  • MJBMJB Posts: 1,235
    edited 2015-06-15 02:03
    Cluso99 wrote: »
    This discussion is getting interesting...

    FYI (first up) There are now larger flash memory versions of the ESP-01 now available for a few cents more. I haven't seen the ESP-12 with larger memory yet, but I am sure that will come.
    ESP-12 with 4MByte Flash is there

    and there is the NEW ESP-12e
    https://www.google.com/search?q=esp-12e&ie=utf-8&oe=utf-8
    which exposes 6 additional pins including the 4 SPI/SD pins ...
    so local SD logging might be available soon.
    Did not see a NodeMCU API for it yet
Sign In or Register to comment.