OneWire device address to String


can someone tell me how i can put the device address into a string instead of doing a serial.print ?

void printAddress(DeviceAddress deviceAddress)
  for (uint8_t i = 0; i < 8; i++)
    // zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);

Thanks in advance

Just off the top of me head…

char *addr2str(DeviceAddress deviceAddress)
     static char return_me[18];
     static char *hex = "0123456789ABCDEF";
     uint8_t i, j;

     for (i=0, j=0; i<8; i++) 
          return_me[j++] = hex[deviceAddress[i] / 16];
          return_me[j++] = hex[deviceAddress[i] & 15];
     return_me[j] = '\0';

     return (return_me);

The programmer does need to make a copy of the string
returned before calling this function again.

It compiles so I’ll leave it up to the reader to make it run correctly! :slight_smile: