I tried the code but the broadcast response is now blank? I can see the broadcast packet but it is empty?
Full code:
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
// Attempt to automatically configure everything. Set a default MAC
// address to be replaced later, and get the IP address from DHCP
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // Try to replace with DS MAC
//udp port
unsigned int localPort = 8888;
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
EthernetUDP Udp;
//setup pins for leds and relays and switches
// Initialise a DS18B20 temperature sensor
OneWire ds(9); // Set up DS18B20 sensor on pin D9
IPAddress UDPServer(255, 255, 255, 255); // destination device server
/***********************************************************************
******************************* Setup **********************************
***********************************************************************/
void setup()
{
byte dsAddress[8];
delay( 500 ); // Give the Ethernet chipset time to fully initialise
ds.reset_search(); // Start the search with the first device
// Offset array to skip DS18B20 family code, and skip mac[0]
mac[1] = dsAddress[3];
mac[2] = dsAddress[4];
mac[3] = dsAddress[5];
mac[4] = dsAddress[6];
mac[5] = dsAddress[7];
Ethernet.begin( mac ); // mac address is derived fomr the DS18B20 chip address.
Udp.begin(localPort);
delay(200); // delay to allow the ethernet to setup
Udp.beginPacket(UDPServer,(8888));
Udp.print("I am Awake");
Udp.endPacket();
}
/***********************************************************************
******************************* LOOP ***********************************
***********************************************************************/
void loop()
{
byte sendBuffer[3] = {0x00,0x01,0x02};
Udp.beginPacket(UDPServer,(8888));
Udp.write(sendBuffer,3);
Udp.endPacket();
delay(2000);
}
MAC - to derive a different Mac for each device without having to re-code each one i use the 1 wire device to provide a unique address - I then use the second portion of this for the MAC address.
(parentheses) - the example I used to derive the code used the parentheses and I left them in, no error was returned to my Udp.print statements in testing which worked as expected without error - I have now removed them and started a retest - it made no difference to the outcome.
I am using a multicast testing app on android to see the packets on the network - the app shows a packet is received but it has no content (Response was a poor wording - my mistake) I believe this to be an empty packet?
The App has a setting to 'Receive in Hexadecimal' which then displays the Hex rather than the Ascii, I've asked the developer if the app has a limitation in terms of received addresses.
I don't have an app for android. Why don't you set up the 2nd Arduino as the receiver? I use a RPi as the test device. I have C code for testing UDP on it.
Ok.. So,
Having spoken to the developer of the testing app there is a bug that shows the wrong ASCII codes / no codes at all... this has now been fixed and an update released
and with help from this thread I'm passing the correct bytes into the write statement and all is working as expected