Hi Horace,
thanks for your reply.
I loaded a sketch of a simple web server (I have found it in example directory of wifi library) and then i checked that there was connection to the network and the server worked fine becouse I saw the web page at the IP address provided by the router for the shield.
Checking at the router IP address, I can see a correct allocation of an IP address to Arduino WiFi.
I tryed also to disable firewall but nothing change.
I load the code, it is so simple, I have found it amoung examples of the same library I have to use in order to connect to a rtp-midi session (AppleMidi.h).
I have only changed the value of "ssid" and "pass", and Wifi.begin(ssid, pass) becouse I have to connect to a network with password.
All work fine and I can see the messages on serial monitor of correct execution and connection. But when I try to connect the shield to my pc (using rtp-midi programm), a popup message says me that divice with IP:port(shield) doesn't reply to the connection request, and on the serial monitor is printed "Disconnected" that is found in "OnAppleMidiDisconnected" function at the end of the code.
As if there is an attempt of connection, but it fails and so the function OnAppleMidiDisconnected is called .
This is the code I use:
// Hardware: Mega 2560 R2 + Wifi Shield
// These need to be included when using standard Ethernet
#include <SPI.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#include "AppleMidi.h"
int status = WL_IDLE_STATUS;
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
unsigned long t0 = millis();
bool isConnected = false;
APPLEMIDI_CREATE_INSTANCE(WiFiUDP, AppleMIDI); // see definition in AppleMidi_Defs.h
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void setup()
{
// Serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
Serial.print("Getting IP address...");
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while (true);
}
String fv = WiFi.firmwareVersion();
if ( fv != "1.1.0" )
Serial.println("Please upgrade the firmware");
// attempt to connect to Wifi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println();
Serial.print("IP address is ");
Serial.println(WiFi.localIP());
Serial.println("OK, now make sure you an rtpMIDI session that is Enabled");
Serial.print("Add device named Arduino with Host/Port ");
Serial.print(WiFi.localIP());
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 = 1;
AppleMIDI.noteOn(note, velocity, channel);
AppleMIDI.noteOff(note, velocity, channel);
}
}
// ====================================================================================
// 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();
}