AmbientIot
This is a Ruby Gem library to access Ambient ( https://ambidata.io ) service which is provided by AmbientData Inc.
You can upload data (such as a IoT) to Ambient.
Then Ambient draw a Graph of the data.
AmbientIot is a port from ambient-python-lib.
Installation
Add this line to your application's Gemfile:
gem 'ambient_iot'
And then execute:
$ bundle
Or install it yourself as:
$ gem install ambient_iot
Usage
First, you should get an account for Ambient.
Next you make a channel on the Ambient.
Then you can get a channel id, a write key and a read key for the channel.
Uploading data:
Ambient data takes keys d1 to d8.
You set a data as a hash.
require 'ambient_iot'
channel_id = 1234 # set your channel id here
write_key = "abc.." # set write key of the channel
client = AmbientIot::Client.new channel_id, write_key:write_key # create a client
client << { d1:1, d2:2, d3:3} # append a data
client.sync # send to Ambient site
Timestamp is automatically added.
If you don't want to set timestamp, set false the timestamp property.
client.append_timestamp = false
In this case, timestamp is set by Ambient.
Getting uploaded data:
require 'ambient_iot'
channel_id = 1234 # set your channel id here
read_key = "abc.." # set read key of the channel
client = AmbientIot::Client.new channel_id, read_key:read_key # create a client
client.read
# => [
# {:d1=>1, :d2=>2, :d3=>3, :created=>2018-04-27 23:13:18 +0900},
# .
# {:d1=>2, :d2=>1, :created=>2018-04-24 00:00:00 +0900}
# ]
# with specific date
client.read date:Time.new(2018, 4, 26)
# with specific range
client.read start:Time.new(2018, 4, 20), end:Time.new(2018, 4, 26)
# with number of data
client.read n:1, step:5
Getting a channel information
require 'ambient_iot'
channel_id = 1234 # set your channel id here
read_key = "abc.." # set read key of the channel
client = AmbientIot::Client.new channel_id, read_key:read_key # create a client
client.info # get
# => {:ch=>"1234", :user=>"1234", :created=>2018-04-23 22:59:06 +0900, :modified=>2018-04-27 23:23:59 +0900, :lastpost=>2018-04-27 23:13:25 +0900, :charts=>1, :chName=>"Temperature", :chDesc=>"Temperature of the room", :d1=>{:name=>"data1", :color=>"1"}, :d2=>{:name=>"data2", :color=>"2"}, :d3=>{:name=>"", :color=>"3"}, :d4=>{:name=>"", :color=>"4"}, :d5=>{:name=>"", :color=>"5"}, :d6=>{:name=>"", :color=>"6"}, :d7=>{:name=>"", :color=>"7"}, :d8=>{:name=>"", :color=>"8"}, :public=>false, :showlocation=>false, :photoid=>"", :phototitle=>"", :dataperday=>1}
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/ito-soft-design/ambient_iot. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the AmbientIot project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.