Introduction
It is quite easy to add OSC capabilities to your node-red flow. This allows you to easily create a bridge between other web-based protocols with OSC for your awesome sonic creations!
Setup
The osc node is already installed in the preconfigured image, but if you’re starting from scratch, you can easily download it by typing npm install node-red-contrib-osc
in your ~/.node-red folder.
Adding OSC Sending to your flow
You should see the OSC node in both the input and output categories in the left toolbar. Building upon the previous example of getting sensor data from the PiShield, we can send the data as an OSC message to an external location. To do so, copy the following flow:
[{"id":"773dc0e9.bb9bb","type":"inject","z":"e0005358.7b6a8","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"x":187.66665649414062,"y":166.66661834716797,"wires":[["c98261b7.4b7d"]]},{"id":"c98261b7.4b7d","type":"mcp3008","z":"e0005358.7b6a8","name":"PiShield Sensor 1","device":"/dev/spidev0.0","mode":"0x80","interval":"10","x":371.6666564941406,"y":172.6666488647461,"wires":[["87496a73.8fc7e8"]]},{"id":"87496a73.8fc7e8","type":"osc out","z":"e0005358.7b6a8","name":"","addr":"192.168.1.101","port":"7000","path":"/node-red/PiShield1","x":634.6666564941406,"y":198.6666488647461,"wires":[]}]
It should look like the following:
Now, open up the OSC node by double clicking on it, and set the appropriate end points (IP address, port, and namespace:
Now you should be able to receive sensor data via OSC on the other side!
OSC Receiving
Similarly, if you add the OSC input node, you will be able to receive messages. As an example, the following short snippet shows an OSC receiver at port 8000, printing received messages to the debug console:
[{"id":"fb13005.73753","type":"osc in","z":"e0005358.7b6a8","name":"","addr":"0.0.0.0","port":"8000","x":296.5,"y":286,"wires":[["b12d2f8c.4eeab"]]},{"id":"b12d2f8c.4eeab","type":"debug","z":"e0005358.7b6a8","name":"","active":true,"console":"false","complete":"false","x":559.5,"y":286,"wires":[]}]
When deployed, a message sent (here from Max/MSP using the namespace “/helloFromMax”, with an integer 1234 looks like the following: