goto

bynight

New member
Hallo,

bin bei Node red und java völlig neu. In Node Red gibt es wohl keine Sprungbefehle. Ich möchte gern verschidenen SOC zuständen verschiedene Ladeströme zuweisen.
Bisher sieht das im Funktionsmodul so aus und funktioniert auch:

Code:
if(msg.payload >=90){
  msg.payload = 0;
  }
else if (msg.payload >=85){
  msg.payload = 20;
  }
  else {
  msg.payload = 80;
  }
return msg;

ich hätte es gern etwas strukturierter und flexibler in der Abstufung, in etwa so:

Code:
if(msg.payload >=90){
  msg.payload = 0;
goto end:
  }
if(msg.payload >=80){
  msg.payload = 20;
goto end;
  }
if{msg.payload >= 70{
 msg.payload = 40;
gtop end;
if{msg.payload >= 60{
 msg.payload = 80;
gtop end;
  }
end:
return msg;

wie schreibt man das in in Java bzw. Node.js ohne goto?
Und wie würde man das ohne Funktionsbaustein mit den vorhandenen Bausteinen realisieren?

MfG,
Ronald
 
Zuletzt bearbeitet:
Meinst du so?

Screenshot 2024-10-11 160414.png

Flow für Import:

Code:
[{"id":"6e8918f1a03a2d38","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"98ffc2e371b04903","type":"debug","z":"6e8918f1a03a2d38","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2780,"y":140,"wires":[]},{"id":"9c9b78cc122f87d3","type":"change","z":"6e8918f1a03a2d38","name":"setze payload auf 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2550,"y":140,"wires":[["98ffc2e371b04903"]]},{"id":"97cdd9d39736a2b0","type":"change","z":"6e8918f1a03a2d38","name":"setze payload auf 20","rules":[{"t":"set","p":"payload","pt":"msg","to":"20","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2560,"y":200,"wires":[["0d34ab22f9d75eeb"]]},{"id":"bd1c0396b5547eb0","type":"change","z":"6e8918f1a03a2d38","name":"setze payload auf 60","rules":[{"t":"set","p":"payload","pt":"msg","to":"40","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2560,"y":260,"wires":[["2347ab3d93323a67"]]},{"id":"d0138948b62f9698","type":"switch","z":"6e8918f1a03a2d38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"90","vt":"num"},{"t":"lt","v":"90","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1830,"y":160,"wires":[["9c9b78cc122f87d3"],["9378cceed722354e"]]},{"id":"16cbebfb79b08496","type":"change","z":"6e8918f1a03a2d38","name":"setze payload auf 80","rules":[{"t":"set","p":"payload","pt":"msg","to":"80","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2560,"y":320,"wires":[["5750fec2c156b215"]]},{"id":"a15079e1a7494771","type":"inject","z":"6e8918f1a03a2d38","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"90","payloadType":"num","x":1610,"y":160,"wires":[["d0138948b62f9698"]]},{"id":"9b179eeaf19e7f29","type":"inject","z":"6e8918f1a03a2d38","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"80","payloadType":"num","x":1610,"y":200,"wires":[["d0138948b62f9698"]]},{"id":"f9fb38f84118db58","type":"inject","z":"6e8918f1a03a2d38","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"70","payloadType":"num","x":1610,"y":240,"wires":[["d0138948b62f9698"]]},{"id":"183dd8183249eb3f","type":"inject","z":"6e8918f1a03a2d38","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"60","payloadType":"num","x":1610,"y":280,"wires":[["d0138948b62f9698"]]},{"id":"0d34ab22f9d75eeb","type":"debug","z":"6e8918f1a03a2d38","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2780,"y":200,"wires":[]},{"id":"2347ab3d93323a67","type":"debug","z":"6e8918f1a03a2d38","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2780,"y":260,"wires":[]},{"id":"5750fec2c156b215","type":"debug","z":"6e8918f1a03a2d38","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2780,"y":320,"wires":[]},{"id":"9378cceed722354e","type":"switch","z":"6e8918f1a03a2d38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"80","vt":"num"},{"t":"lt","v":"80","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1950,"y":220,"wires":[["97cdd9d39736a2b0"],["b165d298b9ee36ce"]]},{"id":"b165d298b9ee36ce","type":"switch","z":"6e8918f1a03a2d38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"70","vt":"num"},{"t":"lt","v":"70","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":2090,"y":280,"wires":[["bd1c0396b5547eb0"],["2c29640dc1cf6cf9"]]},{"id":"2c29640dc1cf6cf9","type":"switch","z":"6e8918f1a03a2d38","name":"","property":"payload","propertyType":"msg","rules":[{"t":"gte","v":"60","vt":"num"},{"t":"lt","v":"60","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":2230,"y":340,"wires":[["16cbebfb79b08496"],["6bc0f36e01fb54b4"]]},{"id":"6bc0f36e01fb54b4","type":"debug","z":"6e8918f1a03a2d38","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2780,"y":380,"wires":[]},{"id":"c9a024a3f6f0a4fc","type":"inject","z":"6e8918f1a03a2d38","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"59","payloadType":"num","x":1610,"y":320,"wires":[["d0138948b62f9698"]]}]
 
Danke für die Antwort! Ich hatte es am Ende per Funktionsbaustein so gelöst, da ich auch noch viel mehr Abstufungen haben wollte:

Code:
 if(msg.payload >=100){
  msg.payload = 0;
  return msg;
}
 if(msg.payload >=99){
  msg.payload = 10;
  return msg;
}
 if(msg.payload >=98){
  msg.payload = 20;
  return msg;
}
 if(msg.payload >=97){
  msg.payload = 30;
  return msg;
}
 if(msg.payload >=96){
  msg.payload = 40;
  return msg;
}
 if(msg.payload >=95){
  msg.payload = 50;
  return msg;
}
 if(msg.payload >=94){
  msg.payload = 60;
  return msg;
}
 if(msg.payload >=93){
  msg.payload = 70;
  return msg;
}
 if(msg.payload >=92){
  msg.payload = 80;
  return msg;
}
 if(msg.payload >=91){
  msg.payload = 90;
  return msg;
}
 if(msg.payload >=90){
  msg.payload = 100;
  return msg;
}
 if(msg.payload >=88){
  msg.payload = 110;
  return msg;
}
 if(msg.payload >=86){
  msg.payload = 120;
  return msg;
}
 if(msg.payload >=84){
  msg.payload = 130;
  return msg;
}
 if(msg.payload >=82){
  msg.payload = 140;
  return msg;
}
 if(msg.payload >=80){
  msg.payload = 150;
  return msg;
}
 if(msg.payload >=78){
  msg.payload = 160;
  return msg;
}
 if(msg.payload >=76){
  msg.payload = 170;
  return msg;
}
 if(msg.payload >=74){
  msg.payload = 180;
  return msg;
}
 if(msg.payload >=72){
  msg.payload = 190;
  return msg;
}
 if(msg.payload >=70){
  msg.payload = 200;
  return msg;
}
msg.payload = 240
return msg;

Gruß,
Ronald
 
Ja, vor allem übersichtlich und einfach zu modifizieren. Inzwischen nutze ich es aber gar nicht mehr... ;-)
 

Zurzeit aktive Besucher

Letzte Anleitungen

Statistik des Forums

Themen
5.550
Beiträge
54.653
Mitglieder
5.371
Neuestes Mitglied
Zentrifuu
Zurück
Oben