//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
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.
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()
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()