Movement of two servos

I want to move two servos (X and Y) from node-red with the node-red-contrib-ui-joystick and an esp32 card, through the MQTT protocol but I don't know how to make that node return numeric values, I only get the addresses like: up, down, right and left

Here are 2 examples of mapping strings to numeric output.

[{"id":"8c79df799a065775","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"right","payloadType":"str","x":230,"y":4020,"wires":[["176f4895991e0b73","c972b7a991f0d619"]]},{"id":"176f4895991e0b73","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"right","fromt":"str","to":"1","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"left","fromt":"str","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":4040,"wires":[["a5d6577723690188"]]},{"id":"c972b7a991f0d619","type":"switch","z":"b9860b4b9de8c8da","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"left","vt":"str"},{"t":"eq","v":"right","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":310,"y":4100,"wires":[["fccde62f0a39cb30"],["e491dde00075eb15"]]},{"id":"78aae710123dc67a","type":"inject","z":"b9860b4b9de8c8da","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"left","payloadType":"str","x":230,"y":4060,"wires":[["176f4895991e0b73","c972b7a991f0d619"]]},{"id":"a5d6577723690188","type":"debug","z":"b9860b4b9de8c8da","name":"debug 320","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":4040,"wires":[]},{"id":"fccde62f0a39cb30","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":4080,"wires":[["bce0347d7989f9bd"]]},{"id":"e491dde00075eb15","type":"change","z":"b9860b4b9de8c8da","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":4120,"wires":[["bce0347d7989f9bd"]]},{"id":"bce0347d7989f9bd","type":"debug","z":"b9860b4b9de8c8da","name":"debug 321","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":4100,"wires":[]}]

You could also use Javascipt in a function node or JSONata in a change node.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.