Sorry, I missed the last part, following the skrech I have loaded into Arduino:
#include <NewPing.h>
#include <Ethernet.h>
#include <SPI.h>
#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte abyStartReceiver[] = {0xAA, 0xBB, 0x01, 0x01, 0x11, 0x01, 0xAA, 0xCC };
byte abyLoadParameter1[] = {0xAA, 0xBB, 0x01, 0x01, 0x1E, 0x00, 0x01, 0xAA, 0xCC};
boolean bStartEnabled = false;
byte byReceived;
IPAddress serverIP(192,168, 0, 1);
int serverPort=4007;
EthernetClient client;
int msg;
void setup()
{
Serial.begin(9600);
IPAddress IP(192,168,0,177); //static assignment of IP address
Ethernet.begin(mac,IP); //if not specified gateway=192.168.0.1 and subnet=255.255.255.0
delay(1000);
pinMode(2, INPUT);
Serial.println("connecting to Server ...");
// if you get a connection to the Server
if (client.connect(serverIP, serverPort)) {
Serial.println("Connected");//report it to the Serial
Serial.println("Load Parameters 1 ");//log to serial
client.write(abyLoadParameter1, 9);//send the message
delay(1000);
Serial.println("Sending START Message ");//log to serial
client.write(abyStartReceiver, 8);//send the message
client.stop();
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
delay(50);
bStartEnabled=digitalRead(2);
if(bStartEnabled)
{
if (client.connect(serverIP, serverPort)) {
Serial.println("Connected");//report it to the Serial
Serial.println("Load Parameters 1 ");//log to serial
client.write(abyLoadParameter1, 9);//send the message
delay(1000);
Serial.println("Sending START Message ");//log to serial
client.write(abyStartReceiver, 8);//send the message
bStartEnabled=false;
}
else {
// if you didn't get a connection to the server:
Serial.println("connection failed");
client.stop();
}
}
if (client.available()) {
char c = client.read();
Serial.print(c, HEX);
}
}
As I said the skrech itself is straightforward, during the setup opens a socket and send Load Parameter 1 and Start Receiver commands.
If something happens during execution, through D2 is possible to re-inizialite the ext. device.
NB. Library Newping is inserted but never used...
Everything works nice, the only problem is the receiving buffer, this is beyond the functionalities I need for this project but still I would like to understand what is happening.
Thank you.