[Resolved, thanks] Why doesn't this hex 1 wire address comparison evaluate true?

Why doesn’t this hex 1 wire address comparison evaluate true?

if (tempDeviceAddress==thirdFloorAddress) Serial.print(" MATCH ");

I’m trying to match sensors to their addresses. Heres’ the result It should say on the 8th line"2888CDEB030000A2 third floor MATCH" :

Arduino connected to network using DHCP

Connecting Arduino to network...

Arduino connected to network using DHCP

Locating devices...Found 6 devices.
Parasite power is: OFF
Found device 0 with address: 
2888CDEB030000A2 third floor 
Setting resolution to 12
Resolution actually set to: 12
Found device 1 with address: 
2888CDEB030000A2 third floor 
Setting resolution to 12
Resolution actually set to: 12

Hers’s the code, note the DeviceAddress thirdFloorAddress variable:

#include <SPI.h>
#include <Ethernet.h>

//Dallas 1 wire stuff
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 11 on the Arduino
#define ONE_WIRE_BUS 11
// 9 to 12 bit precision
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);
int numberOfDevices; // Number of temperature devices found
DeviceAddress tempDeviceAddress; // We'll use this variable to store a found device address
DeviceAddress thirdFloorAddress = { 
  0x28, 0x88, 0xCD, 0xEB, 0x03, 0x00, 0x00, 0xA2}; // 

// Local Network Settings
byte mac[] = { 
  0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak Settings
char thingSpeakAddress[] = "api.thingspeak.com";
String writeAPIKey = "KEY HERE";
const int updateThingSpeakInterval = 15 * 1000;      // Time interval in milliseconds to update ThingSpeak (number of seconds * 1000 = interval)

// Variable Setup
long lastConnectionTime = 0; 
boolean lastConnected = false;
int failedCounter = 0;

// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()
  // Start Serial for debugging on the Serial Monitor

  // Start Ethernet on Arduino
  // Start up the library

  // Grab a count of devices on the wire
  numberOfDevices = sensors.getDeviceCount();

  // locate devices on the bus
  Serial.print("Locating devices...");

  Serial.print("Found ");
  Serial.print(numberOfDevices, DEC);
  Serial.println(" devices.");

  // report parasite power requirements
  Serial.print("Parasite power is: "); 
  if (sensors.isParasitePowerMode()) Serial.println("ON");
  else Serial.println("OFF");

  // Loop through each device, print out address
  for(int i=0;i<numberOfDevices; i++)
    // Search the wire for address
    if(sensors.getAddress(tempDeviceAddress, i))
      Serial.print("Found device ");
      Serial.print(i, DEC);
      Serial.print(" with address: ");
      Serial.print(" third floor ");
      if (tempDeviceAddress==thirdFloorAddress) Serial.print(" MATCH ");
      Serial.print("Setting resolution to ");
      Serial.println(TEMPERATURE_PRECISION, DEC);

      // set the resolution to TEMPERATURE_PRECISION bit (Each Dallas/Maxim device is capable of several different resolutions)
      sensors.setResolution(tempDeviceAddress, TEMPERATURE_PRECISION);

      Serial.print("Resolution actually set to: ");
      Serial.print(sensors.getResolution(tempDeviceAddress), DEC); 
      Serial.print("Found ghost device at ");
      Serial.print(i, DEC);
      Serial.print(" but could not detect address. Check power and cabling");

Because it is a pointer, all arrays are. You are trying to compare two pointers thinking you are comparing their values. You need to compare the elements of the arrays of bytes to see if they are identical.

The printAddress function is likely doing the array looping for you to print out the values.

You need to put this in an inline function or something like it.

inline bool compareAddresses(byte *addr1, byte *addr2, len)
  for (i = 0; i < len; i++)
    if (addr1[i] != addr2[i])
       return false;
  return true;

// Then call instead of:
// if (tempDeviceAddress == thirdFloorAddress)
// do this:
if (compareAddresses(tempDeviceAddress, thirdFloorAddress, sizeof(thirdFloorAddress)))
   // ....

If this fixes it for you, please update subject with [RESOLVED] tag or similar in front to be considerate of the time of others interested in assisting.

Thanks, exedor.

Can I somehow use string.compare for this?

#define A_SIZEOF(ARRAY)    (sizeof(ARRAY) / sizeof(ARRAY[0]))

uint8_t    array1[] = { 0, 1, 2, 3, 4 };
uint8_t    array2[] = { 0, 1, 2, 3, 4 };

void loop()

void setup()
    if (    (A_SIZEOF(array1) == A_SIZEOF(array2))
         && (0 == memcmp(array1, array2, A_SIZEOF(array1))) )

Interesting, didn't think memcmp was available on the Arduino. Last time I tried to use it I ran into lots of problems. If it is there and it works for you, use that instead...it's better.

Awesome, lloyddean!

2888CDEB030000A2 third floor  MATCH 

if (0 == memcmp(tempDeviceAddress, thirdFloorAddress, 8))  Serial.print(" MATCH ");

‘compareAddresses’ could duplicate the functionalluty of ‘memcpy’ if implementted something like -

int memcmp(const void* lhs, const void* rhs, size_t len)
    const uint8_t* _lhs = (uint8_t*)lhs;
    const uint8_t* _rhs = (uint8_t*)rhs;
    for ( size_t i = 0; i < len; i++ )
        uint8_t t = _lhs++ - _rhs++;
        if ( 0 != t )
            return (t < 0) ? -1 : 1;

    return 0;