<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Multiple URL Querys to fill JSON]]></title><description><![CDATA[<p dir="auto">I hope I describe it correct and you understand what I mean.<br />
I’m writing a new module which has to display the information from 2 different URL’s.<br />
When I query them seperate than everythink works OK.<br />
But I want to do query from URL-1 to JSON (MHW-P1) and URL-2 to JSON (MHW-WM).</p>
<p dir="auto">Is this possible and how?<br />
This is what I’ve came up with, but it doesn’t work.</p>
<p dir="auto"><strong>node_helper.js</strong></p>
<pre><code>// P1 Meter section
//
getMHW_P1: function(urlP1) {
        // Make a GET request using the Fetch API for the P1 Meter
        fetch(urlP1)
          .then(response_P1 =&gt; {
            if (!response_P1.ok) {
              console.error('MMM-MyHomeWizard: Network response was not ok');
            }
            return response_P1.json();
          })

          .then(result_P1 =&gt; {
            // Process the retrieved user data
            console.log(result_P1); // Remove trailing slashes to display data in Console for testing
            this.sendSocketNotification('MHWP1_RESULT', result_P1);
          })

          .catch(error =&gt; {
            console.error('Error:', error);
          });
  },

  socketNotificationReceived: function(notification, payload_P1) {
            if (notification === 'GET_MHWP1') {
            this.getMHW_P1(payload_P1);
            }
  },
  
  // Water Meter Section
  //
  getMHW_WM: function(urlWM) {
        // Make a GET request using the Fetch API for the Water Meter
        fetch(urlWM)
          .then(response_WM =&gt; {
            if (!response_WM.ok) {
              console.error('MMM-MyHomeWizard: Network response was not ok');
            }
            return response_WM.json();
          })

          .then(result_WM =&gt; {
            // Process the retrieved user data
            console.log(result_WM); // Remove trailing slashes to display data in Console for testing
            this.sendSocketNotification('MHWWM_RESULT', result_WM);
          })

          .catch(error =&gt; {
            console.error('Error:', error);
          });
  },

  socketNotificationReceived: function(notification, payload_WM) {
            if (notification === 'GET_MHWWM') {
            this.getMHW_WM(payload_WM);
            }
  },
</code></pre>
<p dir="auto"><strong>MMM-MyModules.js</strong></p>
<pre><code>// &lt;-- P1 Meter Section --&gt;
	
	// This processes your data P1 Meter
	processMHW_P1: function(data_P1) { 
		this.MHW_P1 = data_P1; 
		console.log(JSON.stringify(this.MHW_P1)); // uncomment to see if you're getting data (in dev console)
		this.loaded = true;
	},

	// this tells module when to update
	scheduleUpdate: function() { 
		setInterval(() =&gt; {
		    	this.getMHW_P1();
			this.getMHW_WM();
		}, this.config.updateInterval);
		this.getMHW_P1();
		this.getMHW_WM();
		var self = this;
	},
	  
	// this asks node_helper for data
	getMHW_P1: function() { 
		this.sendSocketNotification('GET_MHWP1', this.urlP1);
	},

	// this gets data from node_helper
	socketNotificationReceived: function(notification_P1, payload_P1) { 
		if (notification_P1 === "MHWP1_RESULT") {
		// this notification doesn't come back on error..
		this.processMHW_P1(payload_P1);
		this.updateDom(this.config.initialLoadDelay); 
		}
	},
	
//&lt;-- Water Meter Section --&gt;
	
	// This processes your data Water Meter
	processMHW_WM: function(data_WM) { 
		this.MHW_WM = data_WM; 
		console.log(JSON.stringify(this.MHW_WM)); // uncomment to see if you're getting data (in dev console)
		this.loaded = true;
	},

/*	// this tells module when to update
	scheduleUpdate: function() { 
		setInterval(() =&gt; {
		    	this.getMHW_WM();
		}, this.config.updateInterval);
		this.getMHW_WM();
		var self = this;
	},
*/	  
	// this asks node_helper for data
	getMHW_WM: function() { 
		this.sendSocketNotification('GET_MHWWM', this.urlWM);
	},

	// this gets data from node_helper
	socketNotificationReceived: function(notification_WM, payload_WM) { 
		if (notification_WM === "MHWWM_RESULT") {
		// this notification doesn't come back on error..
		this.processMHW_WM(payload_WM);
		this.updateDom(this.config.initialLoadDelay);
		}
	},

I hope somebody can help me with this.
I'm not a programmer, but I try to do my best ;-)
</code></pre>
]]></description><link>https://forum.magicmirror.builders/topic/19213/multiple-url-querys-to-fill-json</link><generator>RSS for Node</generator><lastBuildDate>Mon, 07 Sep 2026 06:53:58 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/19213.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 11 Dec 2024 13:41:48 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:40:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> Wow, it works!<br />
Just checking, it has to be done in node_helper and the MMM-Module?</p>
]]></description><link>https://forum.magicmirror.builders/post/121846</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121846</guid><dc:creator><![CDATA[htilburgs]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:40:11 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 22:01:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mmrize" aria-label="Profile: MMRIZE">@<bdi>MMRIZE</bdi></a> Thanks for your reaction.</p>
]]></description><link>https://forum.magicmirror.builders/post/121865</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121865</guid><dc:creator><![CDATA[htilburgs]]></dc:creator><pubDate>Wed, 11 Dec 2024 22:01:51 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 15:59:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mmrize" aria-label="Profile: MMRIZE">@<bdi>MMRIZE</bdi></a> quite true, since fetch is now part of electron.</p>
]]></description><link>https://forum.magicmirror.builders/post/121853</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121853</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 11 Dec 2024 15:59:53 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 15:51:05 GMT]]></title><description><![CDATA[<p dir="auto">This is not a direct answer to the question, but just for your reference.<br />
The <code>fetch</code> API can be executed directly in the browser, not just in a Node.js environment. You can call the <code>fetch</code> API directly in <code>MMM-MyModule.js</code> without needing <code>node_helper.js</code>.</p>
<p dir="auto">Additionally, since the <code>fetch</code> API works asynchronously, you can manage the responses of two fetch calls as follows:</p>
<ul>
<li>If you need to use the response that arrives first, use <code>Promise.race()</code> or <code>Promise.any()</code>.</li>
<li>If you need to wait for both responses to arrive before proceeding, use <code>Promise.all()</code>.</li>
</ul>
<p dir="auto">Using these methods can help you manage data synchronization more efficiently.</p>
]]></description><link>https://forum.magicmirror.builders/post/121852</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121852</guid><dc:creator><![CDATA[MMRIZE]]></dc:creator><pubDate>Wed, 11 Dec 2024 15:51:05 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:54:10 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> Thnx, you helped me a lot!!</p>
]]></description><link>https://forum.magicmirror.builders/post/121850</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121850</guid><dc:creator><![CDATA[htilburgs]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:54:10 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:47:35 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/htilburgs" aria-label="Profile: htilburgs">@<bdi>htilburgs</bdi></a> the sendSocketNotification(xyz,foo) -------&gt;socketNotificationReceived(notification, payload)<br />
in both directions…</p>
<p dir="auto">only one received on each side… if there are multiple, then the last one seen is used.</p>
]]></description><link>https://forum.magicmirror.builders/post/121847</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121847</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:47:35 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:40:11 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> Wow, it works!<br />
Just checking, it has to be done in node_helper and the MMM-Module?</p>
]]></description><link>https://forum.magicmirror.builders/post/121846</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121846</guid><dc:creator><![CDATA[htilburgs]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:40:11 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:31:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/htilburgs" aria-label="Profile: htilburgs">@<bdi>htilburgs</bdi></a> I meant in the node_helper… you have 2 there as well</p>
]]></description><link>https://forum.magicmirror.builders/post/121845</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121845</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:31:59 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:27:21 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> I’ve changed it into this, but still only result from the WaterMeter and not the P1 meter</p>
<pre><code>	socketNotificationReceived: function(notification, payload) { 
		if (notification === "MHWP1_RESULT") {
		// this notification doesn't come back on error..
		this.processMHW_P1(payload);
		this.updateDom(this.config.initialLoadDelay); 
		}
		else if (notification === "MHWWM_RESULT") {
		// this notification doesn't come back on error..
		this.processMHW_WM(payload);
		this.updateDom(this.config.initialLoadDelay);
		}
	},
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/121842</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121842</guid><dc:creator><![CDATA[htilburgs]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:27:21 GMT</pubDate></item><item><title><![CDATA[Reply to Multiple URL Querys to fill JSON on Wed, 11 Dec 2024 14:00:47 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/htilburgs" aria-label="Profile: htilburgs">@<bdi>htilburgs</bdi></a> you cant have two socketNotificationReceived() functions</p>
<p dir="auto">only 1, but it gets both notifications</p>
<pre><code>if notification=== "type1"
     call this function
else   if notification=== "type2"
     call that function
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/121838</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/121838</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 11 Dec 2024 14:00:47 GMT</pubDate></item></channel></rss>