Giter VIP home page Giter VIP logo

elixir-rf69's Introduction

RF69HCW Elixir Interface

Interact with RFM69HCW radio modules via spi.

datasheet

Arduino compatible library

Purchase from adafruit

Purchase from SparkFun

Current Features / Known Issues / wants

  • Packet encryption/decryption
  • Send packets
  • Receive packets
  • Auto Ack packets
  • only 915 mhz is currently supported
  • AES encryption
  • Basic Usage documentation
  • RSSI value reading
  • Processing packet data outside of the library
  • Packet recv/send telemetry (because why not?)
  • Unit tests?

WARNINGS

Be sure to check your local laws for legal radio bands.

Compatability

Packets are encoded/decoded with the same format as LowPowerLabs RF69 library version 1.4 (described here). The goal is to have feature parity with the Arduino library.

Wiring

Currently i've only tested on Raspberry Pi, but it should work on any device that ElixirCircuits supports.

Usage

iex()> {:ok, pid} = RF69.start_link [
  reset_pin: 16,
  ss_pin: 25,
  irq_pin: 13,
  spi_bus_name: "spidev0.0",
]
{:ok, #PID<0.1660.0>}
iex()> receive do
...()>  %RF69.Packet{} = packet ->
...()>  IO.inspect(packet, label: "received packet")
...()>  :ok
...()> end
packet received: %RF69.Packet{
  ack_requested?: true,
  is_ack?: false,
  payload: "123 ABCDEFGHIJK",
  rssi: -42,
  sender_id: 2,
  target_id: 1
}
:ok
iex()> RF69.send(pid, 2, "hello node 2 from gateway node!")
:ok
iex()> 

Examples

The API defined is pretty low level. If you want to use it, you should probably wrap the radio server in your own genserver. See the Logger Example for an example.

There is a repo here with some more examples

Acking

By default the rf69 server will respond to acks If your implementation requires user acking, when starting the rf69 server, pass in auto_ack?: false. This will require that in your code when you receive a packet, you will be responsible for acking it in the configured amount of time required by your other nodes. Here's an example:

def handle_info(%Packet{requires_ack?: true} = packet, state) do
  # Process the packet (whatever that means to your application)
  case process_packet(packet) do
    :ok -> 
      # packet processed successfully.
      RF69.ack(state.rf69, packet)
    :error -> 
      # packet processed unsuccessfully.
      # The protocol has no concept of "nack"ing, so the lack of
      # an ack should be considered a "nack"
      Logger.error "Not acking #{inspect(packet)}"
  end
  {:noreply, state}
end

Encryption

AES Encryption is handled at the hardware level. All you as a developer need to do is load the encryption key when starting the server.

WARNING: This key must be EXACTLY 16 bytes wide.

{:ok, pid} = RF69.start_link(encrypt_key: "sampleEncryptKey")

elixir-rf69's People

Contributors

connorrigby 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.