-->
Page 1 of 1

Error compiling at the command client.write

PostPosted: Fri Jan 08, 2016 11:40 am
by piyush95
In a part of my code i am using the following command
Code: Select allbyte Debug[7] = {0xAB, 0x0D, 0x30, 0x01, 0x33, 0x00, 0x00};
//Debug[6] is the main debug packet
byte message = 0x00; // this variable will be for the last byte of Debug array
double timeout=300000;
double CurrentTime,LastTime;
  while (client.connected())//See if client is connected to server
  {
    //******************************************
    //**SEND DATA TO SERVER
    while (Serial.available())
   {
      LastTime = millis();
      if (message & 0x80)
      {
        Serial.println("DATA Received..clearing the error");
        message = 0x00;
        Debug[6] = message;
       client.write(Debug, sizeof(Debug));
        Serial.write(Debug, sizeof(Debug));
      }
      for (i = 0; i < 7; i++)
      {

        ns[i] = Serial.read();

        if (ns[i] != -1)
        {
          delay(100);
        }
      }
      client.print(ns);
      Serial.println(ns);
    }
    //after all the data that was in the serial buffer is sent, check if there is anythng that the server responds

    //*************************************************
    // DEBUG MESSAGE FORMATION
    CurrentTime = millis();
    if (CurrentTime - LastTime >= timeout)
    {
      // No data received from Receiver in last 5 minutes
      //change bit number 3 ie 4th bit from the right.
      message |= 0x08;
      Debug[6] = message;
      Serial.println("Sending Debug Message: No data for 5 min");     
      client.write(Debug, sizeof(Debug));
      Serial.write(Debug, sizeof(Debug));
    }
}


The above code is a part of a code that i am developing for communicating with a TCP server over port 40000.
The arduino IDE shows en error compiling message possibly due to the <code>client.write()</code> statement. However the function is described as having two possible arguments- the buffer ie the array and the size of the array. I have to use <code>client.write()</code> because i need to send 7 bytes in HEX. in order to avoid this kind of an error, i had converted my ns[] into a char type array and used client.print() instead ,but i'm afraid i can'y do the same this time.

The error shown is:

In file included from C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/ESP8266WiFi.h:32:0,
from ESP_Wifi.ino:3:
C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/WiFiClient.h: In instantiation of 'size_t WiFiClient::write(T&) [with T = unsigned char [7]; size_t = unsigned int]':
ESP_Wifi.ino:85:27: required from here
C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/WiFiClient.h:78:28: error: request for member 'available' in 'src', which is of non-class type 'unsigned char [7]'
while (src.available() > WIFICLIENT_MAX_PACKET_SIZE){
^
C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/WiFiClient.h:79:7: error: request for member 'read' in 'src', which is of non-class type 'unsigned char [7]'
src.read(obuf, WIFICLIENT_MAX_PACKET_SIZE);
^
C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/WiFiClient.h:87:38: error: request for member 'available' in 'src', which is of non-class type 'unsigned char [7]'
uint16_t leftLen = src.available();
^
C:\Users\Piyush\AppData\Roaming\Arduino15\packages\esp8266\hardware\esp8266\2.0.0\libraries\ESP8266WiFi\src/WiFiClient.h:88:5: error: request for member 'read' in 'src', which is of non-class type 'unsigned char [7]'
src.read(obuf, leftLen);
^
Error compiling.


Also if there is any other way of sending 6-7 HEX bytes at once to the ESP or to the client please mention.

Re: Error compiling at the command client.write

PostPosted: Fri Jan 08, 2016 5:13 pm
by martinayotte
Since client.write() is using templates, passing the whole Debug confuse the compiler, you need to provide address of the first byte :

Code: Select all        client.write(&Debug[0], sizeof(Debug));

Re: Error compiling at the command client.write

PostPosted: Mon Mar 28, 2016 9:24 am
by ravi
if i use "client.write(&Debug[0], sizeof(Debug));" it will send only once to server , what should i do so that data can be sent continuously

Re: Error compiling at the command client.write

PostPosted: Mon Mar 28, 2016 11:27 am
by martinayotte
ravi wrote:what should i do so that data can be sent continuously

What do you means by "continously" ?
Simply do it in a infinite loop ? ...