node-red flow menampilkan data dari gps

[{"id":"81f9ffeb.66d4d","type":"gpsd","z":"e108dd82.a3cce","name":"","hostname":"localhost","port":"2947","tpv":true,"sky":false,"info":false,"device":false,"gst":false,"att":false,"x":400,"y":160,"wires":[["33ea6491.a441ac","9f80de4c.be389"]]},{"id":"33ea6491.a441ac","type":"debug","z":"e108dd82.a3cce","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":160,"wires":[]},{"id":"9f80de4c.be389","type":"function","z":"e108dd82.a3cce","name":"","func":"msg.payload = {\n    name:\"cyberdeck\",\n    icon:\"fa-car\",\n    lat :,\n    lon : msg.payload.lon,\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":570,"y":260,"wires":[["f568e1f8.f22dd","a3414ec7.91967"]]},{"id":"f568e1f8.f22dd","type":"debug","z":"e108dd82.a3cce","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":260,"wires":[]},{"id":"a3414ec7.91967","type":"worldmap","z":"e108dd82.a3cce","name":"","lat":"","lon":"","zoom":"12","layer":"OSM","cluster":"","maxage":"","usermenu":"show","layers":"show","panit":"false","panlock":"false","zoomlock":"false","hiderightclick":"false","coords":"none","showgrid":"false","allowFileDrop":"false","path":"/map","x":800,"y":360,"wires":[]}]

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${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"

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

    driver: local
      type: "nfs"
      o: addr=,nolock,soft,rw
      device: ":/media/fdisk/nodered/"


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=\"<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="" />
<script src=""></script>

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

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

Tunggu sampai selesai kalau sukses maka node-red sudah terinstall