GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - jeffutter/particle-elixir: An Elixir Client for the Particle Cloud API

BranchesTags
Open more actions menu

Latest commit

 

History

47 Commits
47 Commits

Folders and files

NameName
Last commit message
Last commit date
config
config
 
 
fixture/vcr_cassettes/particle
fixture/vcr_cassettes/particle
 
 
lib
lib
 
 
scripts
scripts
 
 
test
test
 
 
.formatter.exs
.formatter.exs
 
 
.gitignore
.gitignore
 
 
.tool-versions
.tool-versions
 
 
.travis.yml
.travis.yml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
mix.exs
mix.exs
 
 
mix.lock
mix.lock
 
 

Repository files navigation

Particle

Build Status Hex.pm Inline docs Deps Status License

Particle Cloud API Client for Elixir:

This is an unofficial client for the Particle IoT platform's HTTP API.

Usage

Installation

def deps do
  [{:particle, "~> 0.1.0"}]
end

and run mix deps.get. Now, list the :particle application as your application dependency:

def application do
  [applications: [:particle]]
end

Configuration

You will need to set the following configuration variables in your config/config.exs file:

use Mix.Config

config :particle,
  particle_key: System.get_env("PARTICLE_KEY")

Stream Usage

Create a module responsible for the handling of the events. Customize handle_events for your application.

defmodule MyApp.ParticleEventHandler do
  alias Experimental.GenStage
  alias Particle.Stream

  use GenStage

  def start_link() do
    GenStage.start_link(__MODULE__, :ok, name: __MODULE__)
  end

  def init(:ok) do
    # Starts a permanent subscription to the broadcaster
    # which will automatically start requesting items.
    {:consumer, :ok, subscribe_to: [Stream]}
  end

  def handle_events(events, _from, state) do
    IO.inspect events
    {:noreply, [], state}
  end
end

Start the workers in the Application.

defmodule MyApp do
  use Application
  alias Particle.Stream

  def start(_type, _args) do
    import Supervisor.Spec

    children = [
      worker(Particle.Stream, ["https://api.particle.io/v1/devices/events/status", Particle.Http, [name: Stream]]), # define url here
      worker(MyApp.ParticleEventHandler, [])
    ]
    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

About

An Elixir Client for the Particle Cloud API

Resources

Readme
MIT license
Activity

Stars

5 stars

Watchers

1 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.