Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ESP8266 OSC -> Serial Bridge
/*
ESP8266 Bridge OSC -> Serial
Receives OSC (Port 8888), and passes it through to Serial
Have been using this with Teensy 3.2 (Serial 1)
*/
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
#include <OSCBundle.h>
#include <OSCData.h>
#include <SLIPEncodedSerial.h>
SLIPEncodedSerial SLIPSerial(Serial);
// Wifi settings
const char* ssid = "SSID";
const char* password = "PASSWD";
// A UDP instance to let us send and receive packets over UDP
WiFiUDP Udp;
// Port to receive on
const unsigned int localPort = 8888;
void connectToWiFi() {
// No Access Point mode for us
WiFi.mode(WIFI_STA);
// Connect to WiFi network
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Udp.begin(localPort);
}
void setup() {
SLIPSerial.begin(115200);
connectToWiFi();
delay(1000);
}
void loop() {
OSCMessage msg;
int size = Udp.parsePacket();
if (size > 0) {
while (size--) {
msg.fill(Udp.read());
}
if (!msg.hasError()) {
// forward message to serial
SLIPSerial.beginPacket();
msg.send(SLIPSerial); // send the bytes to the SLIP stream
SLIPSerial.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.