Skip to content

Instantly share code, notes, and snippets.

@dropmeaword
Last active May 8, 2019 15:37
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 dropmeaword/4c38baed17032c1bc2e0545ffb9438b2 to your computer and use it in GitHub Desktop.
Save dropmeaword/4c38baed17032c1bc2e0545ffb9438b2 to your computer and use it in GitHub Desktop.
send stuff from nodeMCU to wekinator
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
const char* ssid = "IoT";
const char* pass = "IoT4onderwijs";
WiFiUDP Udp;
// destination IP
IPAddress dest(127, 0, 0, 1);
const unsigned int destPort = 6448; // in the case of wekinator is always this number
int reading = 0;
void setup() {
Serial.begin(115200);
// Connect to WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
// light up the on-board LED to signal that we are connected to wifi
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
// print WiFi connection details
Serial.println("Connected to wifi!");
Serial.println("with IP address: ");
Serial.println(WiFi.localIP());
}
void dispatch_osc_message() {
OSCMessage msg("/wek/inputs");
// here you SEND the state of your hardware inputs (sensors, buttons, etc.)
msg.add( reading );
Udp.beginPacket(dest, destPort);
msg.send(Udp);
Udp.endPacket();
msg.empty();
}
void loop() {
// here you READ the state of your hardware inputs (sensors, buttons, etc.)
reading = analogRead(0); // read analog value at pin 0
dispatch_osc_message();
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment