Coder Social home page Coder Social logo

phant-arduino's Introduction

Phant is No Longer in Operation

Unfortunately Phant, our data-streaming service, is no longer in service and has been discontinued. The system has reached capacity and, like a less-adventurous Cassini, has plunged conclusively into a fiery and permanent retirement. There are several other maker-friendly, data-streaming services and/or IoT platforms available as alternatives. The three we recommend are Blynk, ThingSpeak, and Cayenne. You can read our blog post on the topic for an overview and helpful links for each platform.

All secondary SparkFun repositories related to Phant have been archived and pulled in as a subtree in the main Phant GitHub repository.


phant-arduino

The goal of this library is to provide a simple interface for logging data to phant. It should take any data type, convert it to a String, and build a url. This library will not handle interaction with WiFi or ethernet shields, it's only purpose is to make it easier for users to build phant compatible requests without worrying about data types and string concatenation.

Installation

Linux & Mac:

$ cd ~
$ git clone [email protected]:sparkfun/phant-arduino.git
$ ln -s ~/phant-arduino/Phant/ ~/Documents/Arduino/libraries/Phant

Windows: 😢

Usage

To create a new instance of the request builder, pass the server's hostname, your public key, and your private key to the Phant constructor.

Phant phant("data.sparkfun.com", "VGb2Y1jD4VIxjX3x196z", "9YBaDk6yeMtNErDNq4YM");

To add data, you can make calls to phant.add(key, value). The library will convert any value data type to a string, so there is no need for conversion before sending data. For example, if you have a stream with fields titled wind, temp, and raining, your code would add data to the request like this:

phant.add("wind", 12.0);
phant.add("temp", 70.1);
phant.add("raining", false);

To get the request string for adding data, you have two options phant.url() and phant.post(). Both methods will clear the current request data after building and returning the current request. Unless there is some compelling reason to do otherwise, you should always use phant.post() to get a HTTP POST request string. phant.url() will return a URL that you can use in your web browser to test data logging.

In this example client would be an instance of whatever ethernet library you are using:

client.println(phant.post());

To clear all of the data in your stream, you can use phant.clear() to get a HTTP DELETE request string. Clearing the data will not delete the stream definition, it will only delete the logged data.

client.println(phant.clear());

If you would like to retrieve your logged data, phant.get() will return a HTTP GET request string that will cause the server to respond with your logged data in CSV format. Parsing CSV is outside of the scope of this library.

client.println(phant.get());

Output Example

Sketch

#include <Phant.h>

// Arduino example stream
// http://data.sparkfun.com/streams/VGb2Y1jD4VIxjX3x196z
// hostname, public key, private key
Phant phant("data.sparkfun.com", "VGb2Y1jD4VIxjX3x196z", "9YBaDk6yeMtNErDNq4YM");

void setup() {
  Serial.begin(9600);
}

void loop() {

  phant.add("val1", "url");
  phant.add("val2", 22);
  phant.add("val3", 0.1234);

  Serial.println("----TEST URL-----");
  Serial.println(phant.url());

  Serial.println();

  phant.add("val1", "post");
  phant.add("val2", false);
  phant.add("val3", 98.6);

  Serial.println("----HTTP POST----");
  Serial.println(phant.post());

  Serial.println();

  Serial.println("----HTTP GET----");
  Serial.println(phant.get());

  Serial.println("----HTTP DELETE----");
  Serial.println(phant.clear());

  delay(2000);

}

Output

This example prints the following to the serial monitor:

----TEST URL-----
http://data.sparkfun.com/input/VGb2Y1jD4VIxjX3x196z.txt?private_key=9YBaDk6yeMtNErDNq4YM&val1=url&val2=22&val3=0.1234

----HTTP POST----
POST /input/VGb2Y1jD4VIxjX3x196z.txt HTTP/1.1
Host: data.sparkfun.com
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 29

val1=post&val2=0&val3=98.6000

----HTTP GET----
GET /output/VGb2Y1jD4VIxjX3x196z.csv HTTP/1.1
Host: data.sparkfun.com
Connection: close

----HTTP DELETE----
DELETE /input/VGb2Y1jD4VIxjX3x196z/clear.txt HTTP/1.1
Host: data.sparkfun.com
Phant-Private-Key: 9YBaDk6yeMtNErDNq4YM
Connection: close

phant-arduino's People

Contributors

bboyho avatar toddtreece avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phant-arduino's Issues

Arduino MKR1000 Not Compiling on Mac

Hello,
So Ive been trying to upload code onto my MKR1000 with the arduino software several times, yet I keep receiving the following error message which is driving me nuts.

Arduino: 1.8.3 (Mac OS X), Board: "Arduino/Genuino MKR1000"

fork/exec /Users/xxxxxx/Library/Arduino15/packages/arduino/tools/arm-none-eabi-gcc/4.8.3-2014q1/bin/arm-none-eabi-g++: no such file or directory
Error compiling for board Arduino/Genuino MKR1000.

Can someone help me out?

Possible size limitation

I am testing a data stream and I noticed something odd. My original stream had 10 fields, with 111 bytes of content. When I added a field, the content went to 118 and the stream failed in update. The additional field caused the packet to be malformed (400).

I recreated the database but with much shorter names. I was able to update all the way to the 15 field limit. The content was 87. When I add real values, this will be closer to 111 but for now, I can proceed.

Can you look to see if there is an issue around 300 ? The header itself has 190 so either phant is having a memory issue, or the Xbee is but something is corrupting the stream.

Error compiling on MKR1000

When i try to compile my sketch for my Genuino MKR1000 (hackster edition), i get the following error:

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp:27:22: fatal error: pgmspace.h: No such file or directory

 #include "pgmspace.h"

                      ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino MKR1000.

When I try to compile on the Arduino Uno settings, it works fine. But I don't have an Uno...

After copying the pgmspace.h file to the C:***\arduino-1.6.8\libraries\phant-arduino-master\src folder the error changed to:

Arduino: 1.6.8 (Windows 7), Board:"Arduino/Genuino MKR1000"

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp: In member function 'void Phant::add(String, double)':

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp:152:26: error: 'dtostrf' was not declared in this scope

   dtostrf(data, 1, 4, tmp);

                          ^

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp: In member function 'void Phant::add(const __FlashStringHelper*, double)':

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp:162:26: error: 'dtostrf' was not declared in this scope

   dtostrf(data, 1, 4, tmp);

                          ^

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp: In member function 'void Phant::add(String, float)':

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp:174:26: error: 'dtostrf' was not declared in this scope

   dtostrf(data, 1, 4, tmp);

                          ^

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp: In member function 'void Phant::add(const __FlashStringHelper*, float)':

C:\Users\***\Documents\arduino-1.6.8\libraries\phant-arduino-master\src\Phant.cpp:184:26: error: 'dtostrf' was not declared in this scope

   dtostrf(data, 1, 4, tmp);

                          ^

exit status 1
Error compiling for board Arduino/Genuino MKR1000.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I hope anyone can help me!

The data does not load to the cloud

I made program with data does not come into the cloud when I copy test URL from the serial monitor, and paste the URL to explore, write the ok data to the cloud when I use the post, it does not ??
 
  phant.add ( "bin_in", "post");
  phant.add ( "bin_out", false);
  phant.add ( "temp_1", 98.6);
  phant.add ( "temp_2", 98.6);
  phant.add ( "temp_3", 98.6);

  Serial.println ( "---- ---- HTTP POST");
  Serial.println (phant.post ());
  client.println (phant.post ());

I use the library

#include <SPI.h>
#include <Ethernet.h>
#include <Phant.h>

I have used
Arduino UNO
Arduino Ethernet

---- TEST URL -----
http://data.sparkfun.com/input/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt?private_key=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz&bin_in=url&bin_out=22&temp_1=0.1234&temp_2=98.6000&temp_3=98.6000

---- HTTP POST ----
POST /input/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx.txt HTTP / 1.1
Host: data.sparkfun.com
Phant-Private-Key: zzzzzzzzzzzzzzzzzzzzzzzz
Connection: close
Content-Type: application / x-www-form-urlencoded
Content-Length: 66

bin_in = item & bin_out = 0 & temp_1 = 98.6000 and 98.6000 temp_2 = & temp_3 = 98.6000

HTTP/1.0 400 error (Bad request) when contacting data.sparkfun.com

I'm using an XBee to send data up to data.sparkfun.com using the Phant library's post method. I always get an HTTP/1.0 400 error in response. In addition to sending the request through the XBee I print it out to the Serial monitor as well (I save the result from post() to a variable and send it to the XBee and then to the Serial monitor). The request looks fine, and in fact if I copy what's printed to the serial monitor and send it through netcat on my computer it works fine. This led me to assume something was going wrong in transit through the XBee, so I wanted to see exactly what the Phant server was getting. I started my own Phant server to see what exactly the server was getting, and the request goes through no problem. Any thoughts on what could be my problem?

strange String problem

This doesn't seem like a bug with Phant, but possibly the Arduino String(String) constructor.

I'm running into a strange issue using the post method. I'm following this tutorial:
https://learn.sparkfun.com/tutorials/internet-datalogging-with-arduino-and-xbee-wifi

It uploads several pieces of information (temperature, methane level, etc) to a phant stream. As a test I set up a phant stream with temperature as the only parameter. I changed the arduino sketch accordingly and removed the phant.add lines except for temperature. As far as I can tell, none of that matters, but I figured I'd include it.

Temperature is a float so before calling post I'm calling add("temperature", float data). When I call post I'm returned a string with 0 length. If I change the return line of post from 'return String(result);' to 'return result;', I get the post string that I expect. If I call add("temperature", "string data"), it works either way. I don't know why Phant is constructing a new String when result is already a string, but I also don't see why it would matter...

I'm running Mac OS X 10.10.

get() and clear() request strings are imcomplete

Whenever I send a string from the get() or clear() methods the server never replied and if I send another request in succession the server would reply with a "Bad Request".
I solved this problem by adding another '\n' to the last concatenation of both methods' strings:
changed

result += "Connection: close\n";

to

result += "Connection: close\n\n";

is it possible to delete part of the dataset recorded?

I wish to have a command able to delete part of the dataset (e.g., using time range as input criteria), because many prototype project would have fiddling stage in between and that will produce some erroneous data. if user can manually delete these problematic data the quality of the data can be improved.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.