ESP8266 AJAX tutorial - send data without page refresing

แชร์
ฝัง
  • เผยแพร่เมื่อ 19 ธ.ค. 2024

ความคิดเห็น • 73

  • @kamikazegoat3641
    @kamikazegoat3641 3 ปีที่แล้ว

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

  • @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.

  • @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!

  • @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+"%");

  • @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.

  • @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());

  • @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

  • @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?

  • @charlesdeguzman2088
    @charlesdeguzman2088 5 ปีที่แล้ว

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

  • @ismail_aydemir_youtube
    @ismail_aydemir_youtube ปีที่แล้ว

    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?

  • @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

  • @hf568tube
    @hf568tube 7 ปีที่แล้ว

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

  • @npslucknow9235
    @npslucknow9235 2 ปีที่แล้ว

    Working on local network or Internet ?

  • @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!

  • @HIGH_TECH_NEWS
    @HIGH_TECH_NEWS 6 ปีที่แล้ว

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

  • @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

  • @xiaomyredmii7430
    @xiaomyredmii7430 6 ปีที่แล้ว

    what if you use AT-commands?

    • @ulasdikme7307
      @ulasdikme7307  6 ปีที่แล้ว

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

  • @elmersunga5776
    @elmersunga5776 4 ปีที่แล้ว

    is this possible sir? two data.

  • @afdyclinton1315
    @afdyclinton1315 7 ปีที่แล้ว +1

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

  • @MrWorkPage
    @MrWorkPage 5 ปีที่แล้ว

    How do I automatically reconnect?

  • @ismail_aydemir_youtube
    @ismail_aydemir_youtube ปีที่แล้ว

    Sir, you are great.

  • @jimjulian4443
    @jimjulian4443 2 ปีที่แล้ว

    Thanks, but in 2022 the sketch will not compile.

  • @monoamiga
    @monoamiga 5 ปีที่แล้ว

    The argument for setTimeout is miliseconds, NOT microseconds.

  • @farhan8328
    @farhan8328 5 ปีที่แล้ว +1

    Thanks, it was very helpful,

  • @nipunaupeksha
    @nipunaupeksha 5 ปีที่แล้ว

    Thanks man. Really helped me out!

  • @TreudtLP
    @TreudtLP 3 ปีที่แล้ว

    Great Video thanks a lot!

  • @kadirozdinc6065
    @kadirozdinc6065 6 ปีที่แล้ว

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

  • @user-im6py6or6v
    @user-im6py6or6v 6 ปีที่แล้ว

    not working! please give a sketch

  • @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.

  • @PhG1961
    @PhG1961 6 ปีที่แล้ว

    Awesome !! Thnxs for sharing !

  • @PanosKontogiannis
    @PanosKontogiannis 6 ปีที่แล้ว

    very nice, thanks a million

  • @mesinantrianyogyakarta6710
    @mesinantrianyogyakarta6710 6 ปีที่แล้ว

    Thanks for this tutor

  • @iamtipe
    @iamtipe 5 ปีที่แล้ว

    LIFE SAVER

  • @eastern815
    @eastern815 7 ปีที่แล้ว

    awesome man

  • @pupanpoulkaew9860
    @pupanpoulkaew9860 5 ปีที่แล้ว

    thx bro