element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog [Pi IoT] Smart Competition Home #10: Competition system V - Adding the competition status in the phone
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: clazarom
  • Date Created: 30 Aug 2016 6:15 AM Date Created
  • Views 588 views
  • Likes 2 likes
  • Comments 1 comment
  • design challenge
  • smart competition home
  • php
  • android app
  • piiot;
Related
Recommended

[Pi IoT] Smart Competition Home #10: Competition system V - Adding the competition status in the phone

clazarom
clazarom
30 Aug 2016

https://avatars2.githubusercontent.com/u/1294177?v=3&s=400In order to have a bit more of feedback and add some thrilling while running ("wait! when did he run all those miles?? no way I will let this be"), I want to have an updated table of the current's month competition state. That means:image

  • Including a new function into Competition Service - in Central Node (Raspberry Pi 3). This way, when requested the competition information, it will send back he appropiate data
  • Implementing the "Podium" activity on the Competition Android App - in User's Node

 

 

 

Central Node - Send competition information

Existing file: insert_into_table.php

New functionality: Obtain last row of each column

 

So, apart from inserting information to the database, the competition service should be able to:

  • Read last row of each of the users table
  • Send it back to the phone

 

Read last values upon request

The main .php file is now able to read different types of messages. As a result, we differentiate:

  • type = insert -> to update values in a table
  • type = get_row -> to get last row of each table and extract its monthly distance

 

This request , the get_row, also contains the names of all the roommates, which will be use to select single tables. Then, the file will

 

1. Once we obtain the value from the right HTTP_POST ($json), the code extracts the roommates requested. Each roommate = table

2. Fetch last row of each of user's table

3. Extract monthly distance

//Decode JSON Into Array
$data = json_decode($json);
foreach($json as $key=>$val){
     $row_last = $db->read_rows($val);
     $month = $row_last[NUM_MONTH_COLUMN];
}

(*) read_rows function is been developed to contains the corresponding SQL calls to obtain the last row, and fetch it as an array to return

 

4. At the end, Send it back to the requester, User's Node

 

User's Node - Podium activity

Initial setup: Nexus 5 / Android / SmartCompetitionHome App v 2

 

In this section, I explain how the PodiumTableActivity.java is implemented. It will request the current state of the competition from the server and display in a table. Again, results will be organized from top to bottom.

 

This Activity will only display a table (and later on,  a REFRESH button).

 

PodiumTableActivity.java

When the Activity is created, it will request the monthly information for each user from the Central Node. Once the response arrives, the table is updated with the most recent data. The interesting part of this file is the new AsyncHttpResponseHandler which handles successful messages as follows:

//Handle succesful response
public void onSuccess(String response) {
  System.out.println("Get comp Server response: "+response);

  try {
   //Convert to a JSON Array and get the arguments
   JSONArray arr = new JSONArray(response);
   //List<String> args = new ArrayList();
  //Analyze each JSON object
   JSONObject jsonObj = (JSONObject)arr.get(0);
   Iterator<?> keys = jsonObj.keys();
  while( keys.hasNext() ) {
  String key = (String) keys.next();
   lastMonthValues.put(key, jsonObj.getString(key));
   }
   //Update gui values:
   updateTableValues();

   } catch (JSONException e) {
  e.printStackTrace();
   }
}

(*)lastMonthValues is a Map<String, String > structure holding each roommates monthly distance. updateTableValues() we use this information to organize the Podium table.

Competition Application running in the smartphone

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

NOTE: There should be a way of reducing that long delay when retrieving data

 

 

Conclusion

The competition android application is completed! With this version, each user can:

  • Record their traveled distance
  • Check what is the current status and the other total distance
  • Sign in to reply

Top Comments

  • DAB
    DAB over 9 years ago +2
    Nice update. Knowing where you go and how much time and distance you travel can be useful for future planning. DAB
  • DAB
    DAB over 9 years ago

    Nice update.

     

    Knowing where you go and how much time and distance you travel can be useful for future planning.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube