Send data from Node red to UI Builder

Hi,
Hope you guys are doing well. I have been following the threads related to Soket.io, so that data from Node red could be sent to UI Builder.

Currently Im facing a problem related to get the data in UI Builder. I could fetch the msg.payload from Node red on the Java script function I have written. Even when I copy paste the solution for virtual Shopfloor from @ [TotallyInformation] ( Uibuilder + VueJS + SVG = visual IoT floorplan )
could see the tags such mentioned in part Mounted such as .onChange.

But whatever changes I make in Html and java script i can see it on the UI Builder.

For Info :
npm version - 8.12.2
node version - v16.14.0

Could you please help me, where am I making mistake.
Thank you in advance.

Please post your code so we can see it. Also, what version of uibuilder are you using.

This is the HTML data:

<!doctype html>
<html lang="en">
<head>

    <meta charset="utf-8">
    <meta http-equiv="refresh" content="120">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Wacker Neuson</title>
    <meta name="description" content="WN - Maschinenpark Überblich">
    <link rel="icon" href="">

    <!-- Your own CSS -->
    <link type="text/css" rel="stylesheet" href="./index.css" media="all">
    
    
</head>

<body class="uib">
    
    <h1>Überblick der Maschinenpark</h1>
    
    
    <div class="container">
        
        <div class="img1">
            <img src="./Halle-2.JPG" alt="H2" class="H-2" id="H-2"/>
            
        </div>
    
        <div class="button">
            
            <a href="http://127.0.0.1:1880/ui/#!/0?socketid=FePTsBggi4HWiQVoAAAF"><button 
     style="background-color: #FFBA01" class="Dash" id="Dash">DASHBOARD</button></a>

            
            <button 
                  type="button" class="H2" id="H2" onclick="h2(this)">HALLE-2
            </button>
          
             <button 
                  type="button" class="H3" id="H3" onclick="h3(this)">HALLE-3
            </button>
            
             <button 
                  type="button" class="H4" id="H4" onclick="h4(this)">HALLE-4
            </button>
            
           <div class="error">
               <h1 id="err">ERROR</h1>
           </div>
            
           
           
        </div>
    </div>
    
    <div class="overlay">
        
        <div class="Light1">
            
            <img src="" alt="" class="L1" id="L1"/>
            <img src="" alt="" class="L2" id="L2"/>
            
        </div>
        
    </div>
    
    <div>
        <p>Payload output</p>
        <div>
            <p>Messages Received</p>
             <div>Current No: {{vueApp.cardId}}</div>
        </div>
    </div>



    <script src="../uibuilder/node_modules/socket.io/client-dist/socket.io.js"></script>
    

    <!-- Vendor Libraries - Load in the right order -->
    <script src="../uibuilder/vendor/vue/dist/vue.js"></script> <!-- dev version with component compiler -->
    <!-- <script src="../uibuilder/vendor/vue/dist/vue.min.js"></script>   prod version with component compiler -->
    <!-- <script src="../uibuilder/vendor/vue/dist/vue.runtime.min.js"></script>   prod version without component compiler -->
    <script src="../uibuilder/vendor/bootstrap-vue/dist/bootstrap-vue.js"></script>

    <!-- REQUIRED: Sets up Socket listeners and the msg object -->
    <!-- <script src="./uibuilderfe.js"></script>   //dev version -->
    <script src="./uibuilderfe.min.js"></script> <!--    //prod version -->
    <!-- OPTIONAL: You probably want this. Put your custom code here -->
    <script src="./index.js"></script>

</body>
</html>

uibuilder version is - 5.0.2

This one is the Javascript data:
Mainly Im trying to fetch the data from Node-Red (msg.payload) in
vueApp.cardId = newVal.payload.

         function h2(ab)
{
        let obj= document.getElementById("H-2");
        obj.src ="./Halle-2.JPG";
        
        if(msg.payload==1){
            l1= document.getElementById("L1");
            l1.src ="./Red.JPG";
             l1.style.display="inline";
             
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="none";
        }
         if(msg.payload==2){
             
             l2= document.getElementById("L2");
            l2.src ="./Yellow.JPG";
             l2.style.display="inline";
             
            document.getElementById("L1").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="none";
        }
         if(msg.payload==3){
            document.getElementById("L1").style.display="none";
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="inline";
             document.getElementById("L4").style.display="none";
        }
         if(msg.payload==4){
            document.getElementById("L1").style.display="none";
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="inline";
        }
    
        
} 
var app1 = new Vue({

mounted: function(){
        //console.debug('[indexjs:Vue.mounted] app mounted - setting up uibuilder watchers')

        /** **REQUIRED** Start uibuilder comms with Node-RED @since v2.0.0-dev3
         * Pass the namespace and ioPath variables if hosting page is not in the instance root folder
         * e.g. If you get continual `uibuilderfe:ioSetup: SOCKET CONNECT ERROR` error messages.
         * e.g. uibuilder.start('/nr/uib', '/nr/uibuilder/vendor/socket.io') // change to use your paths/names
         */
        uibuilder.start('../uibuilder/node_modules/socket.io')

        var vueApp = this

        // Example of retrieving data from uibuilder
        vueApp.feVersion = uibuilder.get('version')

        /** You can use the following to help trace how messages flow back and forth.
         * You can then amend this processing to suite your requirements.
         */
         
        //#region ---- Trace Received Messages ---- //
        // If msg changes - msg is updated when a standard msg is received from Node-RED over Socket.IO
        // newVal relates to the attribute being listened to.
        uibuilder.onChange('msg', function(newVal){
            //console.info('[indexjs:uibuilder.onChange] msg received from Node-RED server:', newVal)
            vueApp.msgRecvd = newVal
                if ( newVal.topic == 'Green' ) {
        vueApp.cardId = newVal.payload
        }
                        if ( newVal.topic == 'Red' ) {
        vueApp.smallCount = newVal.payload
        }
        })
        // As we receive new messages, we get an updated count as well
        uibuilder.onChange('msgsReceived', function(newVal){
            //console.info('[indexjs:uibuilder.onChange] Updated count of received msgs:', newVal)
            vueApp.msgsReceived = newVal
        })

        // If we receive a control message from Node-RED, we can get the new data here - we pass it to a Vue variable
        uibuilder.onChange('ctrlMsg', function(newVal){
            //console.info('[indexjs:uibuilder.onChange:ctrlMsg] CONTROL msg received from Node-RED server:', newVal)
            vueApp.msgCtrl = newVal
        })
        
    }
    
})

Bit hard to decypher - can you please put the code inside preformatted text tripple backticks.

Javascript:

         function h2(ab)
{
        let obj= document.getElementById("H-2");
        obj.src ="./Halle-2.JPG";
        
        if(msg.payload==1){
            l1= document.getElementById("L1");
            l1.src ="./Red.JPG";
             l1.style.display="inline";
             
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="none";
        }
        
         if(msg.payload==2){
             
             l2= document.getElementById("L2");
            l2.src ="./Yellow.JPG";
             l2.style.display="inline";
             
            document.getElementById("L1").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="none";
        }
        
         if(msg.payload==3){
            document.getElementById("L1").style.display="none";
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="inline";
             document.getElementById("L4").style.display="none";
        }
         if(msg.payload==4){
            document.getElementById("L1").style.display="none";
             document.getElementById("L2").style.display="none";
             document.getElementById("L3").style.display="none";
             document.getElementById("L4").style.display="inline";
        }
    
        
} 



var app1 = new Vue({


mounted: function(){
        //console.debug('[indexjs:Vue.mounted] app mounted - setting up uibuilder watchers')

        /** **REQUIRED** Start uibuilder comms with Node-RED @since v2.0.0-dev3
         * Pass the namespace and ioPath variables if hosting page is not in the instance root folder
         * e.g. If you get continual `uibuilderfe:ioSetup: SOCKET CONNECT ERROR` error messages.
         * e.g. uibuilder.start('/nr/uib', '/nr/uibuilder/vendor/socket.io') // change to use your paths/names
         */
        uibuilder.start('../uibuilder/node_modules/socket.io')

        var vueApp = this

        // Example of retrieving data from uibuilder
        vueApp.feVersion = uibuilder.get('version')

        /** You can use the following to help trace how messages flow back and forth.
         * You can then amend this processing to suite your requirements.
         */
         
        //#region ---- Trace Received Messages ---- //
        // If msg changes - msg is updated when a standard msg is received from Node-RED over Socket.IO
        // newVal relates to the attribute being listened to.
        uibuilder.onChange('msg', function(newVal){
            //console.info('[indexjs:uibuilder.onChange] msg received from Node-RED server:', newVal)
            vueApp.msgRecvd = newVal
                if ( newVal.topic == 'Green' ) {
        vueApp.cardId = newVal.payload
        }
                        if ( newVal.topic == 'Red' ) {
        vueApp.smallCount = newVal.payload
        }
        })
        // As we receive new messages, we get an updated count as well
        uibuilder.onChange('msgsReceived', function(newVal){
            //console.info('[indexjs:uibuilder.onChange] Updated count of received msgs:', newVal)
            vueApp.msgsReceived = newVal
        })

        // If we receive a control message from Node-RED, we can get the new data here - we pass it to a Vue variable
        uibuilder.onChange('ctrlMsg', function(newVal){
            //console.info('[indexjs:uibuilder.onChange:ctrlMsg] CONTROL msg received from Node-RED server:', newVal)
            vueApp.msgCtrl = newVal
        })
        
    }
    
})


Not needed since Node-RED should be sending your page data so that you don't need to keep refreshing.

Is not the correct URL. ../uibuilder/vendor/socket.io-client/socket.io.min.js is the correct URL.

I had the same code earlier, but still wasnt working so I tried to modify it. But now again I have changed to the later part as suggested by you.

The problem is the UI Builder is not recognizing the Output from Node red and also not interpreting the data from Java script. So in HTML when I wrote this code -

<div>
        <p>Payload output</p>
        <div>
            <p>Messages Received</p>
             <div>Current No: {{vueApp.cardId}}</div>
        </div>
    </div>

It showing the same with curly brackets in the Dashboard. As shown in the picture.

My Project is basically to make a Dashboard on which the lights will be switched on and off with the help of bulb images depending on the topic and payload that i receive from the node red.

Dashboard:

image

Is this Vue v2 or Vue v3? Only Vue v2 works with bootstrap-vue.

That is not the signature in any of the examples. uibuilder.start(this) for uibuilder v5 with Vue v2.

When using Vue, you would normally use Vue's methods so that should be:

<button  type="button" class="H2" id="H2" @click="h2">HALLE-2</button>

What errors are you getting in the browser dev console?

I have installed the following libraries.

image

On the developer Console Im not getting any error.

This is my flow.

And this is the dev console.

image

I was using till now the svelte basic as the template. Will that be reason of not fetching the data from Node Red?

This problem is solved, just by installing the vue@2 version.
Thanks alot [TotallyInformation] for your help. I managed to find the console error and followed old threads to solve it. Thanks again. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.