SparkJ

Control the Particle Cloud from Java

License

License

MIT
Categories

Categories

Ant Build Tools
GroupId

GroupId

com.github.grantwest.sparkj
ArtifactId

ArtifactId

sparkj
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

SparkJ
Control the Particle Cloud from Java

Download sparkj

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.grantwest.sparkj/sparkj/ -->
<dependency>
    <groupId>com.github.grantwest.sparkj</groupId>
    <artifactId>sparkj</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.grantwest.sparkj/sparkj/
implementation 'com.github.grantwest.sparkj:sparkj:0.0.3'
// https://jarcasting.com/artifacts/com.github.grantwest.sparkj/sparkj/
implementation ("com.github.grantwest.sparkj:sparkj:0.0.3")
'com.github.grantwest.sparkj:sparkj:jar:0.0.3'
<dependency org="com.github.grantwest.sparkj" name="sparkj" rev="0.0.3">
  <artifact name="sparkj" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.grantwest.sparkj', module='sparkj', version='0.0.3')
)
libraryDependencies += "com.github.grantwest.sparkj" % "sparkj" % "0.0.3"
[com.github.grantwest.sparkj/sparkj "0.0.3"]

Dependencies

compile (3)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.4.2
com.mashape.unirest : unirest-java jar 1.3.20
org.glassfish.jersey.media : jersey-media-sse jar 2.22.2

test (4)

Group / Artifact Type Version
junit : junit jar 4.12
com.sparkjava : spark-core jar 2.3
org.hamcrest : hamcrest-junit jar 2.0.0.0
org.slf4j : slf4j-simple jar 1.7.7

Project Modules

There are no modules declared in this project.

SparkJ: Control the ParticleCloud w/ Java

Disclaimer

I built this as a naive developer, it is not a good example of code and it is not a good idea to ever hard code your password as suggested in the documents. A proper program would use a token (not password) provided at runtime. I am only leaving this code here because it works and someone might find it usefull for a little weekend experiment.

Usage

SparkJ is a maven project and is available from the Maven Central repository. To use SparkJ add this to your pom.xml:

<dependency>
  <groupId>com.github.grantwest.sparkj</groupId>
  <artifactId>sparkj</artifactId>
  <version>0.0.3</version>
</dependency>

Call functions and read variables:

SparkDevice device = new SparkDevice("50df6b0651675496402a02b7", "username", "password");
int funcResult = device.callFunction("functionName", "argsHere");
String varValue = device.readVariable("varName");

Subscribe to a device's event stream:

SparkDevice device = new SparkDevice("50df6b0651675496402a02b7", "username", "password");
SparkEventStream stream = device.eventStream((event) -> System.out.println(event.toString()));
//You will need to wait here because the event stream is asynchronous

It is also possible to get other event streams by using the myEvents() and publicEvents() methods of the SparkEventStream class.

Lastly, if you are instantiating many devices, this method will result in fewer HTTP requests:

  SparkSession session = new SparkSession("username", "password");
  SparkDevice dev1 = new SparkDevice("50df6b0651675496402a02b7", session);
  SparkDevice dev2 = new SparkDevice("5496402a02b000df6b06516c", session);

Documentation

Full ParticleCloud documentation and examples on how to write your Particle device code can be found here: https://docs.particle.io/reference/api/

Versions

Version
0.0.3
0.0.2
0.0.0