Sorry, I didn't get that...
Thanks for your replies!
My hardware setup is: Arduino Uno, Arduino Ethernet Shield connected to TP-Link Nano Wireless router, MIDI Shield.
My aim is to build a standalone RawUDP->MIDI, MIDI->RawUDP standalone interface using Arduino modules.
The RawUDP part is the issue... I'm sure it's a small coding error.
#include <MIDI.h>
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0x90, 0xA2, 0xDA, 0x0D, 0xFC, 0xDD };
IPAddress ip(192,168,0,21);
int led = 6;
unsigned int localPort = 9000; // local port to listen on
IPAddress destinationIP(192, 168, 0, 223); // Address of target machine
unsigned int destinationPort = 9001; // Port to send to
// buffers for receiving and sending data
char packetBuffer[14]; //buffer to hold incoming packet,
char ReplyBuffer[] = "acknowledged"; // a string to send back
// An EthernetUDP instance to let us send and receive packets over UDP
EthernetUDP Udp;
void setup() {
pinMode(led, OUTPUT);
// start the Ethernet and UDP:
Ethernet.begin(mac,ip);
Udp.begin(localPort);
//Serial.begin(9600);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if(packetSize)
{
digitalWrite(led, HIGH);
// read the packet into packetBufffer
Udp.read(packetBuffer,UDP_TX_PACKET_MAX_SIZE);
// send a reply, to the IP address and port that sent us the packet we received
delay(10);
// The message is UDP equivalent of a MIDI SysEx message to turn channel 2 of an 01v96 console ON...
byte outBuf[] = {0xF0, 0x43, 0x10, 0x3E, 0x7F, 0x01, 0x1A, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0xF7};
// This should send all 14 bytes, zeros and all - this is not working!
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(outBuf, 14);
Udp.endPacket();
Serial.flush();
delay(2);
Serial.end();
// Change the arduino's baud rate to that of MIDI...
Serial.begin(31250);
//Send received string out via MIDI - this is working.
Serial.write(240); //F0
// Serial.println("SysEx Sent:");
// Serial.print(240);
//Serial.print(" ");
for (int n = 1; n< packetSize - 1; n++)
{
Serial.write(packetBuffer[n]);
// Serial.print(packetBuffer[n], DEC);
// Serial.print(" ");
}
Serial.write(247); //F7
Serial.flush();
delay(2);
Serial.end();
digitalWrite(led, LOW);
}
delay(10);
}
I'm receiving fine from the iPhone, and the MIDI is output correctly. But the UDP send back to the iPhone (which should turn channel 2 on in the iOS App) never gets received. That's my only stumbling block. Please note, I need the output to be Raw UDP, sent to the correct IP and Port. I think that's where the problem lies.
Hope you can help!