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

Low cost wifi module ESP8266

1246718

Comments

  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-17 18:18
    back to the ESP8266:

    three of the four ESP8266-01 that I bought from china made some magic "red" smoke by burning down the red power-led.
    Lights up really bright for one second glowing down to almost off then smoking for several minutes - gone

    smells bad :-(
    Fortunately they are still working as expected. OK got to take a look if the blue Tx-Led lights up when power is switched on.
    Maybe I will solder a 3mm LED onto the PCB

    I decided to use the nodeMCU-Firmware. So I flashed this firmware to all modules I have.

    I found this little demo for a webserver based on the nodeMCU-firmware
    http://randomnerdtutorials.com/esp8266-web-server/

    simply using the two GPIOs on a ESP8266-01 to switch on/off two LEDs.
    Somehow there is a bug: If the LEDs are connected to the GPIOs when power is switched on
    the ESP8266 seems to change into "load-firmware" mode.

    So when using GPIO0 for LEDs I would have to add some hardware tristating the LED until power-up has finished.
    Guess I'm gonna buy modules with all IO-Pins accessable from a high quality manufacturer outside china

    Olimex has a module with 2MB flash on board
    https://www.olimex.com/Products/IoT/MOD-WIFI-ESP8266-DEV/open-source-hardware
    But I'm not sure if this module will work with the nodeMCU-Firmware.

    This one https://www.it-wns.de/themes/kategorie/detail.php?artikelid=1129&source=2
    has all GPIOs accessable and a socket for external antenna.

    best regards

    Stefan
  • TubularTubular Posts: 4,705
    edited 2015-03-17 21:29
    I had a chance to play with the NodeMCU version and ESPlorer the other week, and was very impressed

    If you're in Oz, Tronixlabs now have these in stock
    http://tronixlabs.com/iot/esp8266-nodemcu-development-board/
  • koehlerkoehler Posts: 598
    edited 2015-03-18 00:29
    Dr_Acula wrote: »
    Finally... I have something vaguely reliable.)

    Hmm, if ambient is above max temp for most of the equipment then that is a problem.

    Just a note, removing a device from its case, even when running a fan might be worse in some instances. The few times I've had to do that, I've cut a hole in the case above the cpu/gpu/mosfet, mounted a fan to the outside of the case, and had it force air over the component and then out over the rest of the board before exiting. Maybe a few extra holes on each side to help.

    As for gluing a heatsink, I am assuming this is with a decent TPM material?

    I was going to say that by far the issue is most likely the high ambient temps. Not sure if these are standard consumer AP's your talking about, or ESP8266 mesh routers. Maybe relocate the routers, or frankenstein up some copper roof flashing soldered to your heatsink to give you a larger external heat-pipe sort exposed to the extractor fans?

    Or, maybe test reversing your extractor fans if nothing else?

    And, I've not jumped onto the ESP8266 since there seem to be so many people selling them, with lots of QA issues, and apparently the initial F/W was rather clunky.

    Has this changed?
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-18 03:22
    Thanks for the tips re cooling. Lots of fans and heatsinks.

    Re ESP modules, I think they are reliable enough to do useful things now. Tonight I soldered up a propeller board. Next step is to write the software to collect bytes from the ESP8266 and dump to the terminal, which should be just a few lines of Spin. Then port over the Arduino code for logging into Google, which I know is reliable.

    For my reference later on, attached is the propeller schematic I am using. This is mainly just to remind me that I have (randomly) chosen propeller pins 8,9 and 10 for the ESP8266. Note the 4700uF capacitor next to the ESP8266 to absorb power surges. Most of the components on this board are not needed for this experiment - can omit the SD card, TV, VGA, keyboard, voltage translation, analog I/O. Really, it is just an ESP8266 connected to three propeller pins, and a large capacitor near the wifi module.
    824 x 806 - 275K
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-18 04:29
    Hi Dr_Acula,

    I have running the ESP8266 with the nodeMCU-firmware with a small Lua-script
    reading a DS1820 1wire-sensor every 5 seconds.
    Sending the data to the serial terminal and via WiFi to thingspeak.com.
    Always open and close the connection to thingspeak.com
    It's running for two days now without any troubles.

    But I guess this is a rather easy task.
    What did you do with the ESP8266-module for intensive testing the reliability?
    I would like to do the same testing under the nodeMCU-firmware in a Lua-script if this is possible.

    best regards

    Stefan
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-18 04:55
    What did you do with the ESP8266-module for intensive testing the reliability?

    I had it read www.google.com and if the correct text came back, it lights a led. Read every 10mins or every hour or whatever, if the led is on, it is working.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-18 05:13
    Hi Dr_Acula,

    thank you very much for answering.
    I'm completely new to webservers / clients. I almost have no idea
    how to establish a connection to a website
    and what to send to the website to get an answer and how to evaluate received data.

    Would you mind sharing your code that is doing the testing?

    Maybe some people here were interpreting my question as "hurry up finishing my project"
    No no no not at all! Really really not! It is meant exactly as the question that you can read by combining the letters to words.

    So if you don't enjoy sharing your code or answering in any other way . Don't answer or answer with a "no". Simple thing to do.
    Also links to introductional tutorials to this stuff are appreciated.

    best regards

    Stefan

    P.S.:
    Sometimes I myself really enjoyed internetresearch for a complete "foreign" project even for hours.
    It was about specs of the RS485-standard. And as I enjoyed it I did it for some other guy who had posted a question here in the forum.
    Just for the joy of doing it. I guess in real rare cases other people here in the forum will enjoy helping me to. If so good. If not - good too.

    So feel free to answer or not.
  • Heater.Heater. Posts: 21,230
    edited 2015-03-18 06:58
    Stefan,

    You worry too much about asking questions here. Normally the problem is not that one does not get an answer but one gets too many!:)
    I'm completely new to webservers / clients. I almost have no idea
    how to establish a connection to a website
    and what to send to the website to get an answer and how to evaluate received data.
    Here is a fun experiment.
    1) Connect to some web site using telnet, say this forum like so:
    $ telnet forums.parallax.com 80
    
    Notice the url gets you to the IP address of the web site, and the 80 is the port number to use for HTTP.
    If you are on windows you can use the putty program to do this telnet thing.

    2) Type the following into the telnet session:
    GET / HTTP/1.0
    
    
    That first "/" is the thing you are requesting from the server in this case the root document. You need two new lines at the end there.

    You should get a response back like so:
    HTTP/1.1 200 OK
    Date: Wed, 18 Mar 2015 13:46:20 GMT
    Server: Apache/2.2.22 (Ubuntu)
    X-Powered-By: PHP/5.3.10-1ubuntu3.15
    Set-Cookie: bb_lastvisit=1426686383; expires=Thu, 17-Mar-2016 13:46:23 GMT; path=/; domain=.parallax.com
    Set-Cookie: bb_lastactivity=0; expires=Thu, 17-Mar-2016 13:46:23 GMT; path=/; domain=.parallax.com
    Cache-Control: private
    Pragma: private
    Content-Length: 22872
    Vary: Accept-Encoding
    Connection: close
    Content-Type: text/html; charset=ISO-8859-1
    
    That first line says "OK" and the error code "200" (Which means OK)
    Then there is a lot of other interesting info.
    Then you should get a big pile of HTML text which is the content of the page you requested.

    You can GET other content, like this particular forum page by changing the request path like so:
    GET  http://forums.parallax.com/showthread.php/157430-Low-cost-wifi-module-ESP8266/page5 HTTP/1.0
    
    

    Now, your WIFI module presumably does all that connecting and request sending for you via AT commands. I have no idea about that I'm sure Dr_A does.

    You can read about all this web HTTP stuff here: http://www.jmarshall.com/easy/http

    Of course a request need not return a huge pile of HTML. It could return just a simple text text string in whatever format you like.

    Then there are the PUT and POST requests which all for sending data back to the server.
  • ErNaErNa Posts: 1,752
    edited 2015-03-18 08:58
    I like this website to quickly run tests and to get an overview: http://www.w3schools.com/js/default.asp
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-18 11:06
    Hi Heater,

    first of all thank you very much for your effort explaining it.

    I seem to have strange obstacles in my way to learn it.
    I searched for putty on my hardisc. Did'nt find it.
    OK download it....
    startet PUTTY.EXE.
    With the PUTTY.EXE I downloaded I didn't got a console
    I got a windows window so seems to be the wrong PUTTY.EXE

    So I googled for "telnet-client"
    I found manuals how to activate telnet client/server on windows 7 did that.

    If I type telnet inside the window you get by typing "Windows-Key-R"
    I get a console-window named "telnet.exe"

    I found that inside telnet.exe I have to type O forums.parallax.com 80
    took half a minute until message "type any letter to continue" typed connection lost.

    Now I'm lost. Maybe I'm spoiled as with the ESP8266 getting started website everything run through
    smoothly as possible. Here I'm stumped. Where can I download a telnet commadline client for windows that works as heater has posted above? Or what else is wrong with my Win7 Laptop?

    I tried TeraTerm but all I get is connection timed out

    Is my Internet security suite BitDefender blocking the connection?

    best regards

    Stefan
  • koehlerkoehler Posts: 598
    edited 2015-03-18 12:54
    Putty from Windows CLI near bottom:

    http://etherealmind.com/putty-command-line/

    Problem you are seeing is that Putty is not in your current path. Easily changed also.
  • mindrobotsmindrobots Posts: 6,506
    edited 2015-03-18 13:06
    Hi Stephan,

    They sure make playtime hard when you are using windows.

    OK, it sounds like you have PuTTY installed. When starting PuTTY, you don't get a console directly, you need to tell PuTTY where to open a session to.

    When you start it, you get a window named PuTTY Configuration that has various categories listed down the left side and some blanks to fill in like "Host Name" and some radio buttons to select and a few buttons to push (Load, Save, Delete, Open, Cancel)

    To see the raw HTML traffic and do the things Heater suggested, you need to:

    1) enter the URL where it says "Host Name" - in heater's examplt, this was forums.parallax.com
    2) enter a port number of 80 where it says "Port"
    3) Check the radio button under "Connection Type" that says "Raw"
    4) Check the radio button under "Close window on exit:" that says "Never"
    5) Click on the "Open" button
    6) Putty should open a new window at this point that just looks like a blank terminal screen. Here you can enter:
    "GET / HTML/1.0" without the quotes
    7) press enter twice
    8) after a delay, you will see a bunch of text come back to you screen
    9) PuTTY will put up a Windows dialog saying "Connection Closed by Remote Host" - you can click OK on this
    10) Finally, in the terminal window, you will have the response from the Parallax server to your GET command and you can look at all the goodies sent in an HTML response.

    Wow, it really makes you appreciate *nix systems!! :D

    I hope this works for you. If not, let us know where it breaks.
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-18 15:11
    I am going to be trying my ESP modules over the next few days.
    I don't really know anything about the internet protocols/etc either but I will learn along the way. At least I know about older protocols so that is something giving me an insight.

    I am going to follow this quick start guide initially
    http://benlo.com/esp8266/esp8266QuickStart.html
    and see where I get to. I am using W7 and/or W8.1.

    Wish me luck ;)
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-18 19:03
    Code below - able to get the signon message.

    However, I have a very strange fault that I can't debug - these modules work with arduino but not with a propeller! I am gradually narrowing down the problem but it is not simple.

    First step - all modules are in sockets and I have about ten of them so can easily swap them in and out - works with arduino, not with propeller.

    Next step - the exact problem, which is that I can send a character, I can get it echoed back from the ESP module, and the ESP module flashes its LED, but the module does not do anything, ie send an acknowledge. The simplest command is AT then <Enter> and I have tried that and others.

    Tested all the voltages, they seem correct. Power is 3V3, reset is high (after cycling with the software) and Tx and Rx are also both 3V3 when resting.

    I have also tried with just a Max3232 and no propeller and talking via a terminal program - the problem the same as the propeller, so it isn't the propeller as such, but something else. Maybe the voltages?

    So what exactly are the differences between the two setups. I see three things:

    1) Reset and Rx on the ESP module ar 4.9V when connected to the arduino, and 3V3 when connected to the propeller (the ESP module is 5V tolerant)
    2) The propeller power supply is a switching regulator, and on the arduino it is a linear regulator.
    3) The arduino supply measures 3.4V, and the propeller supply measures 3.3V.

    Apart from that, the setup seems as identical as I can get it. Both ESP chips have 4700uF caps on their supplies.

    So I need to do more experiements. These modules are very fickle - I guess it is a matter of discovering what all the problems are and documenting them all.

    ' ESP8266 experiments
    ' default baud rate is 9600 but can increase if needed to 115200 for large websites
    ' ESP8266 input is from P8, reset is P9 and the output goes to P10
    con
      _clkmode = xtal1 + pll16x                '
      _xinfreq = 5_000_000
               '
    obj
      esp8266       : "FullDuplexSerial_rr004"    ' 256 byte buffer version
      terminal      : "FullDuplexSerial_rr004"
      delay         : "Timing"     
    VAR
      
    pub main | c,d
    
      esp8266.start(10,8,0,9600)                            ' rxpin,txpin,mode,baudrate
      terminal.start(31,30,0,9600)                          ' propeller terminal F12, 115200 baud
      terminal.str(string("ESP8266 test program",13,10))
      dira[9]~~                                             ' reset pin is an output
      outa[9]~                                              ' set low
      delay.pause1ms(200)                                   ' small delay
      outa[9]~~                                             ' set high
    
      ' send commands, eg AT (then Enter) and should return OK
      
      repeat
        c := esp8266.rxcheck                                ' -1 if no data, 0-255 if there is a byte
        if c <> -1                                          ' c contains the byte
           terminal.tx(c)                                   ' send to terminal
        d := terminal.rxcheck
        if d <> -1
          esp8266.tx(d)
    
  • ersmithersmith Posts: 6,068
    edited 2015-03-18 19:21
    When you send <Enter> to the remote device, is it sending carriage return (ASCII 13), line feed (ASCII 10), or both? I'm guessing the Propeller terminal acts differently in this regard from the Arduino one.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-18 22:12
    Hi Rick,

    thank you so much for your detailed manual.
    I could reproduce each step and got each reaction as you described it.
    OK the get command initiates transfering all the html-code similar to what you see if you do
    "view page sourcecode" in firefox.

    Aha. So this makes me think new: what would be a WiFi-activity-stresstest for the ESP8266-module
    that makes the ESP8266- modul moan: "lot's of work to do not sure if I get it all done"

    What do you think? What would be a stresstest for the ESP8266?
    sending short messages every 10 milliseconds. Sending huge messages
    sending pings from 3 PCs at the same time?


    read Dr_Aculas latest post.

    gonna try you testcode to see what results I get
    I was measuring the current of the ESP with a DMM. The digits jumped up and down continuosly between 150-250mA.
    Suspecting the the regulator:
    how about supplying the ESP from the arduino with only GND and IO-Pins connected to the propeller-chip
    and vice versa to analyse if it is the regulator?

    best regards

    Stefan
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-19 02:12
    Dracula,
    First up I would suspect the switching regulator. That 4700uF is possibly causing problems for the switcher. I would try 100uF to 470uF. Even these values are high for a switcher.
    Otherwise, it could be the cr lf issue.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-19 05:50
    I'm sure you are both right - and I just remembered I ran out of the correct inductors for the switchers, and have substituted some smaller ones that have the same inductance but DC resistance of 3R, and I think they ought to be much less than that. I'll try a beefier power supply.

    And thanks for those suggestions - it gives me several new things to test and I was completely stuck for ideas.

    This forum is great!
  • FredBlaisFredBlais Posts: 375
    edited 2015-03-19 21:17
    Cluso99 wrote: »
    I am going to be trying my ESP modules over the next few days.
    I don't really know anything about the internet protocols/etc either but I will learn along the way. At least I know about older protocols so that is something giving me an insight.

    I am going to follow this quick start guide initially
    http://benlo.com/esp8266/esp8266QuickStart.html
    and see where I get to. I am using W7 and/or W8.1.

    Wish me luck ;)

    When I saw your post, I decided to remove the dust on the ESP8266 that has been laying on my table for the 3 last months and start playing with it too :)

    I spent 2 hours with the module and the experience has been good so far. I'm able to get my module online and communicate with it by TCP
    My setup is a USB-Serial cable with RX,TX plugged into the ESP (I did not bother that the usb serial module puts 5V on the RX of the ESP)
    Wiring was simple, ESP needs 3.3V, GND and CH_PD connected to 3.3V

    I opened a serial terminal and I figured out that the baud rate was 9600 because when I wrote "AT" I received the string "OK"

    After that, I entered the command "AT+CWLAP" returned a list of the SSID the ESP saw
    CWLAP: (4,"freddynet",-40,"00:18:e7:d1:84:0e",3)
    +CWLAP: (4,"freddynet2",-61,"6c:19:8f:cf:12:e8",3)
    +CWLAP: (0,"HP-Print-1502",-59,"38:b1:db:64:00:15",3)
    ...meaning that the wifi seems to be working

    After that, I connect to my network with this command : AT+CWJAP=”freddynet”,”MyPassword”
    When done, entering this command "AT+CIFSR" returns this :
    +CIFSR:APIP,"192.168.4.1"
    +CIFSR:APMAC,"1a:fe:34:9f:72
    +CIFSR:STAIP,"192.168.0.177"
    +CIFSR:STAMAC,"18:fe:34:9f:7"
    where 192.168.0.177 is the address that my router gave to the ESP. For some reason, the ESP act as an access point too... but I did not investigate that.

    Next, I entered "AT+CIPMUX=1" (for the next command to succeed)
    then "AT+CIPSERVER=1,5000" to create a listening TCP server on port 5000

    On my Linux box I connected to the server with "telnet 192.168.0.177 5000" which returned that I was connected
    Entering "Hello!" on telnet gives me this on the ESP side :
    +IPD,0,8:Hello!
    0 is the connection ID and 8 is probably the length of "Hello!\r\n"

    If I want to send data from the ESP back to my telnet session, I issue "AT+CIPSEND=0,x" (x being the number of character I want to send) and then I enter the x characters and they appear in the session.
    when I close the connection on the telnet side, I receive the "CLOSED" message on the ESP side.

    From there, I suppose it would not be too hard to replicate that using the Propeller to communicate with the ESP. A simple TCP socket client code with any programming language would let the Prop communicate over the internet. It would also be possible to make a really small HTTP server :)
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-20 01:50
    More experiments. I have a working Arduino system and a non working Propeller system and I am trying to narrow down what is the difference between the two. DC voltages seem correct. Data signals seem the same. So I have run some alligator leads over the bench and started adding things like filtering capacitors, but the errors get more bizarre. I now have random data appearing on inputs but being sent to outputs, and oscillations such that the blue led on the board is flashing very fast, and things that change when you move your hand near the circuit.
    This last fault very much suggests RF oscillation, and even though this module won't be transmitting RF at bootup, it still has a CPU running at RF speeds. I note that the module seems to have very little in the way of onboard filtering, so I am thinking of a carrier board with some filtering capacitors (large, medium and small, to filter different frequencies, probably 4700uF, 22uF and 0.1uF in parallel), and also I/O buffering with maybe a 74HC08 and maybe even optocouplers if I can't get it working reliably. I might think about adding some inductors on the gnd and 3V lines as well to isolate the supply lines and prevent 2.4Ghz feeding back into the Propeller/Arduino. Hopefully adding some RF design techniques will improve reliability.


    Back to the soldering iron!

    Addit: see post #113 - completely different fault...
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-20 12:51
    Drac,
    The filter isn't the solution. At best it is only masking a problem.

    How do you have your ESP8266 board setup on the prop board (photo?). I presume the aerial is away from the pcb and no tracks or ground planes near it.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-20 19:32
    When you send <Enter> to the remote device, is it sending carriage return (ASCII 13), line feed (ASCII 10), or both? I'm guessing the Propeller terminal acts differently in this regard from the Arduino one.

    ersmith wins a prize!!!!

    Ok, this has taken a whole morning of debugging. I built a little board with LC filters and large onboard capacitors and diagnostic leds. I couldn't have found this fault without this board but in the end the fault was software, not hardware. What this board did enable me to do is to quickly change between the Propeller and Arduino setup and try to determine why the Propeller one wasn't working. So I could change power supplies between switching and linear, and I could change the propeller pins, and because I had 5V to 3V buffers, I could eliminate the difference between the Arduino 5V system and the Propeller 3V system.

    Finally, I ended up with just a Terminal program and a Max3232 and it still wouldn't accept the AT command. But it would accept it if I fed the module from the Arduino and listened on the Terminal program.

    Then I remembered ersmith's comment.

    The Arduino uses a simple print command called serial.println. Implicit in this is a carriage return and a line feed, which is the old typewriter standard where carriage return moves the whole carriage to the left side, and line feed moves the paper up one line. If you hit Enter on a computer keyboard, or indeed, in any Terminal program, you just get a carriage return.

    So after all this, here is a bit of code that allows you to type commands in manually from the F12 propeller terminal. It captures an Ascii 13 and sends a 10 as well.
    ' ESP8266 experiments
    ' default baud rate is 9600 but can increase if needed to 115200 for large websites
    ' ESP8266 input is from P8, reset is P9 and the output goes to P10
    con
      _clkmode = xtal1 + pll16x                '
      _xinfreq = 5_000_000
               '
    obj
      esp8266       : "FullDuplexSerial"    
      terminal      : "FullDuplexSerial"
      delay         : "Timing"     
    VAR
      
    pub main | c,d
    
      esp8266.start(10,8,%0000,9600)                            ' rxpin,txpin,mode,baudrate
      terminal.start(31,30,%0000,9600)                          ' propeller terminal F12, 115200 baud
      terminal.str(string("ESP8266 test program",13,10))
      dira[9]~~                                             ' reset pin is an output
      outa[9]~                                              ' set low
      delay.pause1ms(200)                                   ' small delay
      outa[9]~~                                             ' set high
    
      ' send commands, eg AT (then Enter) and should return OK
      
      repeat
        c := esp8266.rxcheck                                ' -1 if no data, 0-255 if there is a byte
        if c <> -1                                          ' c contains the byte
           terminal.tx(c)                                   ' send to terminal
        d := terminal.rxcheck
        if d <> -1
          esp8266.tx(d)
          if d == 13
            esp8266.tx(10)                                  ' module needs cr and lf
    
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-20 20:56
    Drac,
    I had presumed you had tested this - bad presumption.
    Yes, often a catch between programs and drivers. And it's also a difference between Windows and Linux too.
    Anyway, its now running :)

    Meanwhile I have been doing a lot of reading, thinking about what path to take initially to get running.

    Ultimately, I want to get some working standalone (no prop) within a mesh. Not sure how to approach this yet.
  • Dr_AculaDr_Acula Posts: 5,484
    edited 2015-03-20 21:49
    Thanks cluso, yes, lots of things working now. Already have found an advantage compared to the Arduino the Propeller seems faster so can gobble up bytes without missing them. Might be something to do with the bigger serial buffers - 256 bytes, and I suspect also when multitasking ie running dual serial ports, this is where the propeller really shines. Debugging seems a lot easier as a result.

    I can already see an advantage there - when I was listing the nearby wifi access points on the arduino it would miss the odd character, so you couldn't build up a list. I got around that by manually coding to join a certain access point, but that is not a great solution if you change the router name, or move the board somewhere else.

    But in Spin, it lists the names perfectly, so you could then create a list, and could select one from a menu. Or it could look at the -db value for each one (number is after the router name), and try to join them starting with the strongest one.

    Screen dump of what I have working in Spin so far:
    ESP8266 test program
    [Vendor:www.ai-thinker.com Version:0.9.2.4]
    
    ready
    AT
    
    OK
    AT+CWMODE=3
    no change
    AT+CWLAP
    +CWLAP:(0,"Hogwarts Great Hall Wifi",-92,"6c:19:8f:c1:11:ff",1)
    +CWLAP:(0,"Oslo_Cabin",-48,"00:e0:4b:b5:f5:26",9)
    +CWLAP:(0,"TP-LINK_ROOF",-86,"c0:4a:00:db:1f:ea",9)
    +CWLAP:(0,"TP-LINK_PUMP",-89,"c0:4a:00:db:32:7a",9)
    
    OK
    

    This is the working spin code I have so far, and underneath is the C code I am translating it from. Just a matter of going through each line and converting to spin, then testing as I go.
    ' ESP8266 experiments
    ' default baud rate is 9600 but can increase if needed to 115200 for large websites
    ' ESP8266 input is from P8, reset is P9 and the output goes to P10
    con
      _clkmode = xtal1 + pll16x                '
      _xinfreq = 5_000_000
               '
    obj
      esp8266       : "FullDuplexSerial_rr004"    
      terminal      : "FullDuplexSerial_rr004"
      delay         : "Timing"     
    VAR
      
    pub main 
    
      esp8266.start(10,8,%0000,9600)                            ' rxpin,txpin,mode,baudrate
      terminal.start(31,30,%0000,9600)                          ' propeller terminal F12, 115200 baud
      terminal.str(string("ESP8266 test program",13,10))
    
       Reset                                                ' reset the module
       commandAT
       commandCWMODE
       commandCWLAP
    
       RunTerminal ' fall through to manual terminal
       repeat ' do nothing
    
    pub Reset | i,c
      dira[9]~~                                             ' reset pin is an output
      dira[0]~~                                             ' pin 0 has a diagnostic led
      outa[9]~                                              ' set low
      LedHigh                                               ' and flash led
      delay.pause1ms(200)                                   ' small delay
      outa[9]~~                                             ' set high
      LedLow
      repeat i from 0 to 1000
        delay.pause1ms(1)
        c:= esp8266.rxcheck
        if c<> -1
          terminal.tx(c)                                    'echo the signon message
          
      
    
    pub RunTerminal | c                     ' use F12, type AT commands to test module
      
      repeat
        c := esp8266.rxcheck                                ' -1 if no data, 0-255 if there is a byte
        if c <> -1                                          ' c contains the byte
           terminal.tx(c)                                   ' send to terminal
        c := terminal.rxcheck
        if c <> -1
          esp8266.tx(c)
          if c == 13
            esp8266.tx(10)                                  ' module needs cr and lf
    
    
    pub LedHigh
      outa[0]~~
    
    pub LedLow
      outa[0]~
    
    pub delayOK | i,delayabort,c,d,e ' times out after 8 seconds or if no OK. Sometimes takes 4 to 5 serial.find loops ie 4-5 seconds to respond
      i := 0
      d := -1
      e := -1
      delayabort := false
      repeat
        c:= esp8266.rxcheck
        if c<>-1
          terminal.tx(c) ' echo to terminal
          if (c== "O") and (d == -1)
            d := c
          if (c == "K") and (e == -1)
            e := c  
        delay.pause1ms(10)
        i := i+1
        if (d == "O") and (e == "K")
          delayabort := true
      until (i>400) or (delayabort == true)
      return delayabort
    
    pub gobbleBytes(milliseconds) | i,c
      repeat i from 0 to milliseconds
        c := esp8266.rxcheck
        if c <>-1
          terminal.tx(c)
        delay.pause1ms(1)  
    
       
    pub dumpESPbuffer | c    ' flush buffer and dump to terminal
      repeat
         c:= esp8266.rxcheck
         if c <>-1
           terminal.tx(c)
      until  c == -1
    
    pub commandAT
      esp8266.rxflush ' flush the buffer  
      esp8266.str(string("AT",13,10))
      if (delayOK == true)
        'terminal.str(string("AT working",13,10))
      else
        terminal.str(string("No reply",13,10))
    
    pub commandCWMODE
       terminal.str(string(13,10,"Change CWMODE",13,10))
       esp8266.rxflush ' flush the buffer
       esp8266.str(string("AT+CWMODE=3",13,10))
       delay.pause1ms(200)
       dumpESPbuffer       ' returns "no change" if ok, rather than OK
    
    pub commandCWLAP' list access points 
      esp8266.rxflush ' flush the input buffer
      esp8266.str(string("AT+CWLAP",13,10))
      gobbleBytes(5000)
       
        
    

    and the Arduino code
    /*
     ESP8266 module - run from arduino 3V3 supply but needs a 4700uF capacitor on the 3V line
     CH_PD pulled high
     newer ESP8266 modules boot at 9600 but can be reprogrammed back to 115200
     reset pin to arduino pin 12 so can do hardware resets
     echo data to arduino terminal  
     The ESP8266 is 3V and arduino is 5V, the ESP8266 chip can handle ? up to 6V on the pins
     in theory, need a 5V to 3V level converter
     in practice, a 10k and 20k resistor divider didn't work, and connecting the 5V directly did work.
     Testing the current through a 100R resistor, getting only microamps, so conclusion is that it is ok to directly connect to arduino.
    
    softserial leaves out some bytes. Altsoftserial is a better routine and feeds all the data through properly. Altsoftserial fixes the pins
    at pin 8 for Ard Rx (Tx on ESP), pin 9 for Tx (Rx on ESP)and also pin 10 is part of the pwm routine, and while the author says that you can still use pin 10,
    I have found that it causes problems so best to leave pin 10 not connected to anything
    
    also there are problems with strings and the stack and working string space overwriting 
    so look at progmem example - store all string text in flash, copy to just one string buffer, and all printstrings use F
    also even defines use ram rather than flash so move all text into flash. Just have one or two common string buffers
    
     */
    
    #include <AltSoftSerial.h>  //http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html
    //#include <avr/pgmspace.h> // saves ram, can store strings in flash as the little UNO only has 2k of ram and every quote uses this
    
    #define SSID "Oslo_Cabin" // insert your SSID
    #define PASS "" // insert your password (blank if no password)
    #define destHost "www.google.com"
    #define destPage "/"
    #define destPort "80"
    #define espRstPin 12
    #define diagLedPin 13
    #define serverLoopDelay 30 // server stays alive for this number of seconds, if a connection, then listens, if no connection then try google 
    //PROGMEM prog_uchar signMessage[] = {"Hello World"};
    
    
    // xively values
    #define APIKEY         "shsCNFtxuGELLZx8ehqglXAgDo9lkyBam5Zj22p3g3urH2FM" // replace your pachube api key here
    #define FEEDID         "970253233" // replace your feed ID
    #define USERAGENT      "Arduino1" // user agent is the project name
    
    AltSoftSerial espSerial; // pins are fixed 8 Rx, 9 Tx, and can't use pin 10 for anything 
    
    char outBuff[256]; // store in one place rather than building strings and then copying them around in memory (or could use pointers)
    int outBuffLen = 0; // can't use 0 as an end of string marker as might need to send out this as a valid binary character
    
    String commandString = ""; // use .reserve on strings to save fixed memory. Use F when printing strings to store that string in flash
    
    void setup()  
    {
      // Open serial communications and wait for port to open:
      Serial.begin(9600); // for debugging
      while (!Serial) { 
        ; // wait for serial port to connect.
      }
      commandString.reserve(40); // use one general command string, avoids strange bugs with fragmented memory building tiny strings
      Serial.println(F("Starting Arduino"));
      espSerial.begin(9600);
      pinMode(diagLedPin, OUTPUT); // diagnostic led
      pinMode(espRstPin, OUTPUT); // ESP8266 reset pin
      digitalWrite(diagLedPin,LOW); //led off
      printFreeRam();
      //testStringMemory();
      rebootTestInternet();
    }
    
    void loop() 
    {
      //serverLoop(serverLoopDelay); // if getting connections keep the server going, if no connections for n seconds, check google is still live
      quickTestInternet(); // is google still contactable?
      //sendXively("sensor1",47);
      delay(10000);
      //quickTestInternet();
      //delay(4000);
    }
    
    void testStringMemory()
    {
      //int k=0;
      //char c;
      
      //c =  pgm_read_byte_near(signMessage + k); 
      //Serial.println(c);
      //strcpy_P(outBuff, (char*)pgm_read_word(&(signMessage))); // Necessary casts and dereferencing, just copy.  - crashed the program
    
    }
    
    boolean rebootTestInternet()
    {
       boolean reply = false;
       resetESP8266(); // gets out of any hangs, eg if two browsers try to read at the same time
       flashLed();
       commandAT(); // test alive, can skip this
       commandCWMODE(); // remembers each time but safest to redo
       //commandCWLAP(); // list access points, can skip this as can take up to 10s and if already know the ap address no need
       flashLed();
       connectWiFi();
       displayIPaddress(); // useful for debugging and working out what address this has been assigned, could skip this 
       flashLed();
       commandCIPMUX();
       flashLed();
       reply = commandGOOGLE();
       return reply;
    }
    
    void quickTestInternet() // for second and subsequent tests, no need to disconnect the router etc
    {
      boolean googleAlive = false;
      // Serial.println("Test internet alive");
      flashLed();
      googleAlive = commandGOOGLE();
      if (googleAlive == false) { // failed to reconnect so do a complete reboot and keep trying till reconnects
        do
        { 
          googleAlive = rebootTestInternet();
        } while (googleAlive == false); // keep repeating if can't reconnect
      }  
    }  
    
    void resetESP8266()
    {
      int i;
      Serial.println(F("Hardware reset ESP8266"));
      digitalWrite(12,LOW);
      delay(200);
      digitalWrite(12,HIGH);
      for(i=0;i<1000;i++) // echo the startup message
      {
          if (espSerial.available())
             Serial.write(espSerial.read());
          delay(1);
      }   
    }
    
    void commandAT()
    {
      espSerial.println(F("AT"));
      if(delayOK())
        Serial.println(F("AT OK"));
    }  
    
    void commandCWLAP() // list access points - this does work but can't read all the bytes due to buffer overrun from the module (same problem with websites)
    {
      espSerial.println(F("AT+CWLAP"));
      gobbleBytes(10000);
    }  
    
    void commandCWMODE()
    {
        espSerial.println(F("AT+CWMODE=3"));
        delay(200); // replies with "no change" not OK so need custom code here
        if(espSerial.find("no change")) {
          Serial.println(F("CWMODE OK"));
        }else{
          Serial.println(F("Error CWMODE")); // the very first time the module runs this, will return an error, but remembers this forever in eeprom
       }  
    }  
    
    //void requestIPaddress() // this is a new function ?Dec 2014 and might not be available on some modules. Can set the IP address
    //{
    //  espSerial.println("AT+CIPSTA=\"192.168.1.70\""); 
    //  waitReply(); // see all the text that comes back
    //}
    
    boolean delayOK() // times out after 8 seconds or if no OK. Sometimes takes 4 to 5 serial.find loops ie 4-5 seconds to respond
    {
      
      int i = 0;
      boolean abort = false;
      serialFlush(); // remove any leftover things
      do
      {
        if(espSerial.find("OK")) {
           abort = true; // will abort the loop
         }   
         i+=1;
      }  
      while ((abort == false) && (i<8));
    }  
    
    void serialFlush(){
      while(Serial.available() > 0) {
        char t = Serial.read();
      }
    }   
    
    boolean connectWiFi()
    {
      commandString ="AT+CWJAP=\""; // global big string variable
      commandString += SSID;
      commandString += "\",\"";
      commandString += PASS;
      commandString += "\"";
      Serial.println(commandString);
      espSerial.println(commandString);
      if(delayOK()){
        Serial.println(F("OK, Connected to WiFi"));
        return true;
      }else{
        Serial.println(F("Cannot connect to the WiFi"));
        return false;
      }
    }
    
    void displayIPaddress() // a useful way to check actually connected
    {
      espSerial.println(F("AT+CIFSR"));
      waitReply();
    }
    
    void waitReply() // wait for a character then prints out, the esp8266 is faster than arduino so once all the bytes have stopped that is it
    { 
      int counter = 0;
      do {
        counter +=1;
        delay(1);
      } while ((counter<3000) && (!espSerial.available())); // wait until one character comes in or times out
      while (espSerial.available()) {
        Serial.write(espSerial.read()); // print out the text, might be just a reply, or even an entire web page
      }  
    }
    
    void gobbleBytes(int timeout) // similar to waitReply but times out after a certain time
    
    {
      int startTime = millis();
      while ((millis() - startTime) < timeout)
      {
        if (espSerial.available()) { Serial.write(espSerial.read());}
      }    
    }  
    
    
    void commandCIPMUX()
    {
       espSerial.println(F("AT+CIPMUX=1"));
       if(delayOK())
         Serial.println(F("CIPMUX OK"));
    }
    
    boolean commandGOOGLE() // connect to google to test internet connectivity
    {
      boolean reply = false;
      int count = 0;
      Serial.println(F("Test google home page"));
      commandString = "AT+CIPSTART=0,\"TCP\",\"";
      commandString += destHost;
      commandString += "\",80";
      espSerial.println(commandString);
      Serial.println(commandString);
      if(delayOK())
         Serial.println(F("CIPSTART OK")); 
      espSerial.find("Linked");
      outBuffClear(); // clear the output buffer prior to adding new data to send
      outBuffAppend("GET ");
      outBuffAppend(destPage);
      outBuffAppend(" HTTP/1.1\r\nHost: ");
      outBuffAppend(destHost);
      outBuffAppend(":");
      outBuffAppend(destPort);
      outBuffAppend("\r\n\r\n");
      commandSendBuff("0"); // send this data
      //gobbleBytes(4000); // comment this out if looking for the "Found" text below
      // or light a led if got a correct website
      while ((reply == false) && (count <4))
      {
        if(espSerial.find("Found"))
        {
          digitalWrite(diagLedPin,HIGH); // led on, found a website 
          Serial.println(F("Reply from GOOGLE"));
          reply = true; 
        }  
        count +=1;
      }
      delay(1000);
      espSerial.flush();
      commandCIPCLOSEzero();
      return reply; // true or false
    }  
    
    void commandCIPCLOSEzero() // close port zero
    {
        espSerial.println(F("AT+CIPCLOSE=0")); // close the connection from this end
        Serial.println(F("Close connection"));
        waitReply();
    }  
    
    void commandSendBuff(String ch_id) // sends outbuff array
    {
      int i;
      commandString = "AT+CIPSEND=";
      commandString += ch_id;
      commandString += ",";
      commandString += String(outBuffLen);
      espSerial.println(commandString);
      Serial.println(commandString); // for debugging
      espSerial.find(">"); // wait for the command prompt to come back
      for (i=0;i<outBuffLen;i++) {
        espSerial.write(outBuff[i]); // output a byte
        //Serial.write(outBuff[i]); // debugging, might slow things down?
      }
    }
    
    
    void flashLed()
    {
      digitalWrite(diagLedPin,HIGH);
      delay(50);
      digitalWrite(diagLedPin,LOW);
    }
    
    void serverLoop(int timeout) // if getting regular connections then no need to check google
    {
      boolean hits = false;
      do
      {
        hits = runServer(timeout); // if get a hit then keep looping as no need to check google all the time
      } while (hits == true);
    }
    
    boolean runServer(int timeout) // http://mcuoneclipse.com/2014/11/30/tutorial-web-server-with-the-esp8266-wifi-module/
    // timeout is in seconds
    {
      int channelNumber;
      int counter = 0;
      boolean connection = false;
      commandAT(); // see if module is awake, sometimes it is busy from a previous command
      Serial.println(F("Starting server"));
      delay(1000);
      espSerial.println(F("AT+CIPSERVER=1,80")); // set up a server, 1 means open connection (0 is close), 80 is the port
      waitReply(); // can't look for OK, as sometimes replies as no change, and sometimes as busy 
      Serial.println(F("Connect now from a browser"));
      //need this next line to time out after a while so can recheck if still on the internet
      while ((espSerial.find("+IPD,") == false) && (counter < timeout)) // this is the login routine, and the next character will be the port number
      { 
        counter +=1; // one second
        Serial.print(timeout - counter); // countdown timer
      }  
      if (counter < timeout) { // must have got a connection, so process it, otherwise fall through and close off
        Serial.print(F("\n\rGot a connection on channel "));  
        channelNumber = espSerial.read() - 48; // 48 is ascii 0
        Serial.println(channelNumber); 
        waitReply();
        Serial.println(F("\n\rServing home page now"));
        serveHomePage(channelNumber); // or can just send some text, if replying to another node, or even just send "Hello"
        delay(2000); //delay
        waitReply();
        Serial.println(F("\n\rClose connection"));
        espSerial.println(F("AT+CIPCLOSE=0")); // must close connection before browser will display anything - returns Unlink so can't look for ok
        delay(100);
        waitReply();
        //espSerial.println("AT+CIPSERVER=0"); // turn off server mode - need to wait a bit after cipclose, otherwise returns busy, please wait
        //delay(100); // not sure if cipserver=0 is needed, will need to do more testing, does this disable google next cylcle, or just bad luck with my link?
        Serial.println(F("Finished closing"));
        connection = true;
      }else{
        Serial.println(F("\r\nNo connections received"));
        espSerial.println(F("AT+CIPSERVER=0")); // close down the server as nothing happened
        waitReply();
      }  
      return connection;
    }  
    
    void serveHomePage(int ch_id) { // http://christinefarion.com/2014/12/esp8266-serial-wifi-module/
    {
      String header = "";
      String content = "";
      header = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n"; 
      // header += "Connection: close\r\n";  // or close with cipclose from this end
      content="";
      // output the value of each analog input pin
      for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
        int sensorReading = analogRead(analogChannel);
        content += "analog input ";
        content += analogChannel;
        content += " is ";
        content += sensorReading;
        content += "<br />\n";       
      }
      header += "Content-Length:";
      header += (int)(content.length());
      header += "\r\n\r\n";
      
      // print to debug, then to wifi
      
      Serial.print("AT+CIPSEND=");
      Serial.print(ch_id);
      Serial.print(",");
      Serial.println(header.length()+content.length());
      Serial.print(header);
      Serial.print(content);
      
      espSerial.print("AT+CIPSEND=");
      espSerial.print(ch_id);
      espSerial.print(",");
      espSerial.println(header.length()+content.length());
      espSerial.print(header);
      espSerial.print(content);
    
      }
    }
    
    //char server[] = "api.xively.com";   // name address for xively API
    
    /*
    // this method makes a HTTP connection to the server:
    void sendXively(String sensorName, int data)
    {
      String xivelyData;
      Serial.println("Please wait");
      delay(4000);
      Serial.println("Connecting to xively");
      String cmd = "AT+CIPSTART=0,\"TCP\",\"";
      cmd += "api.xively.com";
      cmd += "\",80";
      espSerial.println(cmd);
      waitReply();
      delay(3000);
      waitReply();
      //Serial.println(cmd);
      //if(delayOK()) {
      //   Serial.println("CIPSTART OK"); 
      //}else{
     //    Serial.println("CIPSTART fail");
      //}   
      xivelyData = sensorName;
      xivelyData += ",";
      xivelyData += String(data);
      // build the put string  - can't send as one long string so send in pieces
      // or maybe put in an array first
      commandSend("PUT /v2/feeds/");
      commandSend(FEEDID);
      commandSend(".csv HTTP/1.1\r\nHost: api.xively.com\r\nX-ApiKey: ");
      commandSend(APIKEY);
      commandSend("\r\nUser-Agent: ");
      commandSend(USERAGENT);
      commandSend("\r\nContent-Length: ");
      commandSend(String(xivelyData.length())); // length of the data string
      commandSend("\r\nContent-Type: text/csv\r\nConnection: close\r\n\r\n"); 
      commandSend(xivelyData); // the actual data to send
      commandSend("\r\n\r\n"); // ? 1 or 2 crlfs
      
    
      //delay(5000);
      waitReply();
      delay(4000);
      waitReply();
      commandCIPCLOSEzero();
      waitReply();   
    }
    */
    void outBuffClear()
    {
      outBuffLen = 0; // resent the counter. Can't reset the array to zero as zero is a valid binary number
    }
    
    void outBuffAppend(String s)
    { 
      int i;
      int st;
      int fin;
      int ln;
      char c;
      st = outBuffLen; // start at the beginning
      ln = s.length();
      fin = outBuffLen + ln;
      if (ln == 0) {
        Serial.println(F("Error - zero string length - buffer not being filled"));
      }  
      if (fin < 256) { // add string if there is space
        for(i=0;i<ln;i++) {
          c = s.charAt(i); // get the character, make sure it is a character
          outBuff[st] = c; // store it in the array
          st += 1; // increment the st value
        }
        outBuffLen += ln;
      }else{
        Serial.println(F("Buffer overrun"));
      } 
    }
    
    
    void outBuffInsert(String s) // inserts data at the beginning, shuffles existing data up. Safer than using strings as the buffer is predefined
    {
      
    }  
    
    void outBuffPrint() // for debugging, print out all the values in hex
    {
      int i;
      char c;
      for(i=0;i<outBuffLen;i++) {
        c=outBuff[i];
        Serial.print(c);
        printHex(outBuff[i]);
      }
    }
    
    void printHex(char x) {
       if (x < 16) {Serial.print(F("0"));}
       Serial.print(x, HEX);
       Serial.print(" ");
    }
    
    void printFreeRam()
    {
      Serial.print(F("Free ram = ")); 
      Serial.println(freeRam());
    }  
    
    int freeRam () {
       extern int __heap_start, *__brkval; 
       int v; 
       return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
    }
    
  • koehlerkoehler Posts: 598
    edited 2015-03-20 22:05
    I was on the ESP forum, and guy (Chan) has a mesh going, with some initial work on a mesh protocol.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-21 00:25
    @Cluso:

    are you gonna go the nodeMCU-firmware-path (with Lua) or the AT-firmware-path?

    I decided to use nodeMCU and Lua

    best regards

    Stefan
  • MJBMJB Posts: 1,235
    edited 2015-03-21 09:00
    What I was reading here the last many weeks about all the problems with the AT commands made me wait until you guys have sortet it out ;-).

    But now reading about LUA gets me excited - ordered some modules now.

    I like LUA and actually it brought me to the Propeller.
    When looking at the MIZAR project http://simplemachines.it/index.php/pages/mizar-project
    I found they used the Propeller on the VGA-shield.
    So I got here ;-)

    Maye it is posible to write some LUA interface to be used instead of the AT commands via serial from the Prop.
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-21 09:13
    Hi MJB,
    May be it is posible to write some LUA interface to be used instead of the AT commands via serial from the Prop.

    here is the API documentation of the nodeMCU-Firmware https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en

    EDIT: I found this example which seems to do serial communication. It's done a little strange to me and I have to dive deeper into it to understand
    how it works. Explanations are very appreciated

    Lua example-code for Serial communication with a ESP8266
    http://www.esp8266.com/viewtopic.php?f=19&t=1975

    best regards

    Stefan
  • StefanL38StefanL38 Posts: 2,292
    edited 2015-03-21 10:52
    now my understanding how Lua works is slowly growing:

    Lua has a uart-modul.
    in the uart-modul there is a "method" setup https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#uartsetup

    Wow Lua is crazy flexible and powerful

    I successfully wrote a small testcode that shows how receive serial data and how to process the data

    As this becomes more and more Lua-specific I will open a new thread ESP8266 with NodeMCU (Lua) Firmware
    http://forums.parallax.com/showthread.php/160533-serial-communication-with-the-ESP8266-using-the-nodeMCU-firmware-(script-languageLua)

    best regards

    Stefan
  • Cluso99Cluso99 Posts: 18,069
    edited 2015-03-21 19:08
    I posted on the other thread. However, perhaps here might be better as it has a history and prop info too.

    I was also pointed to this quick start for Lua using Python (from the PC and PropPlug)
    http://www.taylorcoffelt.com/article/1

    I have some time this afternoon, so I am torn between trying NodeMCU using the link
    http://benlo.com/esp8266/esp8266QuickStart.html
    and using the AT+ commands and spin.

    Maybe I'll try the AT+ first as this way I don't need to download NodeMCU yet. Then I can try Lua later.
    Off to grab my boards and jumpers :)
Sign In or Register to comment.