-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow storage of more than one temperature sensor at a time
- Loading branch information
1 parent
e788f34
commit 7965a87
Showing
9 changed files
with
130 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
class SensorController < ApplicationController | ||
|
||
def temperature | ||
arduino = Arduino.find_by_mac_address(params[:arduino]) | ||
sensor = params[:sensor] | ||
arduino = Arduino.find_by_mac_address(params[:arduino]) | ||
data = params[:sensor].slice(:capture_time, :data, :unit) | ||
|
||
temperature = new TemperatureSensor( | ||
sensor.slice(:capture_time, :data, :unit) | ||
.merge({arduino_id: arduino.id}) | ||
) | ||
data.merge!({arduino_id: arduino.id}) | ||
|
||
if temperature.save | ||
render json: temperature | ||
sensor = TemperatureSensor.new(data) | ||
|
||
if sensor.save | ||
render json: sensor | ||
else | ||
render json: temperature.errors.messages | ||
render json: sensor.errors.messages | ||
end | ||
end | ||
|
||
def temperatures | ||
arduino = Arduino.find_by_mac_address(params[:arduino]) | ||
sensors = [] | ||
|
||
params[:sensors].each do |sensor_data| | ||
data = sensor_data.slice(:capture_time, :data, :unit) | ||
data.merge!({arduino_id: arduino.id}) | ||
|
||
sensor = TemperatureSensor.new(data) | ||
|
||
if sensor.valid? | ||
sensors << sensor | ||
else | ||
render json: [sensor.errors.messages, params[:sensors]] | ||
|
||
return | ||
end | ||
end | ||
|
||
sensors.each { |sensor| sensor.save } | ||
|
||
render json: sensors | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,26 @@ | ||
<%= form_for(@arduino) do |f| %> | ||
<% if @arduino.errors.any? %> | ||
<div id="error_explanation"> | ||
<h2><%= pluralize(@arduino.errors.count, "error") %> prohibited this arduino from being saved:</h2> | ||
|
||
<ul> | ||
<% @arduino.errors.full_messages.each do |msg| %> | ||
<li><%= msg %></li> | ||
<% end %> | ||
</ul> | ||
<%= form_for @arduino, :html => { :class => 'form-horizontal' } do |f| %> | ||
<div class="control-group"> | ||
<%= f.label :name, :class => 'control-label' %> | ||
<div class="controls"> | ||
<%= f.text_field :name, :class => 'text_field' %> | ||
</div> | ||
<% end %> | ||
|
||
<div class="field"> | ||
<%= f.label :name %><br /> | ||
<%= f.text_field :name %> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :mac_address %><br /> | ||
<%= f.text_field :mac_address %> | ||
<div class="control-group"> | ||
<%= f.label :mac_address, :class => 'control-label' %> | ||
<div class="controls"> | ||
<%= f.text_field :mac_address, :class => 'text_field' %> | ||
</div> | ||
</div> | ||
<div class="field"> | ||
<%= f.label :email %><br /> | ||
<%= f.text_field :email %> | ||
<div class="control-group"> | ||
<%= f.label :email, :class => 'control-label' %> | ||
<div class="controls"> | ||
<%= f.text_field :email, :class => 'text_field' %> | ||
</div> | ||
</div> | ||
<div class="actions"> | ||
<%= f.submit %> | ||
|
||
<div class="form-actions"> | ||
<%= f.submit nil, :class => 'btn btn-primary' %> | ||
<%= link_to t('.cancel', :default => t("helpers.links.cancel")), | ||
arduinos_path, :class => 'btn' %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,40 @@ | ||
<h1>Listing arduinos</h1> | ||
|
||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Mac address</th> | ||
<th>Email</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
|
||
<% @arduinos.each do |arduino| %> | ||
<tr> | ||
<td><%= arduino.name %></td> | ||
<td><%= arduino.mac_address %></td> | ||
<td><%= arduino.email %></td> | ||
<td><%= link_to 'Show', arduino %></td> | ||
<td><%= link_to 'Edit', edit_arduino_path(arduino) %></td> | ||
<td><%= link_to 'Destroy', arduino, method: :delete, data: { confirm: 'Are you sure?' } %></td> | ||
</tr> | ||
<% end %> | ||
<%- model_class = Arduino -%> | ||
<div class="page-header"> | ||
<h1><%=t '.title', :default => model_class.model_name.human.pluralize %></h1> | ||
</div> | ||
<table class="table table-striped"> | ||
<thead> | ||
<tr> | ||
<th><%= model_class.human_attribute_name(:id) %></th> | ||
<th><%= model_class.human_attribute_name(:name) %></th> | ||
<th><%= model_class.human_attribute_name(:mac_address) %></th> | ||
<th><%= model_class.human_attribute_name(:email) %></th> | ||
<th><%= model_class.human_attribute_name(:created_at) %></th> | ||
<th><%=t '.actions', :default => t("helpers.actions") %></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @arduinos.each do |arduino| %> | ||
<tr> | ||
<td><%= link_to arduino.id, arduino_path(arduino) %></td> | ||
<td><%= arduino.name %></td> | ||
<td><%= arduino.mac_address %></td> | ||
<td><%= arduino.email %></td> | ||
<td><%=l arduino.created_at %></td> | ||
<td> | ||
<%= link_to t('.edit', :default => t("helpers.links.edit")), | ||
edit_arduino_path(arduino), :class => 'btn btn-mini' %> | ||
<%= link_to t('.destroy', :default => t("helpers.links.destroy")), | ||
arduino_path(arduino), | ||
:method => :delete, | ||
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, | ||
:class => 'btn btn-mini btn-danger' %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
|
||
<br /> | ||
|
||
<%= link_to 'New Arduino', new_arduino_path %> | ||
<%= link_to t('.new', :default => t("helpers.links.new")), | ||
new_arduino_path, | ||
:class => 'btn btn-primary' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<h1>New arduino</h1> | ||
|
||
<%= render 'form' %> | ||
|
||
<%= link_to 'Back', arduinos_path %> | ||
<%- model_class = Arduino -%> | ||
<div class="page-header"> | ||
<h1><%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human %></h1> | ||
</div> | ||
<%= render :partial => 'form' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,25 @@ | ||
<p id="notice"><%= notice %></p> | ||
<%- model_class = Arduino -%> | ||
<div class="page-header"> | ||
<h1><%=t '.title', :default => model_class.model_name.human %></h1> | ||
</div> | ||
|
||
<p> | ||
<b>Name:</b> | ||
<%= @arduino.name %> | ||
</p> | ||
<dl class="dl-horizontal"> | ||
<dt><strong><%= model_class.human_attribute_name(:name) %>:</strong></dt> | ||
<dd><%= @arduino.name %></dd> | ||
<dt><strong><%= model_class.human_attribute_name(:mac_address) %>:</strong></dt> | ||
<dd><%= @arduino.mac_address %></dd> | ||
<dt><strong><%= model_class.human_attribute_name(:email) %>:</strong></dt> | ||
<dd><%= @arduino.email %></dd> | ||
</dl> | ||
|
||
<p> | ||
<b>Mac address:</b> | ||
<%= @arduino.mac_address %> | ||
</p> | ||
|
||
<p> | ||
<b>Email:</b> | ||
<%= @arduino.email %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_arduino_path(@arduino) %> | | ||
<%= link_to 'Back', arduinos_path %> | ||
<div class="form-actions"> | ||
<%= link_to t('.back', :default => t("helpers.links.back")), | ||
arduinos_path, :class => 'btn' %> | ||
<%= link_to t('.edit', :default => t("helpers.links.edit")), | ||
edit_arduino_path(@arduino), :class => 'btn' %> | ||
<%= link_to t('.destroy', :default => t("helpers.links.destroy")), | ||
arduino_path(@arduino), | ||
:method => 'delete', | ||
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, | ||
:class => 'btn btn-danger' %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters