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 : msg.payload.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 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