ESP8266 AJAX tutorial - send data without page refresing

Sdílet
Vložit
  • čas přidán 14. 04. 2017
  • Send data without page refresing from ESP8266 to the web server
    ulasdikme.com/index.php/2018/0...
    Background music - www.bensound.com

Komentáře • 73

  • @carltone
    @carltone Před 3 lety

    Ulas ,Thank-you for sharing your knowledge. Well done instructional video. Your live interactive , error checking (style) really helped make this tutorial much more meaningful.

  • @georgrichter7199
    @georgrichter7199 Před 4 lety

    Thx, that was exactly what i am looking for!! Super Tutorial!

  • @afdyclinton1315
    @afdyclinton1315 Před 7 lety +1

    this help me a lot, thanks a lot for sharing!

  • @nipunaupeksha
    @nipunaupeksha Před 5 lety

    Thanks man. Really helped me out!

  • @kamikazegoat3641
    @kamikazegoat3641 Před 3 lety

    My dude this is exactly what I was looking for. Plus you got a great voice. What a great day

  • @karolku3136
    @karolku3136 Před 5 lety +1

    I love you, I have looked for this month for my project, thank you very much. Biiiiiiiiiiiiiiiiiiiiig beer for you :)

  • @charlesdeguzman2088
    @charlesdeguzman2088 Před 5 lety

    Thanks for the explanation, very helpful... what model of esp8266 did you use?

  • @farhan8328
    @farhan8328 Před 5 lety +1

    Thanks, it was very helpful,

  • @KrisKasprzak
    @KrisKasprzak Před 4 lety

    This is close to what I"m trying to do however, my ESP-01 is a module so I need to communicate through a serial1 port. Can your code be modified to send to a Serial port? I've found other libraries that pass the serial port into the wifi object, but they don't support the methods in your example server.on for example. I'm trying to find a library that supports communicating via Serial but can use examples such as this.

  • @PhG1961
    @PhG1961 Před 5 lety

    Awesome !! Thnxs for sharing !

  • @sharkyigor
    @sharkyigor Před 3 lety

    thank you! just a quick question.. how do you send data back? for example the content of a dropdown onchange? thank you!

  • @CorbSPeters
    @CorbSPeters Před 7 lety +1

    How does this work? How does the esp8266 running the C code know when to send the XML data to the client? I understand the Javascript running on the client requests the XML every 200ms or something set by the timeout. How does the ESP8266 know to run the XMLcontent function to rebuild and send the XML data?

  • @robitops1547
    @robitops1547 Před 4 lety +1

    Awesome Bro. (specially for error correction show up)

  • @eastern815
    @eastern815 Před 6 lety

    awesome man

  • @PanosKontogiannis
    @PanosKontogiannis Před 5 lety

    very nice, thanks a million

  • @harshsuvarna7943
    @harshsuvarna7943 Před 5 lety

    What is the baud rate that you have set? I am using it at 115200 but it's giving garbage values ..please help

  • @ismail_aydemir_mylife
    @ismail_aydemir_mylife Před 9 měsíci

    Sir, you are great.

  • @TreudtLP
    @TreudtLP Před 3 lety

    Great Video thanks a lot!

  • @ismail_aydemir_mylife
    @ismail_aydemir_mylife Před 9 měsíci

    This method is successful because it connects to the same network. So, how is the remote server sent to an HTML page with another IP address? with the same method?

  • @hf568tube
    @hf568tube Před 6 lety

    You wrote inside the Video "Code is below".
    I can't find the code. Where is it?

  • @mesinantrianyogyakarta6710

    Thanks for this tutor

  • @HIGH_TECH_NEWS
    @HIGH_TECH_NEWS Před 6 lety

    could you please share the code? is somewhat hard to copy on the fly

  • @MrWorkPage
    @MrWorkPage Před 4 lety

    How do I automatically reconnect?

  • @QuzalMehmood
    @QuzalMehmood Před 7 lety

    Thanks alot , Can I send data from esp to my website using ajax ? if so then tell me how ? I'm using Get or Post Method

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety

      The right question " where is your website ?", where is the server ? on your local or on the internet somewhere ?

    • @QuzalMehmood
      @QuzalMehmood Před 7 lety

      my server is on the internet on my website

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety

      ıf you understand the post get method wtih php, there will be only one thing to pass, which is ajax,
      stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php
      you can find much more information implementation ajax to the php.

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety

      also this one,
      www.codeofaninja.com/2013/09/jquery-ajax-post-example.html

  • @kadirozdinc6065
    @kadirozdinc6065 Před 6 lety

    Fascinating and so useful example, but you had better share the codes with us :)

  • @npslucknow9235
    @npslucknow9235 Před 2 lety

    Working on local network or Internet ?

  • @winter20rulez
    @winter20rulez Před 7 lety +2

    How would my code look if I wanted to send 2 types of data? For instance, I want to send a temperature value to website but also a humidity value.

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety +2

      add simply two variable in the main loop. For instance,
      Data = (String)temprature + (String)Humidity;
      then, you will see the two variables in the screen.

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety +1

      Main idea is ,xml does not care how many variable send to webserver. Just add each variable as a string then send them.

    • @winter20rulez
      @winter20rulez Před 7 lety

      I'm having trouble with the javascript code. I want to display them like this:
      Temperature: X
      Humidity: Y
      I don't know how to do that. I added two response tags in XML function, like this:
      void buildXML(){
      XML="";
      XML+="";
      XML+=getTemperature();
      XML+="";
      XML+="";
      XML+=getHumidity();
      XML+="";
      }
      Then, I changed the javascript like this:
      javaScript+="function handleServerResponse(){
      ";
      javaScript+=" if(xmlHttp.readyState==4 && xmlHttp.status==200){
      ";
      javaScript+=" xmldoc=xmlHttp.responseXML;
      ";
      javaScript+=" message = xmldoc.getElementsByTagName('response')[0].firstChild.nodeValue;
      ";
      javaScript+=" document.getElementById('temperature').innerHTML=message;
      ";
      javaScript+=" message = xmldoc.getElementsByTagName('response2')[0].firstChild.nodeValue;
      ";
      javaScript+=" document.getElementById('humidity').innerHTML=message;
      ";
      javaScript+=" }
      ";
      javaScript+="}
      ";
      javaScript+="
      ";
      After I upload this program, I see no value, neither for temperature, nor for humidity.

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety +1

      no, just add them in the main loop. You do not have to change the xml part.

    • @ulasdikme7307
      @ulasdikme7307  Před 7 lety

      It is better to see whole code, but I think you should do,
      data = String(getTemprature())+String(getHumidity());

  • @iamtipe
    @iamtipe Před 4 lety

    LIFE SAVER

  • @KrisKasprzak
    @KrisKasprzak Před 4 lety

    How do you pass more that one value using your XML approach?

    • @ulasdikme7307
      @ulasdikme7307  Před 4 lety

      Hi, send me you code and ı can make the related change

    • @KrisKasprzak
      @KrisKasprzak Před 4 lety

      ​@@ulasdikme7307 Thanks for the replay. I got it working--and the system will post race car telemetry to a "big screen" TV on the pit. I'm actually sending data from the car to the pit using Teensy 3.2 (current setup using EBYTE transceivers, display and a bunch of other things), then I send the incoming struct from Teensy to ESP using serial (had to use easyTransfer.h) , then ESP process the struct and builds a web page displaying the 20 or so data points. Your code worked for 1 val but not multiple until I added to the function response section:
      Javascript+="var xmlResponse;
      ";
      Javascript+="var xmldoc ;
      ";
      Javascript+="var message;
      ";
      My system is now working and I can connect phones/PC's etc to the site). My web page is just a simple table but that is my next venture--to snazzy it up. Man I hate writing HTML code and java script as it's really non-intuitive.
      Well done in posting this, I would never have figured this out.

    • @KrisKasprzak
      @KrisKasprzak Před 4 lety

      I'm now real stuck trying to update a width property
      I have all this running where my MCU reads data and populates a website--it's actually very cool. I have a table of data and in one cell i have a rectangle that i would like the width to vary--a battery level indicator
      here's my java
      // this will not update a width
      xmlResponse=xmlHttp.responseXML;
      xmldoc = xmlResponse.getElementsByTagName('ERem');
      message = xmldoc[0].firstChild.nodeValue;
      document.getElementsByClassName('bar').width=message;
      // this will update a number in the table
      xmlResponse=xmlHttp.responseXML;
      xmldoc = xmlResponse.getElementsByTagName('CarSpeed');
      message = xmldoc[0].firstChild.nodeValue;
      document.getElementById('CarSpeed').innerHTML=message;
      // style definition
      .data {
      font-family: "arial";
      font-size: 20px;
      color: #FFFFFF;
      text-align: right;
      }

      .bar {
      position: relative;
      height: 30px;
      border: 3px solid gray
      }
      // html table code
      thoughts?

    • @KrisKasprzak
      @KrisKasprzak Před 4 lety

      Got it all working I needed to add "%" after message length
      ....style.width=(message+"%");

  • @TechInventorAman
    @TechInventorAman Před 4 lety

    what's the meaning of +data+ like what does the "+" sign do ?

    • @Startix
      @Startix Před 4 lety

      this is when you would show the content of a variable in a string

  • @jimjulian4443
    @jimjulian4443 Před 2 lety

    Thanks, but in 2022 the sketch will not compile.

  • @xiaomyredmii7430
    @xiaomyredmii7430 Před 5 lety

    what if you use AT-commands?

    • @ulasdikme7307
      @ulasdikme7307  Před 5 lety

      Well, if you can implement javascript over tcp with AT then everything should be same...

  • @monoamiga
    @monoamiga Před 4 lety

    The argument for setTimeout is miliseconds, NOT microseconds.

  • @elmersunga5776
    @elmersunga5776 Před 4 lety

    is this possible sir? two data.

  • @pupanpoulkaew9860
    @pupanpoulkaew9860 Před 5 lety

    thx bro

  • @user-im6py6or6v
    @user-im6py6or6v Před 6 lety

    not working! please give a sketch

  • @Xen_Prime
    @Xen_Prime Před 5 lety +1

    Javascript on arduino. unbelievable

    • @ulasdikme7307
      @ulasdikme7307  Před 5 lety +2

      It is just a buch of string for browser :)

    • @Xen_Prime
      @Xen_Prime Před 5 lety

      @@ulasdikme7307 anyway. you did a good explanation

    • @ulasdikme7307
      @ulasdikme7307  Před 5 lety

      @@Xen_Prime Thank you. Do not forget to be subscribe ! :)

    • @billallen275
      @billallen275 Před 4 lety +1

      @@ulasdikme7307 Yeah but it is still Really COOL! Thanks - I'm in the process of doing a logging/charting upload/download project for use in the field and this helps a lot! Been digging into the rabbit hole - fascinating! Now putting different pieces together. Nice work, thank you!

    • @ulasdikme7307
      @ulasdikme7307  Před 4 lety +1

      @@billallen275 I would recommend you to use websocket. You can find an example in my channel.