Skip to content

Instantly share code, notes, and snippets.

@griv
Last active March 2, 2018 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save griv/d07e789765ec3d19e4d68564a0beaf29 to your computer and use it in GitHub Desktop.
Save griv/d07e789765ec3d19e4d68564a0beaf29 to your computer and use it in GitHub Desktop.
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