Skip to content

Fermi-4/ParticleClient

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ParticleKafkaConnectorLogo

Particle Client

ParticleClient is a java library which provides a client class for interacting with Particle API

See Maven Central

Getting started

Add dependency to maven pom.xml:

<dependency>
    <groupId>io.github.fermi-4</groupId>
    <artifactId>particle-client</artifactId>
    <version>1.0.3</version>
</dependency>

Usage

Create instance using:

ParticleClient client = ParticleClient.builder()
                            .withToken(token)
                            .build();

// or optionally provide user/pass for 
// endpoints requiring it like the generate token endpoint
ParticleClient client = ParticleClient.builder()
                            .withUsername(username)
                            .withPassword(password)
                            .withToken(token)
                            .build();

List all device id (parse json using jackson):

// jackson mapper
ObjectMapper mapper = new ObjectMapper();

// get the response (see https://docs.particle.io/reference/cloud-apis/api/)
Response response = client.listDevices();

// parse and print out each id
JsonNode rootNode = mapper.readTree(response.body().string());
for (JsonNode deviceNode : rootNode) {
    System.out.println(deviceNode.get("id"));
}

Open a device event stream:

client.openEventStream("temperature", new EventSourceListener() {
            @Override
            public void onEvent(EventSource eventSource, String id, String type, String data) {
                System.out.println("Got temperature event: " + data);
            }
        });

About

Particle client for interacting with Particle.io

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages