-->
Page 1 of 2

Latest Staging Sprintf

PostPosted: Sun Nov 22, 2015 12:22 pm
by danbicks
Hi Guys,

Seems like the latest staging has a problem with Sprintf

Igrr are you aware of this.

Dans

Re: Latest Staging Sprintf

PostPosted: Sun Nov 22, 2015 12:57 pm
by martinayotte
What kind of problems ?
Because the sprintf in libc_replacements.c is quite simple and simply redirect it to ets_vsprintf() of the Espressif SDK.
Also, I've almost the latest version and don't have any problems.

Re: Latest Staging Sprintf

PostPosted: Sun Nov 22, 2015 2:51 pm
by danbicks
martinayotte wrote:What kind of problems ?
Because the sprintf in libc_replacements.c is quite simple and simply redirect it to ets_vsprintf() of the Espressif SDK.
Also, I've almost the latest version and don't have any problems.


Hi Martin,

I have errors with several projects that work perfect in older version before staging, these seem to be all string errors.
Sprintf throws an error and so does strcmp.

error:

NET_MOD.ino: In function 'int32_t getRSSI(const char*)':
NET_MOD:13: error: cannot convert 'String' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'
cannot convert 'String' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'

Code: Select allint32_t getRSSI(const char* target_ssid) {
  byte available_networks = WiFi.scanNetworks();

  for (int network = 0; network < available_networks; network++) {
    if (strcmp(WiFi.SSID(network), target_ssid) == 0) {
      return WiFi.RSSI(network);
    }
  }
  return 0;
}


The above routine works perfect in my ESP_T_TRACKER project posted on this forum, any ideas why they now error?

Cheers

Dans

Re: Latest Staging Sprintf

PostPosted: Sun Nov 22, 2015 3:29 pm
by martinayotte
Hi Dans,
But this is completely different issue than the sprintf() problems you've mentioned.
Also, the String class always been like that even for AVR, not only ESP.
The String class doesn't provide implicit conversion to "const char *".
To use String class with strcmp() for example, you need to do explicit conversion with c_str() such as :
Code: Select all    if (strcmp(WiFi.SSID(network).c_str(), target_ssid) == 0) {