Use of arduino StringObject?

The line:

String testValue = String(millis(),DEC);

works fine on an Arduino, but not on the core, I get the following error on verify:

../xxx/the_user_app.cpp: In function 'void setup()':
../xxx/the_user_app.cpp:63:43: error: call of overloaded 'String(uint32_t, int)' is ambiguous
../xxx/the_user_app.cpp:63:43: note: candidates are:
In file included from ../inc/spark_utilities.h:31:0,
from ../inc/spark_wiring.h:31,
from ../inc/application.h:29,
from ../xxx/the_user_app.cpp:2:
../inc/spark_wiring_string.h:78:14: note: String::String(double, int)
../inc/spark_wiring_string.h:77:14: note: String::String(float, int)
../inc/spark_wiring_string.h:76:11: note: String::String(long unsigned int, unsigned char)
../inc/spark_wiring_string.h:75:11: note: String::String(long int, unsigned char)
../inc/spark_wiring_string.h:74:11: note: String::String(unsigned int, unsigned char)
../inc/spark_wiring_string.h:73:11: note: String::String(int, unsigned char)
../inc/spark_wiring_string.h:72:11: note: String::String(unsigned char, unsigned char)

Any ideas? My ultimate aim is to convert millis() (an unsigned long) to string.

Hey @dermotos,

I think there is a bug with our compiler that is making the syntax a little awkward–we’ll work to improve it to make the experience more like the standard Arduino IDE. In the meantime, I’m seeing the code compile in my IDE by adding (unsigned char) in front of DEC, as in

String testValue = String(millis(),(unsigned char)DEC);

Let me know if this works for you!

also this lines compiles in Arduino IDE but fails on the Core

String testString=“defd”;
String domain=“https://someApi.com/”+testString;

    ../4b7afec1a7ff16d6558a1426739ef992ca03411e8c9cf2a64b09c524fcde/the_user_app.cpp:33:15: error: missing terminating " character [-Werror]
../4b7afec1a7ff16d6558a1426739ef992ca03411e8c9cf2a64b09c524fcde/the_user_app.cpp:33:1: error: missing terminating " character
../4b7afec1a7ff16d6558a1426739ef992ca03411e8c9cf2a64b09c524fcde/the_user_app.cpp:36:1: error: expected primary-expression before 'void'
../4b7afec1a7ff16d6558a1426739ef992ca03411e8c9cf2a64b09c524fcde/the_user_app.cpp:36:1: error: expected ',' or ';' before 'void'
cc1plus: all warnings being treated as errors
make: *** [../4b7afec1a7ff16d6558a1426739ef992ca03411e8c9cf2a64b09c524fcde/the_user_app.o] Error 1

Thanks for the bug report @sjunnesson—added to the backlog.

Removing the compiler flag “-Werror” (Warnings as Errors) in the build script should fix the compiler error “cc1plus: all warnings being treated as errors”

@satishgn, How does one do that for the web IDE?

I am getting a lot of “-Werror=maybe-uninitialized” and would like to turn it off.

Aren’t we relying on warnings as errors to make sure the function signatures match when using Spark.Function and whatnot?

Yes, but only in the core-firmware repo. In core-common-lib and core-communication-lib, we don’t use the -Werror flag.

Hmm… we are using that flag in an attempt to help people write better code—including, as @Dave says, to prevent what we expect will be common mistakes. Without it, some hard-to-debug cases will silently creep into user apps.

Dear Spark Community—what do you think? Should we remove it? Down the road we could make it an option in the web IDE, like with a checkbox or something, but for now, we need the most sensible default. Vote +1 to remove -Werror or -1 to keep warnings failing the build.

how do we Vote +1 or -1?
id vote to keep the warnings as errors, but would like this to become a user configurable item…

Sorry, just put that text “+1” or “-1” in a reply in this thread. Definitely user configurable down the road, but let’s vote on the default until then.

+1

It’s going to be a PITA to port some libraries over with -Werror on, so I say remove for now and keep as an option. You’ll still be able to see the warnings in the compile output, but if the compile is erring out it does me no good.

1 Like

+1 to remove

Can’t port even basic libraries (eg: SimpleTimer) at the minute with the errors.

1 Like

+1. I like the idea of showing the errors in the debug console even when the compile succeeds, but that requires some changes to the web IDE, so the quicker fix will just be to switch the flag.

Glad I ran across this - I have a todo list item that says “figure out how to turn off warnings”. I would have been pretty stuck.

+1 to remove. This is currently blocking me on porting a couple of Arduino based libraries.

1 Like

+1 to remove

(Of course there would have to be a minimum number of chars in a reply :smile: )

1 Like

Removed in the master branch:

It’s not incorporated into the web IDE yet. Everyone can expect that in about a week.

Woot! Community!

1 Like

There is an another weird thing with StringObject.

String message = "Spark*Core!";

void setup() {
    message = "Potato";
    message += 42;
    Serial.begin(9600);
}

void loop() {
        Serial.println(message);
        delay(1000);
}

This outputs semirandom character between “Potato” and 42.
In bigger app I got “PotatoL42” and now with this bare example I get “Potato¼42”.

I was debugging my led matrix and I thought that it or the library was defective, but now that Serial works, it seems the String indeed gets that extra character in this operation.

I now use char[] and sprintf etc., but String would be easier to use if it works properly.

Thanks @weakset, I’ve added that to our backlog. The firmware’s open source of course, so we accept pull requests. :smile:
https://github.com/spark/core-firmware/blob/master/src/spark_wiring_string.cpp

Your itoa() function is broken for non-negative numbers:

char* itoa(int a, char* buffer, unsigned char radix){
    if(a<0){
            *buffer = '-';
            a = -a;
    }
    ultoa(a, buffer + 1, radix);
    return buffer;
}

You probably want something like (I haven’t tested this):

char* itoa(int a, char* buffer, unsigned char radix){
    char *wrkbuf = buffer;
    if(a<0){
            *wrkbuf++ = '-';
            a = -a;
    }
    ultoa(a, wrkbuf, radix);
    return buffer;
}
1 Like

I didn’t have local build enviroment ready and it took a bit longer to set up than I expected. Meanwhile @Raldus already spotted the same thing, but my solution was to add alternative function calls in if-else.

char* itoa(int a, char* buffer, unsigned char radix){
	if(a<0){
		*buffer = '-';
		a = -a;
		ultoa(a, buffer + 1, radix);
	}else{
		ultoa(a, buffer, radix);
	}
	return buffer;
}

That works, but my virtual machine setup seems too unstable so I can’t test Radus’s version. (I can compile and flash stuff, but Core keeps resetting to listening mode even if I give it Wifi credentials.)


@Raldus’s version also works. Turned out that my build system was all good, but my router had different settings than I remembered.