Coder Social home page Coder Social logo

byrdman / sparkfun_phant_particle_library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparkfun/sparkfun_phant_particle_library

0.0 2.0 0.0 120 KB

A Phant library for the Particle Core and Photon.

License: GNU General Public License v3.0

C++ 56.79% Arduino 43.21%

sparkfun_phant_particle_library's Introduction

SparkFun Phant Particle Library

A Phant library for the Particle Core and Photon.

About

This is a firmware library SparkFun's Phant data storage/stream service, implemented on data.sparkfun.com

Phant logo

Repository Contents

  • /firmware - Source files for the library (.cpp, .h).
  • /firmware/examples - Example sketches for the library (.cpp). Run these from the Particle IDE.
  • spark.json - General library properties for the Particle library manager.

Example Usage

Create a Phant Stream

Visit data.sparkfun.com to create a Phant stream of your own. You'll be given public and private keys, don't lose them!

If you want to set up Phant on a server of your own, visit phant.io.

Include & Constructor

Make sure you include "SparkFun-Spark-Phant/SparkFun-Spark-Phant.h":

// Include the Phant library:
#include "SparkFun-Spark-Phant/SparkFun-Spark-Phant.h":

Then create a Phant object, which requires a server, public key and private key:

const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "DJjNowwjgxFR9ogvr45Q"; // Phant public key
const char privateKey[] = "P4eKwGGek5tJVz9Ar84n"; // Phant private key
Phant phant(server, publicKey, privateKey); // Create a Phant object

Adding Fields/Data

Before posting, update every field in the stream using the add([field], [value]) function. The [field] variable will always be a String (or const char array), [value] can be just about any basic data type -- int, byte, long, float, double, String, const char, etc.

For example:

phant.add("myByte", 127);
phant.add("myInt", -42);
phant.add("myString", "Hello, world");
phant.add("myFloat", 3.1415);

POSTing

After you've phant.add()'ed, you can call phant.post() to create a Phant POST string. phant.post() returns a string, which you can send straight to a print function.

Most of the time, you'll want to send your phant.post() string straight out of a TCPClient print. For example:

TCPClient client;
if (client.connect(server, 80)) // Connect to the server
{
    client.print(phant.post());
}

After calling phant.post() all of the field/value parameters are erased. You'll need to make all of your phant.add() calls before calling post again.

Recommended Components

License Information

This product is open source!

Please review the LICENSE.md file for license information.

If you have any questions or concerns on licensing, please contact [email protected].

Distributed as-is; no warranty is given.

  • Your friends at SparkFun.

sparkfun_phant_particle_library's People

Watchers

James Cloos avatar Sam Byrd avatar

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.