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

Low cost wifi module ESP8266

1101113151618

Comments

  • Andy,
    Glad you got it going. WRT your question on ports in lua... the individual at this link includes defining a port in lua... http://blog.hekkers.net/2015/03/01/esp8266-testing-deep-sleep-interrupts/

    WRT logging in to your ESP outside your private network... XANANU (big thanks!) pointed me in the right direction but had some "trial and error" to get it functional. If I understand you correctly, you are having an issue with this. Forgive me if you have tried the following steps already...

    1. Get your public ip (whatsmyip). Mine is 98.xxx.xxx.xxx
    2. Set up port forwarding as follows... My Belkin router asks to fill in the following info for port forwarding... ON/OFF (select on), Description (I left this blank), Inbound port (I used 5xxx), Type (I selected both TCP and UDP), Private IP address (this is the static ip for my ESP), Private port (I use 80).
    3. In the URL line in your browser (is use chrome), on your cell phone, enter public ip and inbound port (98.xxx.xxx.xxx:5xxx) when outside the range of your wireless router.

    Good luck,
    Bob
  • NWCCTVNWCCTV Posts: 3,629
    edited 2016-07-08 00:53
    Yea, I have a good knowledge of Port forwarding, etc. I actually have a static IP and have my video server setup on port 85 and it works fine. I thought it was because it did not like Port 80 but even after changing to Port 88 I am still not having any luck. I will have to keep playing with it until I get it. What's really odd is that I have a loop back network configuration and my Static IP works within that.

    I am anxious to get this going. My first project is to create a motorized lock for my garage door. I have been testing the motor and am just waiting on my relays to arrive. I also have an electronic dead bolt on order for my back door. After that I have several other "gadgets" in mind!!!!
  • So, Anyone want to test it out? http://209.221.140.112:88/

    I don't have the LED's hooked up but you should still come up with the ESP Web Server. Let me know if it comes up. It did not from one of my outside clients but I went down the street and my Android phone worked.
  • NWCCTV wrote: »
    So, Anyone want to test it out? http://209.221.140.112:88/

    I don't have the LED's hooked up but you should still come up with the ESP Web Server. Let me know if it comes up. It did not from one of my outside clients but I went down the street and my Android phone worked.
    Safari was unable to open that link.

  • I have a hunch it's my router. I show port 88 wide open on canyouseeme.org . I will keep plugging away until I get it figured out. This is the last hurdle for now!!!
  • Is there anything out of the ordinary that needs to be done for Port Forwarding to these devices? I am really getting confused now. If I turn the device off the port does not show as open and when I turn it on it shows as open so I know it works up to that point. It works just fine on my LAN and also on my Loopback Network. Everything else I have ever worked with, if it works on the Loopback Network then it would work from outside. Also, I have Port 85 forwarded to my video server and it works with no issues.
  • Interesting. I just tried with Google Chrome and it worked fine. Just doesn't work under Safari for some reason.
  • Firefox displayed a bunch of HTML when I accessed that link.
    <h1> ESP8266 Web Server</h1><p>GPIO0 <a href="?pin=ON1"><button>ON</button></a>&nbsp;<a href="?pin=OFF1"><button>OFF</button></a></p><p>GPIO2 <a href="?pin=ON2"><button>ON</button></a>&nbsp;<a href="?pin=OFF2"><button>OFF</button></a></p>
    
  • Andy,
    Not sure if this is an issue for you, but I got this quote from the web... "Port numbers range from 0 to 65536, but only port numbers 0 to 1024 are reserved for privileged services and designated as well-known ports." I remember reading this a while ago... that's why I use port numbers in the 5xxx range.

    David,
    I red, on the web, that several people had connection issues when using Safari and the ESP8266. For some reason, they don't play nice together.

  • NAVFAC10 wrote: »
    Andy,
    Not sure if this is an issue for you, but I got this quote from the web... "Port numbers range from 0 to 65536, but only port numbers 0 to 1024 are reserved for privileged services and designated as well-known ports." I remember reading this a while ago... that's why I use port numbers in the 5xxx range.

    David,
    I red, on the web, that several people had connection issues when using Safari and the ESP8266. For some reason, they don't play nice together.
    That's odd. I use Safari all the time with my ESP8266 modules. However, I don't use NodeMCU. Maybe NodeMCU has issues with Safari? In any case, Firefox didn't work well with his site either.

  • This is really bizarre. I took my dog for a walk, about a mile away and i was able to open the web server page and turn on the LED's. I have seen some wild things in my years working on computers but this one is up in the top 5 strangest.
  • NWCCTV wrote: »
    This is really bizarre. I took my dog for a walk, about a mile away and i was able to open the web server page and turn on the LED's. I have seen some wild things in my years working on computers but this one is up in the top 5 strangest.
    How did you know they were really on from a mile away? :-)

  • I called my wife and she confirmed they were on and then off.
  • NWCCTV wrote: »
    I called my wife and she confirmed they were on and then off.
    Ah, cheating! I thought maybe you also had a light sensor that could tell you over the web interface whether they were really on.

  • No, But the web server page would have timed out also. I might try some ports in a higher range just to see what happens. I have a small motor connected now and it seems to work fine. I now have 3 devices running on different ports. LED's on one, a small motor on another and nothing on the third one. Since they are so cheap I impulse bought a bunch of the -01 and -12's. Going to hook up friends and family with some lights, etc. and then who knows what else!!!!
  • NWCCTVNWCCTV Posts: 3,629
    edited 2016-07-09 07:27
    Quick question. How would I go about connecting a servo motor to the GPIO?

    Edit: Never mind. I think I figured it out.
  • I think what I may end up doing is just creating a one page web server and hosting it on my video server system. I can then have links to turn on and off my various ESP8266 devices. I just find it odd that my Android can get to the web server but not all web browsers can. That will make it much easier and less stressful in the long run. I can make the web server private so I am the only one that can get to it and that should resolve that issue!!!1
  • Does anyone know how to send a text to a cell phone number (or send a text to a gmail account) using lua? Thanks.
  • Cluso99Cluso99 Posts: 18,069
    Website works (but I cannot confirm your leds work ;) ) with Windoze 10 and Edge.
  • Thanks Cluso99. As long as the site comes up the LED's will work when connected.

    So, I thought I had the Servo figured out but turns out I was wrong. Does anyone know a simple line of code to turn a servo on/off? I thought High/Low would do it but it does not. This is the code for the LED's:

    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);
  • NAVFAC10, Have you checked here? http://www.esp8266.com/

    Some things are a bit difficult to figure out but there is some useful posts in there.
  • Actually, I think I've got it figured out (sending a text to my cell phone). Just need to get home to test some new code.

    As far as servo's go, don't you have to pulse them every 20 milliseconds (with a pulse between .5 and 2 milliseconds)? Use a servo controller? Been awhile since I messed with them.

  • I googled nodemcu and servo control and was given this as one exmaple:
    local pin4 = 4
    --setup at position 0
    pwm.setup(pin4, 50, 71)
    --turn to position -90
    pwm.setduty(pin4, 27); pwm.start(D5); tmr.delay(500000); pwm.stop(D5)
    --turn to position 0 again
    pwm.setduty(pin4, 71); pwm.start(D5); tmr.delay(500000); pwm.stop(D5)
    --turn to position +90
    pwm.setduty(pin4, 123); pwm.start(D5); tmr.delay(500000); pwm.stop(D5)
    
    --27, 71 and 123 are the appropriated duty cycle "time" to set the desired position from 0 to 180 degrees up. I found this by experimenting.
    

    It appears to be doable, you may need to build a new nodemcu if you didn't include the pwm module in the one you made.
  • I found this for sending text messages. I also found some examples of servo usage, just need to figure it out now!!!!

    --[[
    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
    documentation files (the "Software"), to deal in the Software without restriction, 
    including without limitation the rights to use, copy, modify, merge, publish, distribute, 
    sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be 
    included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 
    IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    ]]--
    
    -- Your access point's SSID and password
    local SSID = "xxxxxx"
    local SSID_PASSWORD = "xxxxxx"
    
    -- configure ESP as a station
    wifi.setmode(wifi.STATION)
    wifi.sta.config(SSID,SSID_PASSWORD)
    wifi.sta.autoconnect(1)
    
    local TWILIO_ACCOUNT_SID = "xxxxxx"
    local TWILIO_TOKEN = "xxxxxx"
    
    local HOST = "iot-https-relay.appspot.com" -- visit http://iot-https-relay.appspot.com/ to learn more about this service
                                               -- Please be sure to understand the security issues of using this relay app and use at your own risk.
    local URI = "/twilio/Messages.json"
    
    function build_post_request(host, uri, data_table)
    
         local data = ""
         
         for param,value in pairs(data_table) do
              data = data .. param.."="..value.."&"
         end
    
         request = "POST "..uri.." HTTP/1.1\r\n"..
         "Host: "..host.."\r\n"..
         "Connection: close\r\n"..
         "Content-Type: application/x-www-form-urlencoded\r\n"..
         "Content-Length: "..string.len(data).."\r\n"..
         "\r\n"..
         data
    
         print(request)
         
         return request
    end
    
    local function display(sck,response)
         print(response)
    end
    
    -- When using send_sms: the "from" number HAS to be your twilio number.
    -- If you have a free twilio account the "to" number HAS to be your twilio verified number.
    local function send_sms(from,to,body)
    
         local data = {
          sid = TWILIO_ACCOUNT_SID,
          token = TWILIO_TOKEN,
          Body = string.gsub(body," ","+"),
          From = from,
          To = to
         }
         
         socket = net.createConnection(net.TCP,0)
         socket:on("receive",display)
         socket:connect(80,HOST)
    
         socket:on("connection",function(sck) 
           
              local post_request = build_post_request(HOST,URI,data)
              sck:send(post_request)
         end)     
    end
    
    function check_wifi()
     local ip = wifi.sta.getip()
    
     if(ip==nil) then
       print("Connecting...")
     else
      tmr.stop(0)
      print("Connected to AP!")
      print(ip)
         -- send a text message with the text "Hello from your esp8266"
      send_sms("15558889944","15559998845","Hello from your ESP8266") 
     end
     
    end
    
    tmr.alarm(0,7000,1,check_wifi)
    
  • MJBMJB Posts: 1,235
    edited 2016-07-10 17:09
  • Cluso99Cluso99 Posts: 18,069
    Wow! Some really neat things happening with nodemcu. Need more time ;)
  • Cluso99 wrote: »
    Wow! Some really neat things happening with nodemcu. Need more time ;)
    Yes, NodeMCU looks pretty interesting and Lua looks like a nice language. I wonder how well it would port to the Propeller?

  • MJBMJB Posts: 1,235
    David Betz wrote: »
    Cluso99 wrote: »
    Wow! Some really neat things happening with nodemcu. Need more time ;)
    Yes, NodeMCU looks pretty interesting and Lua looks like a nice language. I wonder how well it would port to the Propeller?
    there is eLua on some micros, but the P1 has just not enough memory.
    But P2 should work.
    Since it is in pure C you C-guys ;-) should be able to make it run, now that we have HUBExec.

    The search for a micro to run Lua on brought me to the Propeller some years ago.
    There is/was the Mizar32
    with a Propeller based VGA addon board.
    But at that time Peter started Tachyon so I stayed there.
    And now Lua runs on a $3 module ;-)
  • David BetzDavid Betz Posts: 14,511
    edited 2016-07-11 00:41
    MJB wrote: »
    Since it is in pure C you C-guys ;-) should be able to make it run, now that we have HUBExec.
    Well, there is still the small matter of needing a C compiler for the P2. :-)

    Also, I know no one wants to hear this but there is no reason eLua couldn't run on the P1 using the XMM memory model.

  • Cluso99Cluso99 Posts: 18,069
    I liked the little work I did with lua on the esp8266. Was quite easy.

    Wonder how much code a cut down lua would require on the P1? We could always try a P1V with more hub ram on a bemicro cv-a9. IIRC Roger did the auto incrementing for RDLONG which would double the LMM loop speed.
Sign In or Register to comment.