Install node-red in lxc alpine


My note to run node-red in alpine linux container inside proxmox

apk upgrade --update \
&&apk upgrade --update \
 && apk add curl make gcc g++ linux-headers paxctl musl-dev \
    libgcc libstdc++ binutils-gold python openssl-dev zlib-dev \
 && mkdir -p /root/src \
 && cd /root/src \
 && curl -sSL https://nodejs.org/dist/${NODE_VERSION}/node-${NODE_VERSION}.tar.gz | tar -xz \
 && cd /root/src/node-* \
 && ./configure --prefix=/usr --without-snapshot \
 && make -j$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) \
 && make install \
 && paxctl -cm /usr/bin/node \
 && npm cache clean \
 && apk del make gcc g++ python linux-headers \
 && rm -rf /root/src /tmp/* /usr/share/man /var/cache/apk/* \
    /root/.npm /root/.node-gyp /usr/lib/node_modules/npm/man \
    /usr/lib/node_modules/npm/doc /usr/lib/node_modules/npm/html \
 && apk search --update

npm install -g pm2@latest

pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" -- -v

pm2 save
pm2 startup

Multiple output function in node-red


This is sample flow for multiple output in one function in node-red

[{"id":"5f08a336.d9c24c","type":"function","z":"2aaa7997.d6ad76","name":"","func":"raw = msg.payload.object;\n\nvar msg1 = { payload:raw.analogInput[1]};\nvar msg2 = { payload:raw.analogInput[2]};\nvar msg3 = { payload:raw.analogOutput[3]};\nvar msg4 = { payload:raw.temperatureSensor[3]};\nvar msg5 = { payload:raw.humiditySensor[4]};\nvar msg6 = { payload:raw.barometer[5]};\n\n\nreturn [ msg1, msg2, msg3, msg4, msg5, msg6 ];\n\n// msg.payload ={\n//     battery : raw[1],\n//     solar:raw[2]\n// }\n// return msg;","outputs":6,"noerr":0,"initialize":"","finalize":"","x":520,"y":660,"wires":[["719a5264.f5757c"],["1d8c7f1.9f75281"],["e4b2ebe4.6b0728"],["418e174c.6f7258"],["46ea126c.0ec36c"],["703fee7.477581"]]}]

Install node-red in docker swarm with share data in nfs


I’m using portainer

Please read my note before this for setting nfs

This is my docker stack ‘

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Asia/Jakarta
    ports:
      - "1880:1880"
    networks:
      - node-red-net
    volumes:
      - nodered.vol:/data
    user: root:root

volumes:
  nodered.vol:
    driver: local
    driver_opts:
      type: "nfs"
      o: addr=192.168.0.13,nolock,soft,rw
      device: ":/media/fdisk/nodered/"

networks:
  node-red-net:

If you have permission problem when you running your stack in nfs share maybe you can add user:root:root in your stack it works for me

Happy Coding

Salam Ngoprek

How to embed google map at node-red ui template


This is some example how to embed google map at your template for node-red ui dashboard, hope this help and don’t forget to add your own key for google map at gmap template

Good Luck

Happy Coding

Salam ngoprek

[{"id":"cab47749.47c698","type":"inject","z":"322d96d4.be125a","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":560,"wires":[["c80c476c.d450c8"]]},{"id":"c80c476c.d450c8","type":"function","z":"322d96d4.be125a","name":"map","func":"\nvar latitude =-6.21462;\nvar longitude =106.84513;\n\n\nmsg.payload = {latitude, longitude}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":560,"wires":[["22edf841.88a418"]]},{"id":"22edf841.88a418","type":"ui_template","z":"322d96d4.be125a","group":"8add4fe8.53baf","name":"GMAP","order":3,"width":"6","height":"6","format":"<!DOCTYPE html>\n<html>\n  <head>\n    <style>\n       /* Set the size of the div element that contains the map */\n      #map {\n        height: 100%;  /* The height is 400 pixels */\n        width: 100%;  /* The width is the width of the web page */\n       }\n    </style>\n  </head>\n  <body>\n\n    <!--The div element for the map -->\n    <div id=\"map\"></div>\n \n\n<script>  \n\nvar latitude;\nvar longitude;\n\n(function(scope) {\n        //Have to use $watch so we pick up new, incoming msg's\n        scope.$watch('msg.payload', function() {\n\n        initMap(scope.msg.payload)     \n            \n        })\n\n\n    })(scope)\n    \n\n\n\n// // // Initialize and add the map\n function initMap(data) {\n\n  \n  var latitude = data.latitude\n  var longitude = data.longitude\n  \n  console.log(latitude);\n  console.log(longitude);\n  \n  var jakarta = {lat:latitude , lng: longitude };\n\n\n  var map = new google.maps.Map(\n      document.getElementById('map'), {zoom: 18, center: jakarta, mapTypeId: 'satellite'});\n\n  var marker = new google.maps.Marker({position: jakarta, map: map});\n}\n\n    </script>\n\n    <script async defer\n    src=\"https://maps.googleapis.com/maps/api/js?key=<yourkeyhere>&callback=initMap\">\n    </script>\n\n  </body>\n</html>\n\n\n\n","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":false,"templateScope":"local","x":690,"y":560,"wires":[["92a07c8.8e7118"]]},{"id":"92a07c8.8e7118","type":"debug","z":"322d96d4.be125a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":870,"y":560,"wires":[]},{"id":"8add4fe8.53baf","type":"ui_group","z":"","name":"Pictures","tab":"c23383c7.b69a7","order":1,"disp":false,"width":"6","collapse":false},{"id":"c23383c7.b69a7","type":"ui_tab","z":"","name":"LIGHTING PLANT","icon":"dashboard","order":2}]

Add map to node-red


<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.3/leaflet.js"></script>

<script>
    (function() {
        const cScope = this.scope;
        setTimeout(function () {
            
        	const map = L.map('mapid').setView([48.204550, 16.364333], 13);
            let marker;
            
        	L.tileLayer('https://{s}.wien.gv.at/basemap/geolandbasemap/normal/google3857/{z}/{y}/{x}.png', {
        		maxZoom: 18,
                subdomains: ["maps1", "maps2", "maps3", "maps4"]
        	}).addTo(map);
        	
        	map.on('click', function(e) {
                cScope.send(e.latlng);
                if (marker) {
                    map.removeLayer(marker);
                };
                marker = L.circleMarker(e.latlng).addTo(map);
            });
            
            setTimeout(function () {
                map.invalidateSize();
            }, 100);
        }, 300);
    })();
</script>

<div id="mapid" style="width: 100%; height: 320px;"></div>

This is some sample ui template for node-red ui, hope this help

Happy Coding

Salam ngoprek

Simple scheduler in node-red


This is sample flow for scheduling task in node-red, i’m using this for controling pump in my diy indoor hydroponics system

[{"id":"7092122b.f6593c","type":"inject","z":"fee8201c.ff1e","name":"timer lamp on","topic":"lamp","payload":"1","payloadType":"str","repeat":"","crontab":"00 06 * * *","once":false,"onceDelay":0.1,"x":460,"y":1660,"wires":[["85b40c2d.7fdcc"]]},{"id":"e3a49fce.3cda7","type":"inject","z":"fee8201c.ff1e","name":"timer lamp off","topic":"lamp","payload":"0","payloadType":"str","repeat":"","crontab":"00 06 * * *","once":false,"onceDelay":0.1,"x":460,"y":1620,"wires":[["85b40c2d.7fdcc"]]},{"id":"85b40c2d.7fdcc","type":"debug","z":"fee8201c.ff1e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":730,"y":1640,"wires":[]}]

Happy Coding

Salam Ngoprek

Cara subscribe dan publish mqtt menggunakan node-red


Ok kali ini saya akan membagikan cara bagaimana pubsub (publish dan subscribe) di node-red, pertama tama pastikan node-red sudah terinstall kalau belum terinstall coba buka postingan saya dibawah tentang bagaimana cara install node-red di raspberry pi.

Langkah pertama buka browser kalian dan jalankan http://localhost:1880 kalau kalian menjalankannya didalam raspberry pi, kalau remote tinggal masukkan ip raspberry pi diikuti dengan portnya misalkan jadinya http://192.168.0.3:1880 cara mengetahui ip raspberry pi kalian berapa coba jalankan ifconfig di terminal, nanti kalian bisa menemukan ip kalian disana.

Ok setelah terbuka node-red maka akan menampilkan seperti dibawah ini

Screenshot from 2019-11-01 09-57-33

setelah itu kita install mqtt plugin di node-red dengan cara buka manage pallete didalam menu ( garis 3 = ) dibagian atas lihat gambar dibawah

Screenshot from 2019-11-01 09-59-48

setelah terbuka maka masuk ke pallete install lalu masukkan mqtt di search dan install node-red-contrib-mqtt-broker

Screenshot from 2019-11-01 10-01-45

Tunggu beberapa saat sampai terinstall selanjutnya kembali ke halaman depan dan ketikkan mqtt di filter nodes, maka plugin mqtt sudah terinstall.

Screenshot from 2019-11-01 10-03-12

Cara menggunakan plugin ini adalah dengan cara drag n drop ke dalam Flow, kalau kita  perhatian ada dua macam nodes yaitu mqtt in dan mqtt out mqtt in artinya kita subscribe ke topik apabila mqtt out maka kita publish ke mqtt broker.

Ok langkah selanjutnya adalah pastikan kalian menginstall mqtt broker kalau belum silahkan lihat postingan sebelum ini mengenai cara menginstall mqtt di raspberry pi, detailnya howto nya silahkan lihat video dibawah

untuk alamat ip di mosquitto server saya menggunakan 10.81.141.48 kalau di tempat kalian bisa menggunakan ip kalian masing masing atau bisa juga localhost kalau kalian menjalankannya langsung di raspberry pi.

Demikian tutorial ini semoga bermanfaat

Happy Coding …

Salam ngoprek …

Menginstall node-red di Raspberry pi


Cara mudah menginstall node-red di Raspberry

  1. Pastikan internet lancar
  2. Jalankan perintah dibawah ini
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)

Tunggu sampai selesai kalau sukses maka node-red sudah terinstall

 

 

Playing with node-red and firebase


Screenshot from 2019-03-13 08-53-48

[{"id":"b4b35eea.927f1","type":"firebase modify","z":"1998deec.25e9e1","name":"","firebaseconfig":"","childpath":"data/level2","method":"set","value":"msg.payload","priority":"msg.priority","x":562,"y":285,"wires":[[]]},{"id":"d1031a34.0b5af8","type":"firebase modify","z":"1998deec.25e9e1","name":"","firebaseconfig":"","childpath":"data/level/","method":"set","value":"msg.payload","priority":"msg.priority","x":564,"y":200,"wires":[[]]},{"id":"5f50c27e.cc4b3c","type":"inject","z":"1998deec.25e9e1","name":"","topic":"","payload":"200","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":158,"y":200,"wires":[["d1031a34.0b5af8"]]},{"id":"a271ad16.9eab5","type":"inject","z":"1998deec.25e9e1","name":"","topic":"","payload":"{\"dev_id\":\"coba\",\"height\":200}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":158,"y":282,"wires":[["b4b35eea.927f1"]]},{"id":"6d4975ae.f1823c","type":"firebase.on","z":"1998deec.25e9e1","name":"","firebaseconfig":"","childpath":"data","atStart":true,"eventType":"value","queries":[],"x":258,"y":380,"wires":[["35856d82.641bb2"]]},{"id":"35856d82.641bb2","type":"debug","z":"1998deec.25e9e1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":614,"y":378,"wires":[]}]