Permalink
Browse files

added push code sample

  • Loading branch information...
1 parent 2806961 commit 7b78ef166833c0b21e22bba6237d5b7826368b96 @larsburgess larsburgess committed Jun 13, 2011
Showing with 52 additions and 4 deletions.
  1. +17 −2 nfc-rhodes/app/Nfc/index.erb
  2. +35 −2 nfc-rhodes/app/Nfc/nfc_controller.rb
@@ -9,16 +9,31 @@ function onLogClear() {
</script>
<div class="pageTitle">
- <h1>Nfcs</h1>
+ <h1>NFC Demo</h1>
</div>
<div class="content">
+ <% if @notice %>
+ <p style="color: red"><%= @notice %></p>
+ <% end %>
<ul>
<li>
NFC Enabled: <span class="title"><%= @nfc_status %></span>
</li>
- <li>Log:</li>
+ <li>NFC Log:</li>
<input type="text" style="font-style: bold" id="id_log" value="" />
<input type="button" value="Clear" onClick="onLogClear();"/>
</ul>
+ <form method="POST" action="<%= url_for :action => :start_nfc_push %>">
+ <ul>
+ <li>
+ <label for="text" class="fieldLabel">Push Message</label>
+ <input type="text" name="push" value="Hello from NFC!"/>
+ </li>
+ </ul>
+ <input type="submit" class="standardButton" value="Start Message Push!"/>
+ </form>
+ <form method="POST" action="<%= url_for :action => :stop_nfc_push %>">
+ <input type="submit" class="standardButton" value="Stop Message Push!"/>
+ </form>
</div>
@@ -10,9 +10,42 @@ def index
render :back => '/app'
end
+ def start_nfc_push
+ puts "Sending #{@params['push'].inspect}..."
+ payload = Rho::NFCManager.make_payload_with_well_known_text("en", @params['push'])
+ hash = {
+ 'id' => [0],
+ 'type' => Rho::NdefRecord:: RTD_TEXT,
+ 'tnf' => Rho::NdefRecord::TNF_WELL_KNOWN,
+ 'payload' => payload
+ }
+ record = Rho::NFCManager.make_NdefRecord_from_hash(hash)
+ records = [record]
+ msg = Rho::NFCManager.make_NdefMessage_from_array_of_NdefRecord(records)
+
+ # start push message
+ Rho::NFCManager.p2p_enable_foreground_nde_push(msg)
+ @notice = "Started push."
+ render :action => :index
+ end
+
+ def stop_nfc_push
+ Rho::NFCManager.p2p_disable_foreground_nde_push
+ @notice = "Stopped push."
+ render :action => :index
+ end
+
def nfc_callback
- @log = "TAG received: #{Time.now.strftime('%H:%M:%S')}"
- add_to_log(@log)
+ if @params['messages'].size > 0 and @params['messages'][0]['records'].size > 0
+ @msg = @params['messages'][0]['records'][0]['payload_as_string']
+ else
+ @msg = "No payload"
+ end
+ Alert.show_popup( {
+ :message => @msg,
+ :title => "NFC P2P",
+ :buttons => ["Close"] }
+ )
end
def add_to_log(msg)

0 comments on commit 7b78ef1

Please sign in to comment.