A function-definition is not allowed here

//char outgoingDataChannel0[STD_BUFFER_SIZE]; defined on main page
//bool outgoingDataValidChannel0 = false;     defined on main page

void dataTX() {  //acting as a client
//NOTE: This procedure needs to come after dataRX()

  Serial.println("entering dataTX.ino");

 // Clear the outgoingData array on startup
  if (firstCycleMarker) { 
    memset(outgoingData, 0, STD_BUFFER_SIZE);
  } //if (firstCycleMarker)

//create a reject procedure here, send -1 to the sender
  if (incomingRejectDataValid) {
    wifiClient.print("-1  "); //push rejection code
    wifiClient.print(incomingChannel);  //push channel being rejected
    /*Print data to the server that a client is connected to. Prints numbers 
      as a sequence of digits, each an ASCII character (e.g. the number 123 is 
      sent as the three characters ‘1’, ‘2’, ‘3’).
      Syntax
        client.print(data)
        client.print(data, BASE)
      Parameters
        data: the data to print (char, byte, int, long, or string)
        BASE (optional): the base in which to print numbers:, DEC for decimal (base 10), 
        OCT for octal (base 8), HEX for hexadecimal (base 16).
      Returns
        byte : returns the number of bytes written, though reading that number is optional
      */
  } // (incomingRejectDataValid)

  /*This code does not know, or care, what any of the data coming through means, or if it's
    correct or not. It simply transmits the data given to it while identifying the channel 
    it comes from and adds an EOT at the end */
  if (outgoingDataValidChannel0) {
    wifiClient.print("0  ");
    wifiClient.println(outgoingDataChannel0); //push outgoing data
  } //if (outgoingDataValidChannel0)
  if (outgoingDataValidChannel1) {
    wifiClient.print("1  ");
    wifiClient.println(outgoingDataChannel1); //push outgoing data
  } //if (outgoingDataValidChannel1)
  if (outgoingDataValidChannel2) {
    wifiClient.print("2  ");
    wifiClient.println(outgoingDataChannel2); //push outgoing data
  }//if (outgoingDataValidChannel2)
  if (outgoingDataValidChannel3) {
    wifiClient.print("3  ");
    wifiClient.println(outgoingDataChannel3); //push outgoing data
  } //if (outgoingDataValidChannel3)
  
  Serial.println("leaving dataTX.ino");
} //void dataTX()


dataTX.ino:8:15: error: a function-definition is not allowed here before '{' token
void dataTX() { //acting as a client

void dataTX() is prototyped on the main page.
If I take out the 'void' in front of dataTX() on this page, where it is defined, instead I get;

error: expected ';' before '{' token
dataTX() { //acting as a client

What am I getting wrong?

Your problem is happening somewhere above the code snippet that you posted. The void dataTX() { //acting as a client line is just the innocent victim. It's impossible to say more without seeing the rest of the code.

What do you mean by this ?

Where is firstCycleMarker declared ?

#include <WiFiNINA.h>
#include <WiFiServer.h>
#include <WiFiClient.h>
#include <string.h>

#define clientPort 8080
#define serverPort 8081
#define STD_BUFFER_SIZE 0xFF

char incomingDataChannel0[STD_BUFFER_SIZE];
char incomingDataChannel0Pointer = &incomingDataChannel0[0];
bool incomingDataValidChannel0 = false;
char incomingDataChannel1[STD_BUFFER_SIZE];
bool incomingDataValidChannel1 = false;
char incomingDataChannel2[STD_BUFFER_SIZE];
bool incomingDataValidChannel2 = false;
char incomingDataChannel3[STD_BUFFER_SIZE];
bool incomingDataValidChannel3 = false;


char outgoingDataChannel0[STD_BUFFER_SIZE];
bool outgoingDataValidChannel0 = false;
char outgoingDataChannel1[STD_BUFFER_SIZE];
bool outgoingDataValidChannel1 = false;
char outgoingDataChannel2[STD_BUFFER_SIZE];
bool outgoingDataValidChannel2 = false;
char outgoingDataChannel3[STD_BUFFER_SIZE];
bool outgoingDataValidChannel3 = false;


char ssid = "";
char wifiPassword = "";
char EOT = 0x0D;
bool firstCycleMarker = true;
byte rejectChannel = 0;

void clientConnect();
void serverConnect();
void IP_Services();
void dataRX();
void dataTX();

WiFiClient wifiClient(clientPort);
WiFiServer wifiServer(serverPort);

bool isOdd(byte isOddFirstByte) {
  return (isOddFirstByte & 1) != 0; //performs an AND function (effectively an XNOR) between
}                                   //isOddFirstByte and 1, an odd input generates true   
bool recReject = false;


void setup() {
  Serial.begin(9600);
  Serial.println("Bard_Socket.ino");

  clientConnect();
  serverConnect();
  IP_Services();

  
  if(firstCycleMarker) firstCycleMarker = false;
}

void loop() {

  dataRX();
  dataTX();
  exit(0);

}

char incomingTransferData[STD_BUFFER_SIZE];
char incomingRejectData[STD_BUFFER_SIZE];
bool incomingDataTransferComplete = false; // Flag to indicate transfer completion
bool incomingDataTransferInProcess = false;
bool incomingRejectDataValid = false;
int incomingTransferDataIndex = 0;
int incomingTransferDataSize = 0;
byte incomingChannel = 0;



void dataRX() { // Acting as a client, data coming in

  Serial.println("entering dataRX.ino");
    
    if (!incomingDataTransferInProcess && wifiClient.available() && (wifiClient.peek() == EOT)) {
      /*Client.available() Returns the number of bytes available for reading (that is, the 
      amount of data that has been written to the client by the server it is connected to).
        .available() inherits from the Stream utility class.
      Syntax
        client.available()
      Parameters
        None
      Returns
        The number of bytes available. */
      /* Client.peek(): Read a byte from the file without advancing to the next one. 
      That is, successive calls to peek() will return the same value, as will the next call to read().
      This function inherited from the Stream class. See the Stream class main page for more information.
      Syntax
        client.peek()
      Parameters
        None
      Returns
        b: the next byte or character
        -1: if none is available
      */
                  wifiClient.read(); //dump incoming buffer and quit
    } else {  //if (!incomingDataTransferInProcess && wifiClient.available() && wifiClient.peek() == EOT)
    
        if (wifiClient.available()&& !incomingDataTransferInProcess){  //find the incomingChannel
          incomingDataTransferInProcess = true;
          incomingChannel = wifiClient.read(); //read() the first byte
          incomingTransferDataIndex = 1;
        } //if (wifiClient.available()&& !incomingDataTransferInProcess)

        incomingTransferDataSize = incomingTransferDataSize + wifiClient.available();
    
        wifiClient.read(&incomingTransferData[0], incomingTransferDataSize);
        /*  Client.read()reads data from the client. If no arguments are given, 
          it will return the next character in the buffer.
          Syntax
            client.read()
            client.read(buffer, size);
          Parameters
            buffer: buffer to hold incoming packets (char*)
            len: maximum size of the buffer (int)
          Returns
            b: the next character in the buffer (char)
            size: the size of the data
            -1: if no data is available

          The ( & ) operator gets the address of a variable in memory. 
            It returns a pointer to the variable's location.
          The ( * ) operator dereferences the pointer and accesses the 
            value stored at the memory location it points to.
        */
        if (incomingTransferData[incomingTransferDataIndex] == EOT) { //if the last character is EOT

        if (0 <= incomingChannel <= 3) {
          if (incomingChannel = 0) { 
            //if (*(&wifiClient.peek() + incomingDataTransferSize) == EOT) {
            //incomingDataChannel0[0] = incomingTransferData;
            memcpy(incomingDataChannel0, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel0 = true; //false is defined at the user
          } //if (incomingChannel = 0)

          if (incomingChannel = 1) { 
          memcpy(incomingDataChannel1, incomingTransferData, sizeof(incomingTransferData));
          incomingDataValidChannel1 = true; //false is defined at the user
          } //if (incomingChannel = 1)

          if (incomingChannel = 2) { 
            memcpy(incomingDataChannel2, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel2 = true; //false is defined at the user
          } //if (incomingChannel = 2)

          if (incomingChannel = 3) { 
            memcpy(incomingDataChannel3, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel3 = true; //false is defined at the user
          } //if (incomingChannel = 3)

        } else {//if (0 <= incomingChannel <= 3)
            memcpy(incomingRejectData, incomingTransferData, sizeof(incomingTransferData));
            incomingRejectDataValid = true; //false is defined at the user
            rejectChannel = incomingChannel;
          } //else

        incomingTransferDataIndex = incomingTransferDataIndex + incomingTransferDataSize;

      } //else if (!incomingDataTransferInProcess && wifiClient.available() && wifiClient.peek() == EOT)

} //void dataRX()

Which board are you compiling for ?

Arduino Uno WiFi rev 2

You have a missing closing bracket at the end of dataRX(). That put the line void dataTX() { inside dataRX(), and the compiler complained. Add the closing bracket shown below and see how it goes from there.

char incomingTransferData[STD_BUFFER_SIZE];
char incomingRejectData[STD_BUFFER_SIZE];
bool incomingDataTransferComplete = false; // Flag to indicate transfer completion
bool incomingDataTransferInProcess = false;
bool incomingRejectDataValid = false;
int incomingTransferDataIndex = 0;
int incomingTransferDataSize = 0;
byte incomingChannel = 0;



void dataRX() { // Acting as a client, data coming in

  Serial.println("entering dataRX.ino");
    
    if (!incomingDataTransferInProcess && wifiClient.available() && (wifiClient.peek() == EOT)) {
      /*Client.available() Returns the number of bytes available for reading (that is, the 
      amount of data that has been written to the client by the server it is connected to).
        .available() inherits from the Stream utility class.
      Syntax
        client.available()
      Parameters
        None
      Returns
        The number of bytes available. */
      /* Client.peek(): Read a byte from the file without advancing to the next one. 
      That is, successive calls to peek() will return the same value, as will the next call to read().
      This function inherited from the Stream class. See the Stream class main page for more information.
      Syntax
        client.peek()
      Parameters
        None
      Returns
        b: the next byte or character
        -1: if none is available
      */
                  wifiClient.read(); //dump incoming buffer and quit
    } else {  //if (!incomingDataTransferInProcess && wifiClient.available() && wifiClient.peek() == EOT)
    
        if (wifiClient.available()&& !incomingDataTransferInProcess){  //find the incomingChannel
          incomingDataTransferInProcess = true;
          incomingChannel = wifiClient.read(); //read() the first byte
          incomingTransferDataIndex = 1;
        } //if (wifiClient.available()&& !incomingDataTransferInProcess)

        incomingTransferDataSize = incomingTransferDataSize + wifiClient.available();
    
        wifiClient.read(&incomingTransferData[0], incomingTransferDataSize);
        /*  Client.read()reads data from the client. If no arguments are given, 
          it will return the next character in the buffer.
          Syntax
            client.read()
            client.read(buffer, size);
          Parameters
            buffer: buffer to hold incoming packets (char*)
            len: maximum size of the buffer (int)
          Returns
            b: the next character in the buffer (char)
            size: the size of the data
            -1: if no data is available

          The ( & ) operator gets the address of a variable in memory. 
            It returns a pointer to the variable's location.
          The ( * ) operator dereferences the pointer and accesses the 
            value stored at the memory location it points to.
        */
        if (incomingTransferData[incomingTransferDataIndex] == EOT) { //if the last character is EOT

        if (0 <= incomingChannel <= 3) {
          if (incomingChannel = 0) { 
            //if (*(&wifiClient.peek() + incomingDataTransferSize) == EOT) {
            //incomingDataChannel0[0] = incomingTransferData;
            memcpy(incomingDataChannel0, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel0 = true; //false is defined at the user
          } //if (incomingChannel = 0)

          if (incomingChannel = 1) { 
          memcpy(incomingDataChannel1, incomingTransferData, sizeof(incomingTransferData));
          incomingDataValidChannel1 = true; //false is defined at the user
          } //if (incomingChannel = 1)

          if (incomingChannel = 2) { 
            memcpy(incomingDataChannel2, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel2 = true; //false is defined at the user
          } //if (incomingChannel = 2)

          if (incomingChannel = 3) { 
            memcpy(incomingDataChannel3, incomingTransferData, sizeof(incomingTransferData));
            incomingDataValidChannel3 = true; //false is defined at the user
          } //if (incomingChannel = 3)

        } else {//if (0 <= incomingChannel <= 3)
            memcpy(incomingRejectData, incomingTransferData, sizeof(incomingTransferData));
            incomingRejectDataValid = true; //false is defined at the user
            rejectChannel = incomingChannel;
          } //else

        incomingTransferDataIndex = incomingTransferDataIndex + incomingTransferDataSize;

      } //else if (!incomingDataTransferInProcess && wifiClient.available() && wifiClient.peek() == EOT)
   } // <--- this is the missing closing bracket
} //void dataRX()

You were right. The problem was on the previous page.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.