IOT at you service with LoraWan and Ruby
Manage your devices inside a Lora Network
What is Lora?
LoRaWAN is a Low Power Wide Area Network with features that support low-cost, mobile, and secure bi-directional communication for Internet of Things (IoT), machine-to-machine (M2M), and smart city, and industrial applications. LoRaWAN is optimized for low power consumption and is designed to support large networks with millions and millions of devices. Innovative features of LoRaWAN include support for redundant operation, geolocation, low-cost, and low-power - devices can even run on energy harvesting technologies enabling the mobility and ease of use of Internet of Things.

Install
gem install lora-rb
To use it in a bundle, add to gem file gem 'lora-rb' and run bundle install
Connection to lora server
Establish a secure connection to your Lora Application on the cloud.
This version supports: 1. TLS protocol with Loriot 1. Http push with Resiot 1. MQTT with A2aSmartCity
Configuration
Insert private information in the yaml:
lib/config/private.yml
and the configuration's parameter in the config file.
lib/config/config.rb
If you are using rails you can use the generator:
bundle exec rails generate lora_rb:install
Every provider assign you a token and an appkey or an appid. Insert your secret data in the yaml:
defaults:
appid:
token:
# Some provider may use it
username:
password:
connector_id:
If you are using Rails 5.1 you can do something like this:
defaults: &defaults
appid: <%= Rails.application.secrets.lora_appid %>
token: <%= Rails.application.secrets.lora_token %>
# etc ...
TLS (with Loriot)
LoraRb.configure do |config|
# These informations are shared for all environments
config.protocol = :tls
config.host = 'eu1.loriot.io'
config.port = 737
end
HTTP (with Resiot)
LoraRb.configure do |config|
# These informations are shared for all environments
config.protocol = :http
config.host = 'eu72.resiot.io'
config.port = 80
end
RABBITMQ
LoraRb.configure do |config|
# These informations are shared for all environments
config.protocol = :rabbitmq
config.host = 'localhost'
end
MQTT (with A2a)
LoraRb.configure do |config|
# These informations are shared for all environments
config.protocol = :mqtt
config.host = 'ptnetsuite.a2asmartcity.io'
config.port = 8883
config.uplink_url = '/sub/v1/users/{username}/apps/{appid}/devices/+/uplink/+'
config.downlink_url = '/api/v1/users/{username}/apps/{appid}/devices/{deveui}/downlink/post/reply/{clientid}/id/{requestid}'
config.ssl = true
config.ssl_file = 'ssl_certificates/mqtt_ca.crt'
end
Usage
From irb require the library:
require 'lora-rb'
then create an instance
lora = LoraClient.new
you should receive the instance with variables depending on protocol:
#<LoraClient:0x0056318ad8e048 ...
Send data to a device
lora.send_cmd(EUI: 'Insert here your EUI code', confirmed: true, data: "0101")
Request example:
{ "cmd":"tx", "EUI":"BE7A0000000010B7", "port":40, "confirmed":false, "data":"0101" }
Response example:
{ "cmd":"txd", "EUI":"BE7A0000000010B7", "seqdn":114, "seqq":113, "ts":1489133179385 }
"cmd":"txd" show the data sent to the gateway
The response could also be:
{ "cmd":"tx", "EUI":"BE7A0000000010CF", "seqdn": 4, "data": "0301", "success": "Data enqueued" }
Receive Data
To listen your devices:
lora.listen
Close the connection
lora.quit
Compatibility
Ruby 2.3+
Install
gem install lora-rb
To use it in a bundle, add to gem file gem 'lora-rb' and run bundle install
To Do
- [x] Connect to a device with tls protocol
v0.1.0 - [x] Send data to a device
v0.1.0 - [x] Receive data from a device
v0.2.0 - [x] Organization in modules to support new protocols
v0.2.0 - [x] Add a configuration
v0.3.0 - [x] Add a rails generator
v0.3.0 - [x] Add http push support
v0.5.0 - [x] Add RabbitMq support
v0.6.0 - [x] Add Mqtt support
v0.9.0 - [ ] Test with many devices
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-feature) - Commit your changes (
git commit -am 'I made extensive use of all my creativity') - Push to the branch (
git push origin my-feature) - Create new Pull Request
Testing
Wide coverage with xx unit tests and xxx assertions
To test locally install the development requirements:
bundle install
Then execute:
bundle exec ruby test/unit_test.rb
Performance tests:
bundle exec ruby test/performance_test.rb
Found a bug?
Please open an issue.
License
The GNU Lesser General Public License, version 3.0 (LGPL-3.0) See LICENSE file