Error with buffer

I’m getting errors pertaining to the initialization of arrays. It’s a super simple mistake but I just can’t figure it out. I’m measuring a sensor port and putting that value into the buffer, sleep, and repeat.

error: initializer fails to determine size of ‘data’. and error: call of overloaded ‘println(int [1])’ is ambiguous.

// EXAMPLE USAGE
int sensor1 = A1;
int sensorV = 0;
char sensorStr[64];
int data [10000];   //*


TCPClient client;
byte server[] = { 192,168,2,9 }; // IP address


void setup()
{
  // Make sure your Serial Terminal app is closed before powering your device
  Serial.begin(9600);
  // Now open your Serial Terminal, and hit any key to continue!
 pinMode(sensor1, INPUT);
 //Particle.variable("sensorV", sensorStr);
 
 
  while(!Serial.available()) Particle.process();

  Serial.println("connecting...");

  if (client.connect(server, 6780))
  {
    Serial.println("connected");
    client.println("HELLO2");
  }
  else
  {
    Serial.println("connection failed");
  }

}

void loop()
{
    
 // Sleep 1 sec
 // byte[] data = sensor.read();
 // client.println(data);
 
 int data [] = analogRead(sensor1);  //*
 client.println(data);
 delay(2);
 

  if (client.available())
  {
    char c = client.read();
    Serial.print(c);
    
     //sensorV = analogRead(sensor1);
     //snprintf(sensorStr, sizeof(sensorStr), "%d", sensorV);
     //client.println(sensorStr);
  }

  if (!client.connected())
  {
    Serial.println("disconnecting.");
    client.stop();
    //server_connect();
    
  
  }
}

I don’t think this statement does what you want to do. You are declaring a new variable with local scope in the loop function that shadows the global with the same name and you are not specifying the length of the array.

1 Like