• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

http request

Scheduled Pinned Locked Moved Development
53 Posts 7 Posters 45.9k Views 6 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    acdacd2
    last edited by Jun 18, 2016, 5:07 PM

    hello,

    I need a module to show value from a http request url from an ipx (www.gce-electronics.com) device.

    any expérience?

    thx,

    1 Reply Last reply Reply Quote 0
    • A Offline
      acdacd2
      last edited by paviro Jul 17, 2016, 6:01 PM Jun 19, 2016, 5:32 PM

      In php I’m using this code

      $xml = simplexml_load_file('http://ip:8889/status.xml');
      $result = array();
      foreach($xml->children() as $child){
      $result[$child->getName()] = trim($child);
      }
      
      1 Reply Last reply Reply Quote 0
      • E Offline
        Eunanibus Module Developer
        last edited by Jun 20, 2016, 2:56 AM

        Sorry, I wanted to reply to this sooner but I had some issues setting up!

        What kind of information are you trying to display?

        A 1 Reply Last reply Jun 20, 2016, 5:10 PM Reply Quote 0
        • A Offline
          acdacd2 @Eunanibus
          last edited by Jun 20, 2016, 5:10 PM

          @Eunanibus Based on a xml file containing data from temperature captors, via the code above in php I visualise some data in a html table.

          I need convert the php code to js code, i think

          1 Reply Last reply Reply Quote 0
          • E Offline
            Eunanibus Module Developer
            last edited by Jun 20, 2016, 10:16 PM

            Sure. So I’d probably go about it with this approach and work from there:

            Try starting with the HelloWorld module and work from there. I’d start with putting this in the GetDom() function and return the contents of whatever you want displayed in the wrapper by appending it.

            var wrapper = document.createElement("div");
            var xmlhttp = new XMLHttpRequest();
            var url = "http://ip:8889/status.xml";
            
            xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    var results = JSON.parse(xmlhttp.responseText);
                    wrapper.innerHTML = parseResults(results);
                }
            };
            xmlhttp.open("GET", url, true);
            xmlhttp.send();
            return wrapper;
            
            function parseResults(results) {
               var nodes = results.childNodes;.
               var resultsContainer = document.createElement("div");
                var out = "";
                var i;
                for(i = 0; i < results.length; i++) {
                    var resultWrapper = document.createElement("div");
                    resultWrapper.innerHTML = x[i].nodeName + ": " + x[i].childNodes[0].nodeValue + "<br>";
                  resultsContainer.appendChild(resultWrapper);
                }
                return resultsContainer;
            }
            

            I’m a bit of a beginner too, but I think that might give you something to start with?

            1 Reply Last reply Reply Quote 0
            • A Offline
              acdacd2
              last edited by Jun 21, 2016, 6:53 PM

              wow super,

              I’m trying to run the code but “ReferenceError: document is not defined”

              1 Reply Last reply Reply Quote 0
              • E Offline
                Eunanibus Module Developer
                last edited by Jun 21, 2016, 7:39 PM

                I’m replying Mobile at the moment so I can’t give you a comprehensive answer (sorry) - does it say which line the error occurs?

                Ensure that the parseData function is not within the GetDom() method, but isolated on its own. Go through and ensure that the document.createElement(“div”) function is referencing a document.

                Sorry, I mocked up that code in about 10 minutes and I’m not an expert so there may be issues.

                1 Reply Last reply Reply Quote 0
                • A Offline
                  acdacd2
                  last edited by Jun 21, 2016, 8:01 PM

                  ok no problem, I will try to check and share of course

                  1 Reply Last reply Reply Quote 0
                  • A Offline
                    acdacd2
                    last edited by Jun 21, 2016, 8:14 PM

                    I think I’m not sure where exactly to put the code

                    1 Reply Last reply Reply Quote 0
                    • E Offline
                      Eunanibus Module Developer
                      last edited by Jun 22, 2016, 1:05 PM

                      Ok. I took a look at this last night and I’m getting somewhere so let me get back to you on this. I’m just trying to create the module for you.

                      1 Reply Last reply Reply Quote 0
                      • 1
                      • 2
                      • 3
                      • 4
                      • 5
                      • 6
                      • 1 / 6
                      1 / 6
                      • First post
                        5/53
                        Last post
                      Enjoying MagicMirror? Please consider a donation!
                      MagicMirror created by Michael Teeuw.
                      Forum managed by Sam, technical setup by Karsten.
                      This forum is using NodeBB as its core | Contributors
                      Contact | Privacy Policy