OSC send to NodeMCU
I am trying to send some OSC values from Max to Arduino using a NodeMCU (ESP8266). I have partially working. When I send a value to the board I get always the value -1.00.
I am just trying to send a simple toggle (0 - 1)
Why do I get -1.00 instead of 0-1?
the code in Arduino :
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCBundle.h> // for receiving OSC messages
char ssid[] = "TP-LINK_D44190"; // your network SSID (name)
char pass[] = "67966325"; // your network password
// Button Input + LED Output
const int ledPin = 14; // D5 pin at NodeMCU
const int boardLed = LED_BUILTIN; // Builtin LED
WiFiUDP Udp; // A UDP instance to let us send and receive packets over UDP
const unsigned int localPort = 8000; // local port to listen for UDP packets at the NodeMCU (another device must send OSC messages to this port)
const unsigned int destPort = 9000; // remote port of the target device where the NodeMCU sends OSC to
unsigned int ledState = 1; // LOW means led is *on*
void setup() {
Serial.begin(115200);
// Specify a static IP address for NodeMCU
// If you erase this line, your ESP8266 will get a dynamic IP address
WiFi.config(IPAddress(192,168,0,123),IPAddress(192,168,0,1), IPAddress(255,255,255,0));
// Connect to WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Starting UDP");
Udp.begin(localPort);
Serial.print("Local port: ");
Serial.println(Udp.localPort());
// LED Output
pinMode(boardLed, OUTPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(boardLed, ledState); // turn *off* led
}
void loop() {
OSCMessage msgIN;
int size;
if((size = Udp.parsePacket())>0){
while(size--)
msgIN.fill(Udp.read());
if(!msgIN.hasError()){
msgIN.route("/toggleLED",toggleOnOff);
}
}
}
void toggleOnOff(OSCMessage &msg, int addrOffset){
ledState = (boolean) msg.getFloat(0);
Serial.println(msg.getFloat(0));
digitalWrite(boardLed, (ledState + 1) % 2); // Onboard LED works the wrong direction (1 = 0 bzw. 0 = 1)
digitalWrite(ledPin, ledState); // External LED
if (ledState) {
Serial.println("LED on");
}
else {
Serial.println("LED off");
}
ledState = !ledState; // toggle the state from HIGH to LOW to HIGH to LOW ...
}
message to udpsend should be /toggleLED $1
thanks.. this is working .. Now I have another problem.. How could I get Arduino to get multiple values?
with the code under I get :
pixelNum:
10
pixelState:
10
pixelNum:
1
pixelState:
1
void pixelAni(OSCMessage &msg, int addrOffset){
int pixelNum = msg.getInt(0);
int pixelState = msg.getInt(1);
Serial.println("pixelNum: ");
Serial.println(pixelNum);
Serial.println("pixelState: ");
Serial.println(pixelState);
}
This is a solution to your problem. I am developing something similar, if you want we help each other. marceloivanfigueroa@gmail.com
In order for your computer and the NodeCMU to communicate wirelessly, they must both be on the same wireless network, and know about one another's IP addresses. We need to change the IP address in the python program to match the IP address of the NodeMCU so it knows where to send the data. To find the Node's IP address, open up the serial monitor and hit reset on your NodeMCU if you just see garbage, make sure to change the baud rate of the serial monitor to 115200. It should print out the ip address. Be careful when using this in projects, the Node's ip address might change between restarts.