Arduino receiving UDP or IP
I want to use the possibility to receive Midi through UDP (or IP). In your Desktop examples you provide for both the possibility:
- Sending MIDI to the Arduino TCP Server
- Sending MIDI to the Arduino UDP Server
Both state: "If we have deployed the MidiUDPServer sketch we can send MIDI messages to Arduino:"
But I cannot find an MidiUDPServer sketch.
- There is only a "udp-send" example sketch but no udp-receive (with UDP server)
- There is an ip-receive example but the code in the loop is using "out" (sending messages)
Could you please give me some hints to get this working ? Currently I am using your AppleMidi solution which works fine.
Thank you Jaap
I think you can use the applemidi-receive.ino as starting point and just replace the AppleMidiServer with the MidiUdpServer
You are right: the ip-receive.ino looks wrong to me: I corrected it to what I think it should be
Thank you, no success yet but I will work on it ....
I have replaced the AppleMidiServer with the MidiUdpServer as you suggested. Because the server loop returns a void and not a bool i have also replaced the Arduino sketch loop:
void loop() {
apple.loop();
}
Is that correct ? I don't think so because the sketch does not react to the received UDP messages. The programs starts with:
Connected to IP address: 192.168.2.130
Info: bool midi::MidiUdpServer::begin(IPAddress, int)
Info: void midi::MidiStreamIn::setup(Stream*, midi::MidiParser*, bool)
That looks OK to me.
As an alternative I have also tried the unmodified appplemidi-receive.ino. On my Mac I have used the UDP Send python program:
import mido
import socket
UDP_IP = "192.168.2.130"
UDP_PORT = 5004
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
inport = mido.open_input('USB MIDI Interface')
for msg in inport:
print(msg)
sock.sendto(msg.bin(), (UDP_IP, UDP_PORT))
In this case the sketch recieves the UDP messages alright but does not seem to recognize them:
[APPLEMIDI] parse_udb_datagram: unknown command: 0x00004590
Any suggestions to try ?
Did you call the begin with the correct port. If you dont specify anything the default port 5008 is used. Can you share your sketch ?
/**
* @file applemidi-receive.ino
* @author Phil Schatzmann
* @brief Receiving Midi messages using Apple Midi
* @date 2021-12-24
*
* @copyright Copyright (c) 2021
*/
#include <WiFi.h>
#include "Midi.h"
MidiCallbackAction action;
MidiUdpServer apple(&action);
const char *SSID = "xxx";
const char *PWD = "yyy";
void onNoteOn(uint8_t channel, uint8_t note, uint8_t velocity) {
Serial.print("onNoteOn: ");
Serial.println(note);
}
void onNoteOff(uint8_t channel, uint8_t note, uint8_t velocity) {
Serial.print("onNoteOff: ");
Serial.println(note);
}
void setupWIFI() {
Serial.begin(119200);
MidiLogLevel = MidiInfo;
WiFi.begin(SSID, PWD);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(1000);
}
Serial.print("Connected to IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
action.setCallbacks(onNoteOn, onNoteOff);
setupWIFI();
apple.begin(5004);
}
void loop() {
// if (!apple.loop()){
// delay(10);
// }
apple.loop();
// delay(10);
}```
It think it should be something like apple.begin(IPAddress(192, 168, 2, 1),5004); where the address would point back to the sender
You are right, the MidiUdpServer begin requires an IP address, wonder why the compiler does not complain.
However, No change, still no incoming messages
apple.begin(IPAddress(192,168,2,111),5004); which is the address of the sender, my Mac