You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.7 KiB
Arduino

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiUdp.h>
#include <OSCMessage.h>
const char* ssid = ""; // EditThis: The name of your WiFi access point.
const char* password = "";
const int ledPin = LED_BUILTIN; // EditThis: Pin for LED control, use the built-in LED pin or specify your own pin.
WiFiUDP Udp; // Create a UDP object for OSC communication
const int localPort = 8080; // EditThis: The password of your WiFi access point.
// setup executes once after booting. It configures the underlying hardware for
// use in the main loop.
void setup() {
Serial.begin(9600);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
Serial.print("Connecting to WiFi ");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
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("Done!");
Udp.begin(localPort);
Serial.print("Listening for OSC messages on port ");
Serial.println(localPort);
}
void loop() {
HTTPClient http;
// Create a WiFiClient object
WiFiClient client;
// Specify the WiFi client and the request destination URL
http.begin(client, "http://127.0.0.1:8000/hello");
http.GET();
http.end();
delay(500);
if (Udp.parsePacket()) {
OSCMessage oscMsg;
while (Udp.available()) {
oscMsg.fill(Udp.read());
}
if (!oscMsg.hasError()) {
String address = oscMsg.getAddress();
if (address == "/led1") {
digitalWrite(D1, HIGH);
Serial.println("LED 1 turned ON");
delay(1000);
digitalWrite(D1, LOW);
Serial.println("LED 1 turned OFF");
} else if (address == "/led2") {
digitalWrite(D2, HIGH);
Serial.println("LED 2 turned ON");
delay(1000);
digitalWrite(D2, LOW);
Serial.println("LED 2 turned OFF");
} else if (address == "/led3") {
digitalWrite(D3, HIGH);
Serial.println("LED 3 turned ON");
delay(1000);
digitalWrite(D3, LOW);
Serial.println("LED 3 turned OFF");
}
} else {
Serial.print("Error parsing OSC message: ");
Serial.println(oscMsg.getError());
}
oscMsg.empty();
}
}