You didn't follow my instructions. I didn't say anything about EthernetUDP2. I said:
pert:
I forgot to say that you need to move the line:EthernetUDP Udp;// To send & receive packets using UDPabove setup().
Like this:
#include <SPI.h>
#include <Ethernet2.h>
#include <EthernetUdp2.h>
//#include <Udp.h>
#include <EthernetUdp2.cpp>
// ------------------------------------------------------------------
// Configuration
// The mac address is the physical address associated with the
// Ethernet port on the your device. It should be globally unique if
// the board is connected to a public network, or at least locally
// unique if the board is connected to a private network.
byte MacAddress[] = { 0x90, 0xA2, 0xDA, 0x10, 0xA3, 0x4F };
//byte MacAddress[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// The IP address is the internet protocol address for the board. Again
// it should be globally unique if connected to a public network or
// locally unique if connected to a private network. To communicate
// successfully, it should also be on the same sub-net as your PC.
// In practice that means the first three numbers should be the same
// as your PC's IP address. And the last number should be different to
// all devices on your network. Use ipconfig to find out your PC's IP address
IPAddress MyIPAddress(192, 168, 1, 165);
unsigned int LocalPort = 8888; //what would a port for the uno be?
// The destination address is the IP address of the computer you want to send
// messages to. It would normally be on the same sub-net as the Arduino. In practice
// this means the first three numbers of MyIPAddress and DestinationAddress should
// be the same.
IPAddress DestinationAddress(169, 254, 1, 1);
unsigned int DestinationPort = 1701;
//EthernetUDP2 = Ethernet2Udp;
// ------------------------------------------------------------------
// Setup
EthernetUDP Udp;// To send & receive packets using UDP
void setup()
{
// Start ethernet and udp
Ethernet.begin(MacAddress, MyIPAddress);
Udp.begin(LocalPort);
// Start RS232 comms
Serial.begin(9600);
}
// ------------------------------------------------------------------
// Communications
char PacketBuffer[UDP_TX_PACKET_MAX_SIZE]; // Space to hold messages we receive.
unsigned long LastSend = 0; // Last time we sent a message
const long SendPeriod = 1000; // Time between sending messages [milliseconds]
// ------------------------------------------------------------------
// Data
bool EnableADCSend[] = { true, false, false, false, false, false, false, false };
// This Code will get changed when I can compile the code
// ------------------------------------------------------------------
// Functions
void ProcessUDPTraffic()
{
// See if there is any data available and read it.
int nPacketSize = Udp.parsePacket();
if (nPacketSize > 0)
{
int nRead = Udp.read(PacketBuffer, sizeof(PacketBuffer));
if (nRead >= 1)
{
int nPort = PacketBuffer[0] - '0';
if (nPort >= 0 && nPort < sizeof(EnableADCSend))
{
// Toggle sending data from the specified port.
EnableADCSend[nPort] = !EnableADCSend[nPort];
Serial.print("Sending adc data for channel ");
Serial.print(nPort);
Serial.print(" is ");
Serial.println(EnableADCSend[nPort] ? "on" : "off");
}
}
}
}
void SendADCData()
{
if (millis() - LastSend < SendPeriod)
return;
LastSend = millis();
for (int iPort = 0; iPort < sizeof(EnableADCSend); ++iPort)
{
if (EnableADCSend[iPort])
{
int nValue = analogRead(iPort);
Udp.beginPacket(DestinationAddress, DestinationPort);
Udp.send(81, DestinationAddress, DestinationPort ); // the message to send to get BV
Udp.send(01, DestinationAddress, DestinationPort ); //
Udp.send(02, DestinationAddress, DestinationPort ); //
Udp.send(7B, DestinationAddress, DestinationPort ); // The 7B gives a error too, needs fixing
Udp.endPacket();
}
}
}
RS_:
you said that Udp.send() errors would be next. and you said is not valid, is this now Udp.write ...? That I saw in a Udp reference some where during my research...
I'm not aware of any analog to this Udp.send(). I'm not sure where you dug that up. As I said before:
pert:
I recommend you to start with File > Examples > Ethernet2 > UDPSendReceiveString, the associated tutorial:
https://www.arduino.cc/en/Tutorial/UDPSendReceiveString
and the library reference:
Ethernet - Arduino Reference
Note that you send UDP packets in a three part process. First Udp.beginPacket(), then Udp.write(), then Udp.endPacket().
If you study the example code and the reference pages for Udp.beginPacket(), then Udp.write(), then Udp.endPacket() you'll understand.
RS_:
UDPSendReceiveString:
It seems you're using either a very outdated or a modified version of the Ethernet2 library. Please provide a link to where you got that library from. Since it's modified, I suppose there is a chance it does have a Udp.send() function. I'd need to look at the library to see.