New Phant Library available w/ server response checking

I have published a library that will post data to the SparkFun Phant server ( You can find it in the libraries as PietteTech_Phant.

Some differences between this library and the existing Phant library -

 *   Uses TCPClient block write and block reads when possible
 *   Designed with static internal buffers w/511 bytes of name/value pairs
 *   Currently only supports Steam Clear and Stream Post
 *   Waits for the response and checks return codes from the Phant server
 *   Error codes are returned from the sendData & addData calls
 *   You have access to human readable Phant messages using getError() method

The included example will show you how to post just about any data type and send it to the server. I have created a demo test stream on so you can build the example and run it without having to create your own stream. You can view the data at

Please let me know if you experience any problems with this library. A lot of time has been spent into making it solid and robust with communications to the Phant server.

This project was supported by the Open Source Beehives Project (


I just updated the Phant library to change the return value for the addData method.

Previously the addData method returned ‘0’ on failure and ‘1’ on success. Now on success it will return the number of bytes added to the stream and still return ‘0’ on failure.

Since the _params buffer (what gets sent to the Phant server in the POST method) is limited to 512 bytes this allows you to keep track of how much space you have used in the buffer.

Finally I would like to point out that if you get a failure on sending the data to the Phant server the contents of the _params buffer are intact. This way you can retry as many times as you wish. However if you do eventually give up on the send please remember to clear the buffer by calling the begin method before you start adding data again with addData. Otherwise you will have the previous data in the _params buffer when you add new data. This will cause errors with the Phant server as you could have multiple values for the same name in the data stream. (for example: I clear the buffer after I give up on line 145 in phanttest.ino)

1 Like


Thanks for the great work! Is it going to be possible for the url to be something like

I have the phant server running locally but on 8080 as the Spark :cloud: API is taking up port 80 for now…

If i can fix this in the new few hours i’ll be able to demo this tomorrow! :smiley:

@kennethlimcp Yes, I believe DNS will resolve your IP address “” as the correct address.

For the port you can specify that at time of construction. For example your declaration in your main app would be -

Phant::Stream stream1("", <your public key>, <your private key>, 8080)

sweet! I’ll try in a while.

Just a quick crash course, how can i print to the respective data field? :smiley:

Sorry but i have to squeeze you for the short hours i have left. :wink:


Here is a quick tutorial

Phant::Stream stream1("", "<< Public Key >>", "<< Private Key>>", 8080);

Creates the Phant object


Creates the private TCPClient object (only does this the first time), set’s up the header and clears out the buffers

//Adding a int field to the stream
int iTest = -rand();
stream1.add("int", iTest);

Adds an integer to the buffer. Most data types supported.

_retry = 0;
_ret = 0;
while (_retry < 5 && !(_ret = stream1.sendData())) { delay(500); _retry++; }

Sends the data to the Phant server. It will try up to 5 times.

The Phanttest.ino is a very good example of how to add name=value fields to the buffer and post to the Phant database.

Hope this helps!


Currently this library only supports POST methods. (not sure why anyone would use GET for pushing data) POST is the default with the sendData method.

For clearing out the Phant stream of previous data use the following -

// clear previous stream values
_retry = 0;
while (_retry < 5 && !(_ret = stream1.sendData(PHANT_CLEAR_METHOD))) { delay(500); _retry++; }

@kennethlimcp How did the demo go? Were you able to get it working in time?

It worked great at home but broke at the demo. Haha!

I tested it again and it seems to work fielne again. Wondering what’s the issue though.

But thanks for the help! I’ll be using it for other application in future :slight_smile:

1 Like

Hey Guy,

I am trying to use @mtnscott Spark Core Data Library (PIETTETECH_PHANT 0.0.3) but all I can get (even with the example running) are connection errors:

Press any key to begin
PHANT test v1.0
Local IP Address =
Starting client.connect(
Failed to connectStarting client.connect(
Failed to connectStarting client.connect(
Failed to connectStarting client.connect(
Failed to connectStarting client.connect(
Failed to connectStream could not be cleared Retries = 5 - time = 7.0s

I also tried to connect via IP but with the same result.
I hope one of you may be has an idea. :smile:
Thank you a lot.

hi @tooold Can you add a call to your startup function


And add this function to your program

void printDNS() {
    IPAddress dnshost(ip_config.aucDNSServer[3], ip_config.aucDNSServer[2], ip_config.aucDNSServer[1], ip_config.aucDNSServer[0]);
    Serial.print("DNS IP      : ");

Some cores develop DNS problems, if it displays DNS IP: then we have a DNS lookup problem. You can read this thread for more info -

Let me know what you discover

Hey @mtnscott,

thank you for your fast response.
It is exactly like you said:
My Core seems to have these DNS Problem as it alway gets the IP for DNS.
Is there anything I can do, to fix this?

@tooold, I’m glad we confirmed the problem. Unfortunately I have not discovered a reliable way to recover the core once it gets into this state. There are some workarounds based on your skill level. Since this is a different topic lets not discuss it here. PM me and we can discuss options.