ESP8266 AJAX tutorial - send data without page refresing

Поділитися
Вставка
  • Опубліковано 22 сер 2024
  • Send data without page refresing from ESP8266 to the web server
    ulasdikme.com/i...
    Background music - www.bensound.com

КОМЕНТАРІ • 73

  • @carltone
    @carltone 3 роки тому

    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.

  • @kamikazegoat3641
    @kamikazegoat3641 3 роки тому

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

  • @ismail_aydemir_mylife
    @ismail_aydemir_mylife 10 місяців тому

    Sir, you are great.

  • @robitops1547
    @robitops1547 4 роки тому +1

    Awesome Bro. (specially for error correction show up)

  • @KrisKasprzak
    @KrisKasprzak 4 роки тому

    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.

  • @ismail_aydemir_mylife
    @ismail_aydemir_mylife 10 місяців тому

    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?

  • @CorbSPeters
    @CorbSPeters 7 років тому +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?

  • @TreudtLP
    @TreudtLP 3 роки тому

    Great Video thanks a lot!

  • @karolku3136
    @karolku3136 5 років тому +1

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

  • @georgrichter7199
    @georgrichter7199 4 роки тому

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

  • @sharkyigor
    @sharkyigor 3 роки тому

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

  • @afdyclinton1315
    @afdyclinton1315 7 років тому +1

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

  • @harshsuvarna7943
    @harshsuvarna7943 5 років тому

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

  • @charlesdeguzman2088
    @charlesdeguzman2088 5 років тому

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

  • @farhan8328
    @farhan8328 5 років тому +1

    Thanks, it was very helpful,

  • @monoamiga
    @monoamiga 4 роки тому

    The argument for setTimeout is miliseconds, NOT microseconds.

  • @jimjulian4443
    @jimjulian4443 2 роки тому

    Thanks, but in 2022 the sketch will not compile.

  • @nipunaupeksha
    @nipunaupeksha 5 років тому

    Thanks man. Really helped me out!

  • @hf568tube
    @hf568tube 6 років тому

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

  • @winter20rulez
    @winter20rulez 7 років тому +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  7 років тому +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  7 років тому +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 7 років тому

      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  7 років тому +1

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

    • @ulasdikme7307
      @ulasdikme7307  7 років тому

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

  • @KrisKasprzak
    @KrisKasprzak 4 роки тому

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

    • @ulasdikme7307
      @ulasdikme7307  4 роки тому

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

    • @KrisKasprzak
      @KrisKasprzak 4 роки тому

      ​@@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 4 роки тому

      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 4 роки тому

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

  • @HIGH_TECH_NEWS
    @HIGH_TECH_NEWS 6 років тому

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

  • @npslucknow9235
    @npslucknow9235 2 роки тому

    Working on local network or Internet ?

  • @PhG1961
    @PhG1961 5 років тому

    Awesome !! Thnxs for sharing !

  • @PanosKontogiannis
    @PanosKontogiannis 5 років тому

    very nice, thanks a million

  • @elmersunga5776
    @elmersunga5776 4 роки тому

    is this possible sir? two data.

  • @iamtipe
    @iamtipe 4 роки тому

    LIFE SAVER

  • @MrWorkPage
    @MrWorkPage 4 роки тому

    How do I automatically reconnect?

  • @TechInventorAman
    @TechInventorAman 4 роки тому

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

    • @Startix
      @Startix 4 роки тому

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

  • @Xen_Prime
    @Xen_Prime 5 років тому +1

    Javascript on arduino. unbelievable

    • @ulasdikme7307
      @ulasdikme7307  5 років тому +2

      It is just a buch of string for browser :)

    • @Xen_Prime
      @Xen_Prime 5 років тому

      @@ulasdikme7307 anyway. you did a good explanation

    • @ulasdikme7307
      @ulasdikme7307  5 років тому

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

    • @billallen275
      @billallen275 4 роки тому +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  4 роки тому +1

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

  • @mesinantrianyogyakarta6710
    @mesinantrianyogyakarta6710 6 років тому

    Thanks for this tutor

  • @kadirozdinc6065
    @kadirozdinc6065 6 років тому

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

  • @QuzalMehmood
    @QuzalMehmood 7 років тому

    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  7 років тому

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

    • @QuzalMehmood
      @QuzalMehmood 7 років тому

      my server is on the internet on my website

    • @ulasdikme7307
      @ulasdikme7307  7 років тому

      ı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  7 років тому

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

  • @user-im6py6or6v
    @user-im6py6or6v 6 років тому

    not working! please give a sketch

  • @eastern815
    @eastern815 6 років тому

    awesome man

  • @xiaomyredmii7430
    @xiaomyredmii7430 5 років тому

    what if you use AT-commands?

    • @ulasdikme7307
      @ulasdikme7307  5 років тому

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

  • @pupanpoulkaew9860
    @pupanpoulkaew9860 5 років тому

    thx bro