Spark.log function

Suggestion for cloud API:
Add Spark.log function that would simply post strings to Web IDE with timestamps
Like slower, but wireless Serial port debugging analogue

3 Likes

In a DEBUG_BUILD=y You could add a UDP object in a debug_output() in application.ccp and effectively “tee” the output. The cloud folks @Dave would have to add the plumbing to the web IDE. We just have to prevent logging in the UDP object or it will loop

Totally! I think we have this in mind for Spark.publish, essentially something like Spark.log(“my log message here”) would be a wrapper for Spark.publish(“spark/log”, “my log message here”);

Spark.publish still needs some work, but I think it should be available at the end of the next sprint. It might take a little while to incorporate that into the build site, but it’s definitely a cool idea!

1 Like

In the meantime you could use a ring buffer mapped to a Spark variable.
I have one here: https://github.com/finsprings/spark-ring-buffer

That I use like this:

RingBuffer ringBuffer(64);

void setup()
{
	…
	Spark.variable("log", (void*)ringBuffer.buffer(), STRING);
	…
}

void loop()
{
	…
	ringBuffer.log(“Foo”);
	…
}

(The void is necessary because Spark.variable takes a void * for its second parameter rather than a const void *.)

That creates a 64-byte ring buffer. Tthe limit is 230 (per this post) for a variable right now, so don’t go above that. By default it creates the buffer on the heap but you can make it statically allocated by adding a line like this at the top of its header file

#define RING_BUFFER_FIXED_SIZE 64

It’s not as good as a true publish API, but it’s okay as a stop-gap.

1 Like