Error assigning hex address array

This line:

 allSensors[0].address={0x28, 0x26, 0xAE, 0xEB, 0x03, 0x00, 0x00, 0xB2};

Generates this error:

ThingSpeak:104: error: expected primary-expression before '{' token
ThingSpeak:104: error: expected `;' before '{' token

The context is this code (Note that the first line thirdFloorAddress works. Why?):

DeviceAddress thirdFloorAddress = { 
  0x28, 0x88, 0xCD, 0xEB, 0x03, 0x00, 0x00, 0xA2}; // 

class Sensor_Specification {
  public:
    DeviceAddress address;
    String  addressString;
    String location;
    int updateInterval;//in milliseconds
    int pin;
    String channel;
    int field;
    float currentTemp;
    float recentTemps[5];
    float averageTemp;} ;
Sensor_Specification allSensors[12];
  
// Local Network Settings
byte mac[] = { 
  0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network


// Initialize Arduino Ethernet Client
EthernetClient client;

void setup()
{
  // Start Serial for debugging on the Serial Monitor
  Serial.begin(9600);


  //Fill allSensors array
  allSensors[0].location="1st Floor";
  allSensors[0].channel="House Temperatures";
  allSensors[0].field=1;
  allSensors[0].addressString="2826AEEB030000B2";
  allSensors[0].address={0x28, 0x26, 0xAE, 0xEB, 0x03, 0x00, 0x00, 0xB2};
  allSensors[0].pin=11;
  allSensors[0].updateInterval=600000;
...

‘address’ can only be assigned that way while initializing during its declaration.

You’d probably be better off using ‘memcpy’ instead.

Thanks again for your reply.

why can 'address' only be assigned that way while initializing during its declaration? Given the complexity of the Sensor_Specifications class, how can I make the assignment during declaration? I'm unsure about syntax.

How can it be assigned later? Do I need to convert the hexidecimal to integers?

Reading about memcpy, it sounds dangerous, that I could overwrite without being aware.

Due to language specification.

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

struct Sensor_Specification
{
    DeviceAddress   address;
    String          addressString;
    String          location;
    unsigned long   updateInterval;     // NOTE: YOU ATTEMPT TO PLACE A LONG INTEGER INTO A SPACE OF ONTGER
    int             pin;
    String          channel;
    int             field;
    float           currentTemp;
    float           recentTemps[5];
    float           averageTemp;
};

Sensor_Specification allSensors[] =
{
      { { 0x28, 0x26, 0xAE, 0xEB, 0x03, 0x00, 0x00, 0xB2 }, "2826AEEB030000B2", "1st Floor", 600000UL, 11, "House Temperatures", 1, ... }
    , { ... }
};

Thanks, lloyd! It worked!

I'll read about struct.

Please explain:

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

To work out the number of elements in an array at run time 2 things must be known.

  1. The total number of bytes used by the array. This is returned by the sizeof() function with the array as the parameter.
  2. The size of each array element. This is returned by the sizeof() function with the first element of the array as the parameter.

Dividing one by the other gives the number of elements in the array.