Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]
- /*
- WiFiEsp example: ConnectWPA
- This example connects to an encrypted WiFi network using an ESP8266 module.
- Then it prints the MAC address of the WiFi shield, the IP address obtained
- and other network details.
- For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-connect.html
- */
- #include "WiFiEsp.h"
- #include "WiFiEspUdp.h"
- #include "AppleMidi.h"
- APPLEMIDI_CREATE_INSTANCE(WiFiEspUDP, AppleMIDI);
- char ssid[] = "cie_yang_gak_punya_paket"; // your network SSID (name)
- char pass[] = "gakadapassword"; // your network password
- int status = WL_IDLE_STATUS; // the Wifi radio's status
- unsigned long t0 = millis();
- bool isConnected = false;
- void setup()
- {
- // initialize serial for debugging
- Serial.begin(115200);
- // initialize serial for ESP module
- Serial3.begin(115200);
- // initialize ESP module
- WiFi.init(&Serial3);
- // check for the presence of the shield
- if (WiFi.status() == WL_NO_SHIELD) {
- Serial.println("WiFi shield not present");
- // don't continue
- while (true);
- }
- // attempt to connect to WiFi network
- while ( status != WL_CONNECTED) {
- Serial.print("Attempting to connect to WPA SSID: ");
- Serial.println(ssid);
- // Connect to WPA/WPA2 network
- status = WiFi.begin(ssid, pass);
- }
- Serial.println("You're connected to the network");
- // print the network connection information every 10 seconds
- Serial.println();
- printCurrentNet();
- printWifiData();
- Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
- Serial.print("Add device named Arduino with Port ");
- Serial.println(":5004");
- Serial.println("Then press the Connect button");
- Serial.println("Then open a MIDI listener (eg MIDI-OX) and monitor incoming notes");
- // Create a session and wait for a remote host to connect to us
- AppleMIDI.begin("test");
- AppleMIDI.OnConnected(OnAppleMidiConnected);
- AppleMIDI.OnDisconnected(OnAppleMidiDisconnected);
- AppleMIDI.OnReceiveNoteOn(OnAppleMidiNoteOn);
- AppleMIDI.OnReceiveNoteOff(OnAppleMidiNoteOff);
- Serial.println("Sending NoteOn/Off of note 45, every second");
- }
- void loop()
- {
- // Listen to incoming notes
- AppleMIDI.run();
- // send a note every second
- // (dont cรกll delay(1000) as it will stall the pipeline)
- if (isConnected && (millis() - t0) > 1000)
- {
- t0 = millis();
- // Serial.print(".");
- int note = 45;
- int velocity = 55;
- int channel = 2;
- AppleMIDI.noteOn(note, velocity, channel);
- Serial.println("Note on sent");
- AppleMIDI.noteOff(note, velocity, channel);
- Serial.println("Note off sent");
- }
- }
- void printWifiData()
- {
- // print your WiFi shield's IP address
- IPAddress ip = WiFi.localIP();
- Serial.print("IP Address: ");
- Serial.println(ip);
- // print your MAC address
- byte mac[6];
- WiFi.macAddress(mac);
- char buf[20];
- sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
- Serial.print("MAC address: ");
- Serial.println(buf);
- }
- void printCurrentNet()
- {
- // print the SSID of the network you're attached to
- Serial.print("SSID: ");
- Serial.println(WiFi.SSID());
- // print the MAC address of the router you're attached to
- byte bssid[6];
- WiFi.BSSID(bssid);
- char buf[20];
- sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X", bssid[5], bssid[4], bssid[3], bssid[2], bssid[1], bssid[0]);
- Serial.print("BSSID: ");
- Serial.println(buf);
- // print the received signal strength
- long rssi = WiFi.RSSI();
- Serial.print("Signal strength (RSSI): ");
- Serial.println(rssi);
- }
- // ====================================================================================
- // Event handlers for incoming MIDI messages
- // ====================================================================================
- // -----------------------------------------------------------------------------
- // rtpMIDI session. Device connected
- // -----------------------------------------------------------------------------
- void OnAppleMidiConnected(uint32_t ssrc, char* name) {
- isConnected = true;
- Serial.print("Connected to session ");
- Serial.println(name);
- }
- // -----------------------------------------------------------------------------
- // rtpMIDI session. Device disconnected
- // -----------------------------------------------------------------------------
- void OnAppleMidiDisconnected(uint32_t ssrc) {
- isConnected = false;
- Serial.println("Disconnected");
- }
- // -----------------------------------------------------------------------------
- //
- // -----------------------------------------------------------------------------
- void OnAppleMidiNoteOn(byte channel, byte note, byte velocity) {
- Serial.print("Incoming NoteOn from channel:");
- Serial.print(channel);
- Serial.print(" note:");
- Serial.print(note);
- Serial.print(" velocity:");
- Serial.print(velocity);
- Serial.println();
- }
- // -----------------------------------------------------------------------------
- //
- // -----------------------------------------------------------------------------
- void OnAppleMidiNoteOff(byte channel, byte note, byte velocity) {
- Serial.print("Incoming NoteOff from channel:");
- Serial.print(channel);
- Serial.print(" note:");
- Serial.print(note);
- Serial.print(" velocity:");
- Serial.print(velocity);
- Serial.println();
- }
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment