Created
May 22, 2019 17:39
-
-
Save psct/53badc53446a6d886bfa955874d0d384 to your computer and use it in GitHub Desktop.
luftdaten.info per Node-Red in MQTT schieben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Verarbeitet die JSON-Daten, die ein Sensor per Web-API abliefert | |
// und spuckt sie fertig formatiert zur Verarbeitung durch einen | |
// mqtt-Output-Node wieder aus. Funktioniert für Sensoren, die mit einem | |
// oder zwei Temperaturfühlern ausgestattet sind. | |
// Zur Entgegennahme in Node-Red eignet sich ein http-Input-Node, den | |
// man für die POST-Methode konfiguriert und uploads akzeptieren lässt. | |
var output_msgs = []; | |
for ( i= 0; i < 7; i++) { | |
if ( i > 3) { | |
topic= 'feinstaub2'; | |
sensor= msg.payload.sensordatavalues[i].value_type.slice(7); | |
} else { | |
topic= 'feinstaub1'; | |
sensor= msg.payload.sensordatavalues[i].value_type; | |
if ( i === 0) { sensor= 'pm10'; } | |
if ( i == 1) { sensor= 'pm2.5'; } | |
} | |
value=msg.payload.sensordatavalues[i].value; | |
output_msgs.push({ topic:`home/${topic}/sensors/${sensor}`, payload:`${value}`}); | |
} | |
return [ output_msgs ]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment