Professional Documents
Culture Documents
Unit Objectives
After completing this unit, you will:
be able to choose the proper Intel XDK edition for your needs
Logistics
Required software
Key words
Unit summary
Critique
Unit Topics
1-1
Intel XDK
Build for one and publish to all app stores faster, with one
click. Deliver across Android*, iOS*, and Windows* app
stores, and mobile devices.
1-2
Course Content
1-3
1-4
Intended Audience
Intel XDK is a free tool for people who want to create mobile apps. Whether you are a college
student who wants to learn HTML5 to create mobile apps, or an experienced web developer
who knows HTML5 but has never created a mobile app, this guide can take you through the
features of Intel XDK from design, through implementation, to publishing, in order to get
apps on many devices in minimal time.
1-5
Following is a map to help chart your course through this guide. Use the entire guide or
choose the parts that you need.
1-6
Industry Professional
Without
HTML5 Experience
College/University
Student
Industry Professional
with
HTML5 Experience
Welcome
Introducing the course
While doing the exercises throughout the following units, think about
the app you want to create and how each skill you learn applies to that
app.
1-7
1-8
The next several pages introduce some details about Intel XDK.
Choose a Framework
Intel XDK supports several popular frameworks. A framework is a layer
between your code and the program interpreter that
provides functionality for invoking methods on your user
interface (UI) widgets. You may be familiar with a particular
framework for styling HTML5. If not, start with Twitter
Bootstrap for now and switch later if you like. Following are
some of the frameworks supported by Intel XDK.
1-9
the styling looks like an iOS app, etc. CON: not as widely known and
supported as some other UI frameworks.
Intel XDK integrates an easy-to-use, drag & drop App Designer with
Brackets, a highly-regarded, open-source editor with syntax helpers and
auto-completion.
1 - 10
You can trust that it works, because you can verify itBy loading Intel App
Preview onto your mobile devices, you can:
Change your code while running and watch the display change.
Intel App Preview is available for iOS, Android, and Windows 8+ devices in
their respective app stores.
1 - 11
1 - 12
Accelerometer
Android multi-touch
Contacts
Geolocation
Enhanced audio
Accelerated canvas
1 - 13
Logistics
When should you upgrade your Intel XDK version?
Usually immediately.
How much does it cost?
Nothing.
Frequent Upgrades
Intel XDK is a developing product. As such, it is being improved
constantly with upgrades available aproximately every 6-8 weeks. Though
it is usually best to use the latest version, you have the option of
remaining on an older version when a new version is released.
For example, when your app is nearly ready to publish, you may want to
continue using your current version of Intel XDK for a few days while you
finish testing and building.
NOTE: when a new version of Intel XDK is released, before upgrading to
the new version, make a backup copy of your project folders.
Cost
Free.
Apps can be developed with Intel XDK from idea inception, to built files ready for an app
stores, with no cost involved. When you submit your app to one or more app stores you must
meet their requirements, which may involve cost.
1 - 14
Code, debug, test on device, and build for multiple devices all in Intel
XDK
Course Prerequisites
The prerequisites for this course are:
Intel XDK
http://xdk.intel.com/
1 - 15
Reviews test how well you remember the concepts from the unit.
1 - 16
Steps
Download and Install Intel XDK on your host machine
Host machine is the machine you are programming on. Target device is
the tablet or phone on which you will install and run your app.
1. Open a web browser to the following URL http://xdk.intel.com/
2. Click the Download Intel XDK button.
OS X Users:
1.
1 - 17
2.
3.
4.
1.
2.
1 - 18
End of Walkthrough --
View the HTML source code for web pages. Though you will be
creating mobile apps rather than web pages, they are very similar and
you may use these techniques in your mobile development.
Steps
View HTML Source
Each browser is slightly different. There are steps here for Firefox*,
Chrome*, and IE* running on a Windows* system. But you may be running
on an OS X system or you may be using some other browser. These are
just three samples, shown so that you can see the similarities and
differences in the methods, so that you can figure out how to view source
in any browser.
First, open a website in your browser. Then do the following to see the
HTML source code for that page. (Images shown below.)
Firefox
Click the Open Menu icon in the upper right corner of the
browser
1 - 19
HTML source code. This looks a lot like CDT that we will use for
testing later in the course.
Firefox
Chrome
Internet Explorer
Key Words - terms you either learned in class from your teacher, read in this
document or they are terms you should look up
.
HTML5
W3C
UI/GUI
Framework
Brackets
Simulator
Cordova/Plugin
Intel App Preview
Intel XDK
1 - 20
Unit Summary
This Unit summary will summarize things you learned in the previous pages, but some of
those things were not fully explained.
You are encouraged to look up things you dont fully understand (just like an experienced software
developer would do).
The course has been designed assuming that you may not be familiar with
HTML, CSS or JavaScript. Experienced web developers can skip the parts
they know.
Unit Review
Answer the following questions to verify that you learned the basic concepts covered in this unit.
1. You can use a computer with the following operating system(s) to
develop mobile apps with Intel XDK.
a
Windows
OS X
Ubuntu
2. With Intel XDK you can develop apps for the following devices.
a
Windows mobile 8+
iOS
Android
3. Do you need to install any software other than Intel XDK in order to
proceed through a robust development work flow, i.e. create, test,
build, and deploy a mobile app? If so, what?
4. Which physical device features can you test with the simulator?
1 - 21
5. You must develop mobile apps using Intel's App Designer (T/F)
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 22
Unit Objectives
After completing this unit, you should be able to:
get help
Getting help
Key words
Unit summary
Critique
Unit Topics
1 - 23
4. Build
Package the app for further testing and for distribution in app stores.
Designing Apps
As depicted below, Design mode in App Designer enables you to visually
prototype the look and feel of your application.
6
1
5
While in Design view, you can drag and drop components from
the UI Controls Palette (3) onto the Design Canvas (4).
The Product Version (6) indicator shows the version of Intel XDK
that you are using.
Developing Apps
As depicted below, App Designer enables you to toggle from Design to
Code view. This enables you to modify the code generated by App
Designer, as well as edit JavaScript and CSS application assets (buttons
and other widgets). Code hints appear as you type.
1 - 25
Code/Design Toggle
Device Selector
1 - 26
Steps
Make sure you have watched Matts Getting Started video.
Create a New Project
Add an Alert
Watch the following video to review what has been covered and to see
how to add alert pop ups for Android and iOS.
Dales Video https://software.intel.com/en-us/videos/develop-apps-in-html5using-the-intel-xdk
1 - 28
Steps
Create a New Project
1. From the Controls panel, drag a Header and drop it onto the design
canvas.
2. In the Header Settings panel, turn on the checkbox adjacent to the
Title property and enter the following title:
1 - 29
HTML5 Approach
The HTML5 approach is a cross-platform approach that enables access to native features via
plugins
1 - 31
1 - 32
Getting Help
Intel XDK ships with online documentation and sample applications, and
has community support resources available as well. As illustrated below
by the dropdown help menu, help features are available by clicking on the
yellow question mark button.
Help Icon
After learning the basics, perhaps the most useful documentation pages
for Intel XDK beginners are the Testing and Debugging pages. There you
1 - 33
Intel XDK Developer Forum - You can search and read the questions and
answers without being logged in. But to post questions you must log in.
Intel XDK Developer Forum many posts are answered by Intel employees,
1 - 35
Key Words - as before, find these terms either in this document or look
online
.
Host/Target
IDE
HTML5 (in this context, refers to HTML + CSS + JavaScript)
HTML
CSS
JavaScript
Code hints
Develop/Simulate/Test/Debug/Build (know what these are
individually, as well as what the set implies)
App Designer
Roll back
Pop up
Native App
Cross-Platform App
index.html
main.css
User Forum
Unit Summary
Intel XDK is an IDE for creating mobile apps built on HTML5: HTML,
JavaScript and CSS3.
1 - 36
App Designer allows you to switch between the visual editor and the
code editor.
You can create widgets (buttons, etc.) either using App Designer or
without App Designer in code.
Intel XDK ships with several sample apps that demonstrate frequently
requested mobile app features.
You can get help with Intel XDK by reviewing the sample apps, by
reading the documentation and by reading or asking questions on the
user forum.
Unit Review
6. What is the SDL? List at least 3 steps in the SDL.
7. Which tab do you use in Intel XDK to see your code?
8. Which tab do you use when you want to see what your app will look
like on a phone?
9. You must use Intel's App Designer to develop mobile apps with Intel
XDK (true/false), if not, in what other way can you create a button?
10. Which physical device features can you test with the Simulator?
11. What happens when you mouse over color numbers in css files in
Intel XDK?
12. How do you add an alert pop-up to an app?
13. What are the main advantages of developing a mobile app using web
standards instead of using Objective-C or Java? List and explain two
advantages.
14. Describe a scenario in which you would want to use native
development. Justify.
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 37
Unit objectives
After completing this unit, you should be able to:
prepare for the post deployment tasks required to support your app
Think Design
Unit topics
o
Scalability
Security
Support
Key words
Unit summary
Unit review
Critique
1 - 38
Think design
When you are developing an app, dont just think code, think design. Most
people who create apps think its fun. Well, because it IS fun. Its fun when you
first make a button do something. Its fun to see your first app run on an actual
device. Its fun to finish an app and put it in one of the app stores.
When we start creating our first app though, most of us dont think about what
will happen if several thousand people start using it. We might think about the
money and the marketing power, but we might not think about ensuring that
the app maintains efficient service.
Besides creativity and generating interest, there are several design issues to
consider when you start creating an app that you want to scale to many users?:
Scalability refers to the ability of your app to handle users as your user base
increases.
Security refers to hiding certain information that should be kept secret, for
example you dont want user B to see user As private information.
Support is that part of service that is considered a part of maintenance after
the app is created, ensuring that the users are well served.
Scalability
Unless you create apps strictly for fun and dont have any interest in monitoring
their usage, acquiring market share is important. You want people to download
and use your apps. But as you acquire market share you must retain it.
Scalability is the ability of a system, process, or network to increase in service
capacity to accommodate user growth.
Consider a highway you use on a daily basis to go to work or school. There are
times that you travel on that highway with no traffic, and there are times when
you have to wait for some time to move forward. Now imagine, the vehicles on
the road exceed the capacity of the highway. The results will be frustrating to
the drivers; ultimately, drivers may choose to use alternative routes to
commute. To apply this analogy to mobile app development, you can image
the highway to be the app, and the app user is the driver.
To build a highway there are many components that the architects and
engineers consider before actually starting to build the physical structure.
Those elements vary case by case. For example, they must think about weather
conditions. The mixture of asphalt ingredients in a hot, dry location differ from
1 - 39
those ingredients that would be used in a cold, wet location. The curve of the
road and the incline dictate the roads banking angle. The purpose heavy
trucks or light passenger vehicles dictate different attributes. In addition, the
safety of the contractors and engineers plays a part as well. These concerns and
many others must be addressed in the planning and forecasting BEFORE the
road is build. Of course if a road going around a steep curve is build flat, and
then the speed limit increases, the road can be torn out and rebuilt with a
banked curve. But that would be time consuming, inconvenient and expensive.
The same applies with app development. You want to plan as much ahead of
time as possible so that you do not waste time and money, and in addition,
make your users frustrated.
Just as in road development, an app developer should consider many aspects
of development before beginning to create an app. Of course, some parts can
be done in parallel such as researching how to access a site for its data, but it is
easy to get involved in the details before the plan is clear. Beware of working on
implementation too early. Define objective, usage, market demographic and
scalability.
For app development, if you want your app to have the potential to be
monetized, you should, from the early days in your development process
anticipate the number of potential users and how fast that might increase. The
anticipation of this and other aspects of your app usage allows you to better
understand the environment your app will function in and be more prepared to
make adjustments, as they become apparent, based on usage. This approach is
important because it allows you not only to have consistency across different
aspects of your development, but also promotes consistency of user experience
in the future.
As the figure shows, scaling faster than expected, with no contingency plan in
place, can make you and your users very sad. This app did not scale well from
1 - 40
Security
In the beginning programming practices opened holes . . .
In 2008 2012 the world was waking up to the possibilities of mobile apps. As
with any new system, not all bases are covered in the initial stages. Security was
overlooked. This is especially easy to do in the beginning of the era of mobile
apps because companies had been protecting their data for years with stable
web applications allowing customers to access accounts securely. They did
not see that though the data is still on their secure servers behind virtual doors
that are well locked, access to that data can be circumvented when someone
opens the door in a way they hadnt envisioned. Additionally, they did not
envision the many ways that apps that work beautifully can leave their users
vulnerable in so very many ways.
In early 2014 the Starbucks app for paying for purchases was storing
passwords on device in clear text. That means that anyone who had physical
access to a device with a Starbucks app that had been set up could plug it in to
a computer and read the login information. Imagine if you automatically refill
your Starbucks card from a credit card. That credit card could be drained by
someone who had your login information and used it to buy themselves and
their friends daily coffee and food.
But Starbucks was not alone. At that same time early 2014 many mobile
banking apps were found to be insecure.
A security analysis of mobile banking apps for iOS devices from 60
financial institutions around the world has revealed that many were
vulnerable to various attacks and exposed sensitive information. See this
article to understand many vulnerability issues:
http://www.pcworld.com/article/2086320/security-analysis-of-mobilebanking-apps-reveals-significant-weaknesses.html
The article above specifically tested iPhones and iPads, but dont make the
mistake of thinking that only iOS is vulnerable. The operating system cannot be
held at fault when the app itself is programmed in such a way as to be
1 - 41
http://social.technet.microsoft.com/wiki/contents/articles/32288.windo
ws-enforcement-of-authenticode-code-signing-and-timestamping.aspx
Google has been executing its plan to phase SHA1 out since 2014
https://groups.google.com/a/chromium.org/forum/#!topic/securitydev/2-R4XziFc7A%5B1-25%5D
Currently SHA256 with RSA encryption is considered to be a good encryption
algorithm. Unfortunately, not all devices support this algorithm. Older Android
devices do not support SHA256 with RSA. (https://software.intel.com/enus/forums/intel-xdk/topic/622990) What this means is that, as long as the app
stores accept the older encryption algorithms, you must either submit your
apps with weaker encryption, or submit multiple versions of your app, one for
older devices and one for newer devices.
The app stores have begun to facilitate secure apps by providing tools and
testing areas for ensuring that your apps are secure. See: http://androiddevelopers.blogspot.com/2016/04/enhancing-app-security-on-googleplay.html
Just as with any new technology, security in mobile app development is
growing. As a developer you are responsible for protecting your users so that
they feel safe and want to continue using your app(s).
Support
Support is strongly tied to scalability. There are several subsections of support.
You may have a server that you need to ensure is available 24x7. Or you may
need to add another server as your user base grows. This was discussed in the
scalability section above. However, it is in the support area where you can
monitor user issues and be alerted early that you need another server. You may
need to answer user questions. Enabling users to tell you what is wrong can be
a very good way for you to find issues with your app. And finally, you will want
to monitor various types of usage. In addition to monitoring such things as
demographics (covered in Unit 10) so that you will understand your user base,
you will want to monitor usage criteria that will help you determine when to
expand and what users want.
First, 24x7 availability. If you provide a server to store data for your app you
must ensure that downtime is minimal. If that server goes down, you should
have a recovery plan. If your app is a game and that game is becoming popular
and your server is down for 3 months because your server died and you cant
afford a new one yet, you may lose valuable impetus in your game acquiring
customers. However, if this is the case and you communicate with the
customers to come back in 3 months so that they dont get frustrated with
1 - 43
failed attempts, you may recover. If your app is, on the other hand, a business
app then your success may be more dubious. Typically when a business
decision is made to use a new tool and that tool fails, business decision makers
find a different tool to satisfy their needs. Always be honest with users about
downtime, but try to avoid the issues in the first place.
Second, response time to users. You or a partner or an employee should be
able to respond to user questions or issues within a certain amount of time. You
can define that time as something close to 24 hours. Actually solving their
problem may take longer, but responding quickly to acknowledge their
problem makes them feel good like someone is listening. Which you are,
because you care about your apps success. Some types of responses would be:
Thank you, we were not aware of that problem. We will look at it and
get back to you. Then make sure you do get back to them.
Try double-tapping on that selection. It should work then.
That is a known issue. We are working on a solution. Meanwhile, the
workaround is to repeat the double tap.
One bad app review can outweigh many good reviews. For your users to feel
comfortable using your app, they must know that they can get help when they
have a problem.
Finally, a valuable mechanism by which you can support users is monitoring. If
you monitor usage increase you can plan when to add another server without
being blind-sided. You also might want to monitor other patterns like the
length of time it takes to start your app on various devices, or how long a user
uses your app without taking a break. Monitoring, this third piece of support,
will help you support your users in both of the first two pieces. Take a look at
the app stores to see which analytics they will provide you when your app is in
their stores. Then decide if you need more analytics. If so, find or build analytics
capturing that you can include in your app to give you the data you need.
Key words
Scalability
Security
Support
1 - 44
Unit summary
Unit review
15. What does scalability mean?
16. List two areas of security
17. What is good about encryption algorithms continuing to strengthen?
18. What is made more difficult in a developers work when encryption
algorithms continue to strengthen?
19. List three areas of support.
20. What is something you can do to be forewarned that you will need to
scale up?
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 45
Unit objectives
After completing this unit, you should be able to:
Key words
Unit summary
Unit review
Critique
Unit topics
1 - 46
1 - 47
Steps
Build your App for Distribution
1. Launch Intel XDK and open your MyButtons app.
2. Return to Intel XDK on your desktop.
3. Click the Build tab.
4-1a Build your App for Distribution (Android)
1 - 48
1. Go to PROJECT (upper left) Build Settings, click the iOS tab, click in
the Ad hoc Provisioning File box, the folder pop up appears, select
your provisioning profile and it will appear in the text box where you
clicked
2. Click the iOS build button
3. Click Upload Project
4. Click the Build App Now button and wait. This could take a few
minutes.
5. When you get the Successful Build message, type your email address
in the Recipient list and click send.
6. The built files will be sent in an email to you. An executable iOS app
has an ipa file extension.
7. On your iPhone/iPad, open the email, click the link, install the app.
Open it. Test it.
4-1c Build your App for Distribution (Windows 8+)
3. When you get the Successful Build message click the Download
button.
4. Save the zip file and extract it
5. Open the extracted folder
(mybuttons.cordova.windows8.someNumber)
6. Open the Test folder (CordovaApp.Windows_x.y.z.w_anycpu_Test)
7. Right click the ps1 file (Add-AppDevPackage.ps1), select Run with
PowerShell, answer the questions as needed to proceed until you get
to the Success message
8. After it is installed, search for the MyButtons app and click the app
icon to open it. Test it.
4-1d Build your App for Distribution (Windows Phone)
1 - 51
ARM/x86
apk/ipa/apx/appx/xap
Build settings
Launch icon
Splash screen
API
Unit Summary
Use the emulator for initial testing. But for thorough testing always
test your app on a physical device, preferably several, prior to
uploading to an app store.
You can email apk files to your users or post them to a web server.
App distribution for Android does not require uploading your app to
Google Play.
Unit review
1. Which of the main tabs in the Intel XDK would you use if you want to
create an executable app to install on a device?
2. Name one executable file extension for each of the following:
a
Android
iOS
Windows Phone
Apple will reject an app that has any element with a tap-able area
that is less than 44x44 points (though the element itself can be
smaller). (Points = pixels in a regular display, a point is half as wide as
a pixel in a retina display.) Look in the HIG here state the pixel size
for the launch image of an iPad2 when it is in the portrait position.
4. Describe the process for installing an apk file on a target device,
assuming the target already has access to the apk file.
5. Remember the two lines you added to hold portrait screen
orientation? Take a look at the methods and properties available the
cordova device plugin. Using those methods and properties write
pseudocode (since you may not yet know how to write conditional
statements in JavaScript) that will cause rotation if and only if the
screen rotation is in landscape mode.
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 53
Unit objectives
After completing this unit, you should be able to:
Unit topics
1 - 54
CDT allows you to inspect the DOM (Document Object Model) of your
application, review the HTTP requests, read the contents of cookies and
HTML5 local storage, and even provide hints as to how to optimize your
app's performance. Most importantly, it enables you to set breakpoints
and step through your code interactively while monitoring the contents of
variables.
Activate Debugger
1 - 55
Elements
Network
Sources
2016 Intel Corporation.
Timeline
Profiles
Resources
Audits
Console
Label
Description
Elements
Sources
Console
1 - 56
Steps
Practice using CDT in the emulator with the MyButtons app
1. Open Intel XDK this lab will take you back and forth between the
Emulator and CDT.
2. Open your MyButtons app from Unit 1
3. Go to the Emulator (click the Emulator tab at the top)
4. Click on the bug icon
as indicated by the arrow, Activate
Debugger. This will open a CDT window.
1 - 57
5. Arrange your Intel XDK window and your CDT window so that you can
see most of the emulator device and at least the left side of the CDT
window, like what is shown in the figure above.
4. In the debugger window, on the left side you should see the DOM. If
you do not, click the Elements tab.
5. Now click on the triangles
to expand the various parts of the
DOM. What we are interested in right now is the <div class=content>.
Expand that part and you will see the div tags for the two buttons.
6. One of the many powerful features of CDT is the mouse over feature.
After youve opened the content div and see buttonone and
buttontwo, mouse over (maybe youve figured it out intuitively, but
just in case you havent, to mouse over something means to pass
your mouse over an item on the screen without clicking) the HTML
DOM elements and watch the emulator view change. You should
see something similar to the figure above. When you hover over
(hover over means to hold the mouse still over something without
clicking) the buttonone line in the HTML code in CDT, your
emulator image in Intel XDK shows the elements boundaries and
tag.
Using this mouse over technique allows you to see which elements
in the UI are controlled by which elements in the DOM.
Right click on the buttonone line, select Break on, select Attribute
modifications (only if it does not already have a checkmark next to
it.)
1 - 58
Next, go to the Intel XDK emulator and press the top button in
your app device. It will look like the button is not working because
the breakpoint you set will pause execution right before the
button actually presses. The CDT debugger window should
automatically switch from the Elements tab to the Sources tab. If
this did not happen . . .
Troubleshoot tip #1: Check that the breakpoint is set: In
the Elements tab in CDT, right click on the buttonone line in
the DOM and select Break on. There should be a check
mark on Attribute modifications.
Troubleshoot tip #2: If Attribute modifications is checked,
yet the CDT window did not automatically switch to the
Sources tab, click on the Sources tab, in the window on the
right side open the DOM Breakpoints section (click the
triangle). Div#buttonone should be there but may be
unchecked check its check box. Now the breakpoint
should be set. Try clicking the top button back in the Intel
XDK emulator again.
8. After setting the breakpoint you will be looking at the Sources section
of CDT. There you will see that there are 3 windows: left, center and
right, with a 4th window, the console, open at the bottom. If the
console window is not open, find the hamburger icon
(usually top
right or bottom left of the CDT), and press it. It is usually useful to have
the console open to see messages and errors. We will look at this
window later in this unit. There are several things to notice.
First, the window on the left has its own set of tabs and should
default to Sources. So you should be in the Sources tab of the left
window which is in the Sources tab of the main window. Here you
can see the file hierarchy and open files.
1 - 59
9. Open the DOM Breakpoints section in the right hand window. You can
see that the breakpoint we set is on the buttonone div when one of its
attributes is modified.
10. Remember that at this point you have pressed the button in the
emulator and it did not change because the code stopped executing.
Now you will advance the code. You can use the debugger controls to
interactively step through your code. At this point, because you have
very little code, stepping through it is rather uninteresting. But later,
when you have more code, stepping through the code with a
debugger can be very helpful. Now press the Play button to resume
the script.
Using the debugger's step controls
1 - 60
Immediately you will see in the debugger that the file structure on the
left has disappeared and main.js is no longer in the middle window.
That is because this window shows the currently running code, but no
code is running.
NOTE: CDT is a third party tool that is embedded into the Intel XDK, Intel
did not create nor does Intel control the CDT.
WARNING: After hitting the play icon, your button should have released
and changed back to its original color and format. However, it may not
have done that. It is probably just fine. Do not assume it is broken. When
using CDT, there is debugger code that gets inserted amongst your code
and can interfere with the proper action of your app code. This is one of
the reasons you should test on device before publishing an app. Just like
any other system where a host and target are necessary, you are not
guaranteed to see all details of your app running precisely like they would
run in the real world, until you build and run on device.
Congratulations. You've just learned several ways to debug a mobile
app using CDT in the Intel XDK emulator!
End of Walkthrough
More on Breakpoints
You have already seen how you can set breakpoints with the CDT GUI, but
you can also set programmatic breakpoints by inserting the following
command into your JavaScript: debugger; wherever you want a breakpoint
set.
1 - 61
1 - 62
Steps
Use the CDT console and the console.log() function
1. Open Intel XDK, open your MyButtons project, open the DEVELOP
tab, open main.js, find the touchstarthandler function shown
below. This function sets the buttons className attribute to
pressed.
2. Add the following lines to this function after the className is set but
before the ending brace of the function.
for (var i=0;i<5;i++) {
console.log(i);
}
3. Save main.js (right click the filename in the left window, click Save; or
ctrl-S (cmd-S on Mac))
4. Go to the Emulator tab
5. Start the debugger (click the bug icon)
6. Make sure the Console window is open (hamburger icon)
7. Click either of the buttons you should see 0 4 printed, as shown.
1.
1 - 63
2. Add the debugger; line before the other code that you added so that
touchstarthandler looks like the following.
// Touch start functionality for the buttons
function touchstarthandler(event) {
var button= event.target;
button.className ="pressed";
debugger;
for (var i=0;i<5;i++) {
console.log(i);
}
}
3. Save main.js
4. Go to the Emulate tab
5. If CDT is already open, click the refresh icon
CDT, otherwise click the bug icon.
1 - 64
1.
In the CDT right hand window open the Watch Expression
section if it is not open by clicking the triangle next to it.
2. In the Watch Expression area click the + and type i in the box. It may
not be available at the moment, but when you click one of the
buttons in the Intel XDK emulator and start stepping through the
code you will re-enter the for-loop and i will then exist and have a
value.
Congratulations. You've just learned how to use the powerful CDT
console and how to set watch expressions!
End of Walkthrough
your device. You should have installed App Preview on your device already. If you have not, do
that now. The reason you need App Preview is because your app has not been built into an
executable program. Your app has its core pieces, but it needs some more parts to be able to
function as a full-fledged app.
Steps
Test your app via the Test tab
1. Ensure you have the latest version of App Preview installed on your
target device
2. In Intel XDK, open your MyButtons project
3. Click on the Test tab
4. Click on the PUSH FILES command and wait until the project is
uploaded
5. Open App Preview on your target device and log in with your Intel
XDK login. This takes you to App Center where your pushed apps will
be stored
6. Select your MyButtons project
7. It should open
8. Test it
End of Walkthrough --
1 - 66
1 - 67
CDT
DOM
HTML tag
Breakpoint
Mouse over/Hover over
Hamburger icon
console.log()
watch expression
debugger;
untethered
WEINRE
Unit summary
You can find the console and log messages there to track function
results and see variable values.
Unit review
21. How do you access the CDT window in the emulator?
22. Name the Intel XDK tabs where you can debug.
23. Name 8 things you can do to debug your code, for example, set watch
expressions in CDT.
24. What app do you need to download to use the Test Tab?
25. What does it mean to step over a function?
26. Which tabs could you use to test on device?
1 - 68
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 69
Unit objectives
After completing this unit, you should be able to:
Format a page with css using the <style> tag as well as in a separate
file via the <link> tag.
What is HTML5?
Best practices
Wrapping it up
Unit topics
1 - 70
What is HTML5?
When people say 'HTML5', they usually mean a bit more than just the 5th
version of the "Hypertext Markup Language". Modern web pages and web apps
are generally composed of at least three components, so what people
often mean when they say 'HTML5' is the trio of languages; HTML, CSS3 and
JavaScript.
The 'HTML' part contains all the content, organized into a logical structure. This
is the part that an author might be most concerned about; the words, chapter
headings, figures, diagrams, etc. While there have been numerous versions of
HTML since its inception (at least 5, I'd guess), our focus in this course is the
most recent version, HTML5. HTML5 was developed as an attempt to provide
more powerful and flexible ways for developers to create dynamic web pages.
The 'CSS' part (version 3 being current) is all about the presentation or style of
the page; what it looks like without too much regard for the specific content.
We'll be going into more detail on that later in this course, but for now think of
it as the way you might specify a "theme" in a word processing document,
setting fonts, sizes, indentations and whatever else may apply to what it looks
like.
The 'JavaScript' part is about the actions a page can take such as interaction
with the user, and customizing and changing the page according to any number
of parameters. This is what allows a web page to be more than just a document,
but potentially a Web App, with nearly unlimited possibilities. JavaScript is an
important leg of the stool for modern web pages.
1 - 71
That's the situation now, but in the beginning there was just HTML, defined by
Tim Berners-Lee. HTML, combined with the Browser, gave birth to the World
Wide Web.
HTML5 in industry
Remember the discussion from Unit 2 about the native approach vs. the cross
platform approach of creating mobile apps? Lets remind ourselves what that is
all about. If your app must to be super-efficient, they might decide it is best to
program natively. For the rest of us who dont have time critical apps (like
running an Electrocardiogram machine) and want to make our apps work on
multiple operating systems, i.e. iOS, Android, Windows, heres the deal:
If you are not familiar with mobile development you must learn the event loop,
and either
Objective-C, Java, and C# (you may swap Obj-C Swift and C# C++)
and on upgrades change three sets of code.
If you are familiar with mobile development and, say Objective-C, you need to
additionally learn either
HTML5 for the other two operating systems and change two sets of
code on upgrades, or
Again, because time to market is critical in the business world and many of their
developers already have HTML5 in their knowledge base, more and more
companies are turning to cross-platform development and HTML5.
A little history
Ironically, Tim Berners-Lee did not start out as a Computer Scientist, nor did he
initially envision what has become the World Wide Web.
No, he was initially a Physicist, having received a degree from Oxford. Working
under contract at CERN, he came across a problem to be solved. Given the
complex nature of high energy experiments, there were usually many scientists
involved in a given project, and efficient communication was needed to keep
everyone up to date and quickly spread information. He needed an easy way to
organize and track information, and share it among colleagues.
1 - 72
The sharing part was done using existing network technology (TCP/IP) but for
the organization of information he defined a new format based on the existing
concept of "Hypertext".
Hypertext is built on the idea of linking information together, not unlike using
footnotes, except much easier and more flexible. The idea was to "Mark Up"
your document with links and define how to break it down into different
segments (chapters, sections, paragraphs, tables, figures, etc.)
Thus in 1989, he began to create a definition of HTML: Hypertext Markup
Language.
He envisioned a technology that would facilitate thoroughly interconnected
documents. He wanted authors to be able to connect an idea in one document
to the source of the idea in another, or connect a statement with the data that
backs up that statement. Traditionally this kind of thing was done with
footnotes and bibliographies, which can be cumbersome. This information
should be easily transferable from one place to another, so that in reading one
document, it's easy to access everything related (linked) to it. Tim Berners-Lee
imagined a "Web" of interconnected documents.
<p>
It was the best of times, it was the worst of times, .
</p>
...
<p>
. . . it is a far, far better rest
that I go to than I have ever known.
</p>
</body>
If you eliminated everything in between the angle brackets from the text, for
most purposes it would still read the same:
A Tale of Two Cities
It was the best of times, it was the worst of times . . . .
...
1 - 74
Elements
If you're sitting at a coffee shop next to a table of web developers, you'll
probably hear three words quite a bit: 'Tags', 'Attributes' and 'Elements' (or
sometimes 'DOM elements', same thing just more precise and
wordy). 'Elements' are the pieces themselves, i.e. a paragraph is an element, or
a header is an element, even the body is an element. Most elements can
contain other elements, as the body element would contain header elements,
paragraph elements, in fact pretty much all of the visible elements of the DOM.
So, thats nice, but how do we represent elements in a text file? Well, thats
where tags come in.
Tags
Tags are what we use to organize a text file (which is just a long string of
characters) such that it represents a tree of elements that make up the html
document. Tags are not the elements themselves, rather they're the bits of text
you use to tell the computer where an element begins and ends. When you
mark up a document, you generally don't want those extra notes that aren't
really part of the text to be presented to the reader. By using '<' and '>' as a kind
of parentheses, HTML can indicate the beginning and end of a tag, i.e. it's telling
the browser this next bit is markup, pay attention. The line below is an example
of this.
<p>This is my first paragraph!</p>
<img src="https://goo.gl/pVxY0e"/>
There are a few strange tags that do not have open and close versions, such as
the second line above. We generally refer to these strange ones as self-closing
tags.
1 - 75
Attributes
Most of what we'll cover about attributes will come later, but I wanted to
introduce the idea briefly. Basically, a given element on your webpage can be
distinguished by any number of unique or common attributes. You can identify
it uniquely with an 'id' attribute, or group it with a class of other elements by
setting the 'class' attribute. Attributes in HTML are written inside the opening
tag like this:
<p id="paragraph-1" class="regular-paragraphs">
Call me Ishmael . . .
</p>
In this case I've given this paragraph a unique identifier, "paragraph-1" and
made it part of a class of "regular-paragraphs". The letters inside the quotes
have no meaning to the computer, they just need to be consistent. They're
actually strings, which as we will soon learn, if you want to have another
paragraph in this class, it has to say "regular-paragraphs", not "regular" or
"Regular-Paragraphs" or any other variation. Again, the fact that the computer
doesn't much care what we put in those strings (except for some restrictions)
means we can use them to convey meaning to a human developer. I could just
as easily have said id='x' and class='y', but anyone looking at that would have no
hint what the significance of x and y are. Best practice is to name these things
to increase clarity, consistency and brevity.
More about attributes later.
Comments
Computers are great at reading computer languages, but it's not always easy for
humans. Comments are a way of adding some text that is primarily targeted at
human readers. Below is a simple comment.
<!-- This is a comment -->
And if you want a comment to span several lines, mark the beginning and
ending like in the following.
<!-If you want some good advice,
Neither a borrower nor a lender be,
For loan oft loses both itself and friend,
And borrowing dulls the edge of husbandry.
1 - 76
-->
Comments are also used to comment out code when you have lines that you
want to keep, but dont want to display at the moment, like the following.
<!-- Not sure if I want this wording or not:
<p>Eighty seven years ago, a bunch of guys started a new country</p>
-->
It is important to know that just as HTML, CSS and JavaScript are three different
languages, they each have their own way of indicating comments. This might
seem confusing, but it is actually kind of important that the HTML comments, at
least, differ from the others. As for the exact form of those other comments, we
will cover that in good time.
This is a very light introduction to HTML. There are some other critical tags, like
<div> that you should learn if you are going to program in HTML5. There are
many resources where you can learn more, including free online resources to
find some go to a browser and search use search terms like learn html5.
1 - 77
Steps
What happened?
Copy the contents of the index.html file into a text editor on your
host machine, like TextEdit or Notepad, save as test.html, close
the file, go to your file explorer and double click the file name.
Because you saved it with an html extension it will open in a web
browser (unless you have tweaked your extension options).
You can do some tricks to make the title appear, but for now just
state briefly a probable reason why the title does not show.
Congratulations. Now you can create a valid HTML document!
End of Lab
Best practices
The wisdom of our forefathers is in the simile, and my unhallowed hand shall
not disturb it.
- Charles Dickens
I love it when my kids ask lots of questions and challenge my
assumptions. Except sometimes. While it's a great sign of a curious and
reasoning mind, it can be overwhelming, and you can't really learn (or teach)
everything at once. Some things are better to be taken on faith in the short
term, until you fully understand the issue.
That brings up a term you might hear quite a bit in this class: Best practice. It's
often said that bad programs can be written in any language, and I can verify
from personal experience that's true (at least in every language I've
learned). Over time, developers learn that some habits are better than
others i.e. that some habits tend to make a program more readable and easier
to understand and maintain than other habits, It could also be about
1 - 78
performance, i.e. in a given language doing a particular task may be faster one
way than another.
To borrow an example from another profession, if you want to hammer a nail,
it's best to do it in as few strikes as possible (e.g. 2 or 3). That may not be
obvious to non-handy people like me, but I've been assured that's the best way
by people with a lot more experience than I, so I'll take it on faith (at least for
now).
In truth, there is a certain amount of subjectivity where best practices are
concerned. New techniques are discovered, new ideas are born, and
sometimes, fashions change. For our purposes and the duration of this
course, when we use the term "best practice" you can trust that it is, even
though we may not be able to explain it at that point in the course, so you'll
want to make it a habit.
1 - 79
Using CSS we can determine the visual appearance of our HTML elements
independent of the HTML itself.
Recall the metaphor we used for HTML with the journalist and the publisher.
Where HTML represents the author's work, CSS corresponds to the work the
designer does: deciding how things look.
In the early days, there was no CSS, so any control over what the page looked
like was done with tags that controlled the form of the webpage. Tags like 'font'
to choose a font, 'b' for bold, 'i' for italic, &c. were added to have some control,
lest your page be at the mercy of whatever browser the reader was using. There
are several problems with this approach. First, it violates our paradigm of HTML
containing only content. Second, and more practically, the tags only applied
where they were used. For instance, if you originally wrote your document with
all of the paragraphs indented a certain amount and then later you were
decided to change the indentation then you would have to modify every single
paragraph in your document. It would be nice if there were a central way to set
such rules, i.e. one place that said "I want all my paragraphs to be indented this
much", much like master sheets in a word processor. CSS helps to solve this
problem.
Let's see CSS in action. Below we see two identical copies of HTML. But styled
differently.
Here is the HTML:
<p>She looked over the top of her book and whispered
<q>I'm pregnant.</q>My heart stopped.<p>
And now two very different looks:
Both of these use the exact same HTML. It is the CSS that makes them so
different. So let's get started.
1 - 80
CSS tags
<style> tag
The best practice when working with CSS is to keep it in an external file using
the <link> tag, but when starting it is simpler to merely place it directly into the
document under edit.
To place CSS directly into an HTML document, we use the <style> tag. This tag
can appear anywhere in an HTML document, but the most common practice is
to place it in the <head>. Like so:
<!DOCTYPE html>
<html>
<head>
<style>
/* CSS will go in this area */
</style>
</head>
<body></body>
</html>
This line above, /* CSS will go in this area */, is a comment discussed below.
<link> tag
While <style> is convenient, the better practice is to put the CSS into a separate
file. One of the key advantages of using a separate file is that the CSS styles can
easily be re-used between your different .html pages. Another advantage is that
when you are changing your content you dont accidentally change the style, or
vice versa. Many authors further divide their CSS up into different files (for
example one for text styles, one for layout).
Simply put your CSS into a separate file. This file does not need any HTML
markup (ie, no <style> tag required). Use the .css file extension and use
a <link> tag to bind it in. The <link> tag must appear in the <head> section. By
convention, css files are kept in a directory named css.
Use <link> to specify your css file:
1 - 81
Best practices
CSS is a set of rules in curly braces, such as:
p{font-size: 12px; line-height: 15px; }
BUT . . . even though it the above rule set works just fine as is, best practices
dictate that putting each rule on a separate line is better:
p{
font-size: 12px;
line-height: 15px;
}
It is easier to find and read when separated onto different lines and indented as shown.
Comments
CSS comments are different from HTML comments. Comments in CSS are
placed between /* and */, such as:
p{
font-size: 8px; /* client insists small text makes them more 'professional'. */
/* I hope his idea of 'professional' includes paying on time. */
line-height: 24px; /* see above */
/* none of the stuff below is working. I don't know why.
1 - 82
margin-top: 5%;
margin-bottom:6%;
*/
}
CSS properties
There are hundreds of CSS properties. A complete list is here:
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
Below are just three of the most useful and common CSS properties.
FONT-SIZE
font-size can be used to size the text of a tag. The value for the font-size has
two parts: a number and a unit. Some of the most common units
are: px, em, %, vh . For example:
p { font-size: 18px; }
q { font-size: .8em; }
blockquote { font-size: 10vh; }
LINE-HEIGHT
1 - 83
Whereas font-size may drive the size of the text itself, the line-height property
drives the height of the space it is drawn into. A large line-height will give the
text more spacing. A small line-height will smash the text lines together.
For example, all of the Middlemarch text below has font-size:16px; But on the
left we see line-height:8px; and on the right, line-height:30px;
line-height supports the same units that font-size does ( px, em, %, vh, etc)
MARGIN
We will examine layout in a later unit. But the margin property is the lynch-pin
for positioning elements. Whenever you want to move something a little the
margin property should be your first thought. When having layout problems, it
is the first thing you should check.
The margin can be a bit confusing. Depending upon context, it will space an
item away from its immediate neighbors (in the HTML) or from the edges of its
parent. Also, there is not only one margin property, but 5:
p { margin: 10px; } /* a 10 pixel margin will be applied around all four sides of the item */
p{
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;
margin-bottom: 10px;
}
em
'em' is a typographic term that has come to the web. On the web, em units are
usually used for vertical dimensions. One 'em' maps to the height of one capital
letter in the parent context.
p { font-size: 0.9em; } /* text in a paragraph tag is smaller than its parents */
h1 { font-size: 1.2em; } /* but an h1 will be bigger than the parent */
i { font-size: 0.5em; } /* and any italicized text will be half as big. */
All the text sizes above are relative to the pages base size. You'll see radically
different results on the rest of the page from either of these rules applied to the
body, but relative to one another they'll remain sized correctly.
html, body { font-
size: 50px; } /* 50
size: 20px; } /* 20
rem
'rem' is much like 'em'. But while 'em' sizes an element relative to its parent,
'rem' always derives its size relative to the root. In an HTML document with lots
of nested elements, 'rem' will generally prove to be more reliable than
'em'. rem is supported in all modern day browsers, including mobile. But not
older ones.
Using the CSS rules from the em section immediately above, nested paragraphs
(<p>one<p>two</p></p>) would get increasingly smaller. But if rem units were
used, they would be the same size.
Note to ensure you are setting the root size,
use both the html and body selectors.
html, body { font-size: 20px; }
%
Whereas em is a measure relative to the parents text size, the percentage unit
(%) is relative to the parent dimension. This is a useful unit for both horizontal
and vertical dimensions, though often more useful in the horizontal.
p{
margin-left: 10%;
margin-right: 10%; /* 10% of parent width will be spent on the two side margins */
}
Initially, the percentage unit may seem very handy (and it is), and many
developers fall in love with it. But the love affair is usually short lived. One of
the limitations of this rule is that for it to work correctly, the parent must have
an explicit width or height set. This limitation is particularly noticeable in the
vertical dimension. If the parent element doesn't have an explicit height set
then child percentages may be percentages of 0.
1 - 85
vh / vw
'vh' stands for viewport height, and 'vw' for viewport width. The vh and vw units
work much like the percentage ( % ) unit. But instead of percentage of the
parent, it is percentage of the screen (aka viewport). Obviously, vh is for vertical
dimensions, and vw for horizontal dimensions.
vh and vw do not suffer the parent limitation that the % unit does. Most
modern browsers support these units, but there are some exceptions on older
mobile browsers.
p{
margin-left: 10vw;
margin-right: 10vw; /* 10% of screen width will be spent on the two side margins */
}
<!DOCTYPE html>
<html>
<head>
<title>A Poem</title>
<style> /* CSS */ </style>
</head>
<body>
<h1>A Lover</h1>
<address rel="author">Amy Lowell</address>
<p>If I could catch the green lantern of the firefly
<br> I could see to write you a letter.
</p>
</body>
</html>
1 - 86
spacing rules, the other should contain any rules governing font faces or
coloring. Bind both into your HTML document. Note: to add a file, right
click on the folder where you want to create the new file, in the menu popup
select New File.
In the HTML below, there are two paragraph tags. So to style them individually
we can apply unique id attributes to the paragraphs. ( id="p18" and id="p19" ) In
the CSS, we will use the id selector. The id selector is indicated by a hash sign
(#) followed directly by the id.
CSS:
#p18 { color: blue; }
#p19 { color: green; }
HTML:
<p id="p18">He is Ulysses, a man of great craft, son of Laertes. He was born in rugged
Ithaca, and excels in all manner of stratagems and subtle cunning.</p>
<p id="p19">Madam, you have spoken truly.</p>
Result
CLASS SELECTOR
The class attribute is similar to the id. But, whereas the id must be unique and
singular, the values of the class attribute can be shared by multiple tags. And,
multiple classes can be assigned to a tag by simply separating them with
spaces.
HTML
<ul>
<li class="bird flying">eagle</li>
<li class="bird">ostrich</li>
<li class="insect">ant</li>
<li class="insect flying">moth</li>
</ul>
The class selector is simply a period (.) followed by the class name itself.
CSS
1 - 88
Result
eagle
ostrich
ant
moth
.
Being able to define a CSS selector in terms of a tag, class or id is very powerful.
But it's not practical to classes on every tag in your document, much less to put
unique ids throughout. It's also inconvenient to constantly repeat CSS
rules. But by combining composing selectors all that can be avoided.
Separate
blockquote {
color: red;
font-style: italic;
}
q
{
color: red;
font-style: italic;
}
.speech {
color: red;
font-style: italic;
}
joined
blockquote,
q,
.speech {
color: red;
font-style: italic;
}
The joined version on the right is much easier to read and maintain.
1 - 89
If the "speech" items need to also be bold, that can simply be added by an
additional rule:
blockquote,
q,
.speech {
color: red;
font-style: italic;
}
.speech { font-weight: bold; }
SPECIALIZED SELECTORS
If two selectors of different types (like tag and class) appear next to each other
with no spacing separating them, then they form a specialized selector. To
match a candidate must match both rules. If a tag selector is used, it must
appear first.
This is most useful with class and tag selectors, like so:
blockquote.speech { font-color: green; }
html
css
result
<ul>
.insect.flying {
parrot
text-decoration: underline;
ostrich
<li class="bird">ostrich</li>
font-weight: bold;
ant
<li class="insect">ant</li>
wasp
moth
airplane
1 - 90
<li class="flying">airplane</li>
</ul>
Adding functionality
As you have seen, with HTML and CSS you can make very nicely formatted
views for your mobile apps. As you move forward designing your views it is
important to keep aesthetics in mind. There is just one more thing. You need
your app to react to the user: to perform actions based on such things as touch,
text entry or data calculations. For this we need JavaScript. In the remaining
1 - 91
sections of this unit you will experiment with various JavaScript commands and
see how to incorporate JavaScript with HTML and CSS.
Lab 6-5 b: Change text with lines of code in index.html, but now with the click of a
button
Change text using the HTML <button> tag, invoking JavaScript with the onclick event, again,
directly in index.html
1 - 92
Steps
1. Use the Blank Cordova Starter App again, either the one you created in 6-5
a, or create another one
2. In index.html paste the following two lines of code just above the ending
</body> tag (if you are using the same project as in 6-5a, you can paste this
new code either above or below the other code)
<h1 id="id1">My Heading 1</h1>
<button type="button"
onclick="document.getElementById('id1').style.color = 'red'">
Change Color</button>
3. Save the file and emulate
a. What happened?
b. Was it what you expected?
That was super simple, right? Changing text formatting and using buttons is really easy.
Unfortunately, those two examples use bad JavaScript design.
PAUSE
3. Before we continue, lets check something out . . . do you see that
class=align-center? You learned about the CSS classes earlier in this unit.
What if I suddenly want everything left justified? How would I turn off those
centers?
a. First, emulate to see what is centered, then look at the code and
make sure it matches (where ever there is an align-center the text
or button is centered)
b. Then comment the <link> tag line that is at the bottom of the
<head> section
c. Now, emulate.
d. Okay, after all your oohs and ahhs, uncomment the <link> if you
want things centered again.
UNPAUSE
4. Now go to the app.js file in www/js
5. Paste the following function anywhere in that file (not inside the other
function) this part colors the text red
// called when change color button is pressed
function myEventHandler2() {
document.getElementById('id_headerTxt').style.color = 'red';
}
6. Now go to the init-app.js file in www/js and paste the following lines near
the bottom of the initEvents function under the NOTE:s this part invokes
the coloring function
// button changes header text color
var colorElement ;
1 - 94
colorElement = document.getElementById("id_btnColorChg") ;
colorElement.addEventListener("click", myEventHandler2, false) ;
7. Voila! Save all the files and emulate.
That was crazy complex. Why, you might ask, couldnt all the JavaScript code go in app.js. That
is a nice, friendly place it even says this is a place for your code. Well, you could try that.
Maybe it will work, maybe it wont. It didnt work for me. The reason it didnt work for me is
because my DOM was not finished creating itself before my code attempted to attach the
handler to the button. If the button doesnt exist yet, the code will fail to attach any handlers
to it because that button doesnt exist and then the button wont work. The app just wasnt
ready. The app will still work, but the button action cant happen.
This app-not-ready reality is why we started with this more complicated Blank sample
(instead of the Blank Template, which is much simpler). This Blank app has the parts in place
to verify that both the DOM (all your elements) and the Cordova (all the document stuff) are
both ready. Otherwise you could try to do something that fails because some part is not ready
yet.
The initEvents function in the init-app.js file is a safe place to put any function invocations
because initEvents is invoked after all the code in www/xdk/init-dev.js makes sure that
everything is ready. You can look at the init-dev.js file and see what bits and pieces are
checked for readiness things such as Is the Window loaded? Is the device ready? And so
on.
in it. If your code accesses the data and it has nowhere to be placed, then you
end up with a nicely drawn table with nothing in it.
Dog
Woof
Cat
Meow
Cow
Moo
Adding the appropriate JavaScript conditions and checks will ensure that things
happen in order.
<div id ="myContainer">
<div id ="myBox"></div>
</div>
<script>
function myMove() {
var elem = document.getElementById("myBox");
var pos = 0;
var id = setInterval(frame, 5);
function frame() {
if (pos == 350) {
clearInterval(id);
} else {
pos++;
elem.style.top = pos + 'px';
elem.style.left = pos + 'px';
}
}
}
</script>
2. Save the file and emulate
a. Test the button.
b. What happened?
c. Was it what you expected?
3. Now change the design to match best practices techniques.
a. Remember, the <style> code is CSS and should go into a css file (put
it in app.css), then add a <link> tag, if one does not already exist, to
incorporated the css file, as you learned in the CSS tags section
earlier in this unit.
b. Arrange the other code as you learned in Lab 6-5 c and practiced in
Lab 6-5 d.
Wrapping it up
The information here about HTML5 is very sparse just to give you a taste of
what it looks like and how the pieces, JavaScript, HTML and CSS, work together.
Much of this is learned best by doing, but it is also important to have resources
to help guide you. There are many resources available. The w3schools site is
great because it is set up for you to try out samples on the spot to see what
happens without having to run your code externally. edX has some very good
6-week courses, many free, that you can attend online to learn more about
HTML5. You will learn a lot as you create apps.
1 - 98
Unit summary
You read about web apps in Unit 2. Now you should be able to grasp
the idea a bit better. A web app refers to an application (like a mobile
app) that (usually) runs in a mobile devices native web runtime (NOT
in a web browser). A web app uses web technologies. A wholly native
app, on the other hand, does not use a devices web runtime, it
communicates directly with the operating system of the device and
uses the native API.
1 - 99
There are many, many tags. Only a few of which are covered here. This
unit is intended to give you a good start in HTML5, but dont hesitate
to keep learning.
With respect to CSS, id can only be used once, class can be used many
times.
Unit review
27. What does a slash indicate in the following context - </p>?
28. What tag would you use to make a bulleted list (not numbered)?
29. Why are best practices important?
30. Which selector is indicated by a hash sign?
31. Which selector is indicated by a dot?
32. Explain the functionality of each line of the following statements. (If
you arent sure, revisit lab 6-4).
a
b
c
d
width: 400px;
position: static;
background: green;
background-color: green;
33. There are four values for the css position property: static, relative,
fixed and absolute. Explain why, in activity 4, the myContainer position
is relative and myBox position is absolute.
34. If you have an app.css file, how would you turn it off?
35. What characters do you use for commenting in:
a HTML?
b JavaScript?
c CSS?
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 100
Unit objectives
After completing this unit, you should be able to:
Unit topics
1 - 101
Create 3 pages, each with 2 buttons. The top button goes to the next
page (with page 3 advancing circularly to page 1). The other button
invokes an alert that says something different for each page.
Windows* Note: The Windows* Webview does not implement the
HTML alert() message. So here is a way to work around that limitation
in Windows*:
1. Include this line before any other lines that include JavaScript
in the <head> section of the index.html file: <script
type="text/javascript" charset="utf-8" src="lib/xdk-win8xcompat.js"></script>
2. Add xdk-win8x-compat.js to your set of JavaScript files.
Go to GitHub: https://github.com/xmnboy/xdk-win8xcompat.js/tree/master
On the right side, below the thick yellow line is a
Download ZIP button. Click it.
After downloading, extract the files and add the js file to
your js folder, usually in www/js or www/lib.
Read the README file to understand how to create the
alert message.
Congratulations. You have created pages and alert messages!
End of Lab
1 - 104
Key words
.
App Designer
App Framework
Controls/Controls Layout/Controls Buttons/
Widget/Element
Properties/Properties Pane
Style
Interactivity Pane
DOM Tree View
Grid View
Media Queries
Sidebar/Kitten
Page
Alert/popup
Code view/Design view
Unit summary
App Designer allows you to create the GUI part of your app without
using code.
Though App Designer has some features that allow you to add
functionality to your widgets without using any JavaScript, these
options are very limited. For most functionality you need to use code
to control your widgets.
You can add a custom script to a widget Intel XDK will automatically
switch to Code view for you
An animated sidebar is a view that slides into view and partially covers
your current view, usually giving you some options until you select
something and then it goes away
The DOM view shows your GUI view structure (the structure imposed
by the tags)
1 - 105
Unit review
36. What is a framework and how do the various frameworks differ?
37. In which folder should you add images?
38. After creating at least one extra page, look at the DOM tree in Design
view in the Pages section and compare that to the DOM structure in
the index.html page. (To find the code that pertains to the new page,
search (ctl-F) for uib_page.) Notice that it is the div tag that creates
the page in HTML.
39. True or False You must create your GUI with App Designer.
40. In which section will you find the button widget? Controls, Pages,
Themes or Properties You can find out by selecting and deselecting
each of these sections to see when the
disappears.
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 106
Unit objectives
After completing this unit, you should be able to:
What is an API?
Unit topics
1 - 107
Screen orientation
It is often the case that the layout for a particular application is more feasible in either portrait
or landscape view, but not in both. In this case you will want to lock your orientation so that
the user cannot change it. In order to do this, you will add some code and add a plugin.
Steps
Setting and locking screen orientation
For more fun with screen orientation learn how to set, change and lock the screen
orientation: see this documentation.
What is an API?
API is a very commonly used term in the software world. It stands for Application
Programming Interface. It is the set of commands that you would use to gain access to
someones software. Okay, fine . . . but what does that mean?
Plugin APIs
Well, for mobile app plugins the software you are accessing as stated earlier is a translation
mechanism from JavaScript to the native language for a target device. You include the
plugin and use the command you want, like with the screen rotation you would use
device.setRotateOrientation() to change the orientation or device.orientation() to check what
the orientation is.
1 - 110
Replace the index.html file with the file below that contains file I/O
functions.
Add the file core plugin to your project.
Test your app on your device.
o Store a line of text:
Write to a file
Save the file
Clear the entry from the text box
Read the file you should see what you wrote
reappear in the text box
o See what happens when you write to the file several times.
Make the app more secure and more easily debuggable by moving
the JavaScript out of the index.html file. Refer back to Unit 6 if
necessary.
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1, userscalable=no">
<script src="cordova.js"></script>
<script>
document.addEventListener("deviceready", function(){
}, false);
function writeFile(){
window.resolveLocalFileSystemURL(cordova.file.dataDirectory, function(dir){
dir.getFile("log.txt", {create: true}, function(fileEntry){
fileEntry.createWriter(function(fileWriter){
fileWriter.seek(fileWriter.length);
fileWriter.write( document.getElementById("text").value + "\n");
alert("file written");
}, function(error){
alert("Error: " + error.code);
});
}, function(error){
alert("Error: " + error.code);
});
1 - 111
1 - 112
End of Lab
1 - 113
Steps
Setting and locking screen orientation
4.
5.
6.
7.
8.
9.
This function will invoke the Apache* Cordova Camera API and
update the image in the app if a photo was successfully captured
using the mobile devices camera.
1 - 114
There are many plugins available. Some of the more popular ones are directly available
through simply selecting them in Intel XDK like you did for the File plugin. But there are many,
many more written by many people. Be sure when you are adding a plugin that it will do what
you want. If you want to target both Android and iOS, either be sure that your plugin choice
will work for both, or find one plugin for Android and another for iOS. Also, make sure you get
the version that does what you want and works on the target devices you are interested in.
Sometimes a plugin will work for Android 4.3 for example, but not for 4.1 or 4.2. Any plugin
can be added via the Intel XDK plugin manager. You just need to know where to find it.
1 - 115
Key words
.
Plugin
Screen orientation
Plugin API
Third-party plugin
Unit summary
For any features that require native code development, you can use
plugins instead of learning how to work with native code for each
target operating system
Know which testing features will work with your app based on which
plugins you are using.
http://www.html5rocks.com/en/tutorials/geolocation/trip_meter/
http://www.codeproject.com/Articles/811068/Exploration-withIntel-XDK
Unit review
43. Name two things a plugin does.
44. State the basic steps you should follow to add a plugin.
45. What does the onDeviceReady() function do? Why is it important?
46. Give an example of a plugin API call and state its purpose.
47. Can you debug apps with third party plugins in the Debug tab?
1 - 116
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 117
Unit Objectives
After completing this unit, you should be able to:
Unit Topics
1 - 118
Add the <script> from the Test tab onto all html pages that you need to remotely
debug.
For remote debugging in the Test Tab to work properly, you must:
1 - 119
You can inspect the browser's DOM, review network traffic, review
runtime errors, and even interact directly with the app through the
debugger's Console view.
1 - 120
Use the WEINRE debugger via the Test Tab to step through code in
your app running on a physical device
Steps
Use the Test Tab for remote debugging
Steps
Configure your iOS or Android device for remote debugging (Windows and
Windows Phone devices cannot be used with the Debug tab at this time)
3.
4.
5.
6.
1 - 122
To help you decide on the optimum debug option, see the following list.
Note that some of the options in this list may not make sense until you
read the rest of this document.
If you are debugging on Android, use:
The Emulate tab for basic JavaScript logic and approximate layout
The Debug tab for accurate Crosswalk behavior (including thirdparty plugins)
"debuggable" equal "true" with remote CDT for very accurate
behavior (esp. with third-party plugins)
The Test tab with Intel App Preview and WEINRE * (for everything
but third-party plugins)
WEINRE with a built app (esp. with third-party plugins)
The Emulate tab for basic JavaScript logic and approximate layout
The Debug tab for accurate behavior (for everything but third-party
plugins)
Web Inspector Remote with a OS X for very accurate behavior (esp. with
third-party plugins)
The Test tab with Intel App Preview and WEINRE (for everything but thirdparty plugins)
1 - 123
The Emulate tab for basic JavaScript logic and approximate layout
The Test tab with Intel App Preview and WEINRE (for everything but third-
party plugins)
WEINRE with a built app (esp. with third-party plugins)
1 - 124
Unit Summary
WEINRE offers a way to test and debug apps with 3rd-party plugins.
Unit Review
48. Where do you find information guiding you on which testing methods
to use?
49. What are your testing options if you create an app with 3rd party
plugins for Android? What if you want to expand to Windows targets?
50. Explain why you would want to use the Emulator for debugging.
51. State 4 criteria you would consider when deciding whether to test in
the debug tab or in the emulator debugger.
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
1 - 125
Unit objectives
After completing this unit, you should:
Monetizing options
Key words
Unit summary
Unit review
Critique
Unit topics
IoT - 126
Social Benefit
Some people want to make apps for a living, but they also are very
interested in helping to make the world a better place. Someone who has
had a weight problem may develop an app to help people lose weight. A
personal trainer who loves her job may have a great idea for an app that will
match peoples habits with an exercise program that works for them. A math
teacher who has great success with a game to help students understand
how to solve quadratic equations wants to create and app to share this
game with other students.
These people might create their apps and not charge. Or they might charge
later. Or they might not charge but include health or education ads. More
about the monetizing options later.
Example Several apps require users to commit to exercise or healthy
eating habits. Those who meet their commitments get paid. Those who do
not meet their commitments pay. And the app creator gets paid.
Brand Loyalty
If you already have a company and need to get the word out about how
great your company is, you might create a game app that tells the story
about your company. If you have a company that is well known, you might
create an app that will draw people to your product.
Example most big name athletic shoe companies have created free apps
to track exercise statistics. Some require you to buy a device that works with
IoT - 127
the app. Others do not require you to buy anything, but allow you to select
your particular shoe if it is one of their products and then track how many
miles you have on each shoe you use.
Revenue
Maybe you just want to make some money. In this case it is essential to
think about the future of the app and monitor it as time goes on to
determine what if any changes should be made. You may try a monetizing
method that doesnt work as well as you had hoped, so you can alter the
monetizing method or you can alter the app. Either way, track your changes
and the market response to your changes so that you can make informed
decisions.
Awesome App
Maybe you just have fun developing apps and want to create something you
think is really fun or really useful. You can create it and just put it out there.
Or after making it available in the app stores, you track it and notice that it is
doing really well. As you watch its progress you may come up with a
different idea and get excited about trying the new idea and comparing the
market reception of the two ideas.
Monetizing options
Finally! How do I make money . . . ?
You can make money directly or indirectly. You can use a single method or
mixed methods. You can entice with a free app, then start charging for it later.
No matter the method(s) you as you should always be planning 3-5 years out.
Whether you stick to your plan or alter it along the way, having a plan helps you
visualize what might happen and also makes you more aware of how you are
progressing over time.
Paid apps
You can charge for your apps up front. Most apps are very low cost with
developers hoping to gain income from a large number of sales.
Ads in apps
You can charge nothing for your app up front and include ads. Each time a
user sees an ad, money is added to your account in the store. Ads can be
banner ads that can continue on the top or bottom of the view during the
IoT - 128
time that the user is using the app, or they can be intersitial ads which ocupy
the entire window in between game levels or other pauses.
In-app purchases
You may not charge and not include ads but have in-app purchase options.
These are often used in games to allow the user to advance more quickly or
gain more power or gain access to more levels. In order to reduce negative
comments so that your app remains in the top listed apps in the stores, you
may allow users to buy a higher level of functionality while still allowing
those who dont pay to continue full use but at a slower rate. For example,
users may automatically get 5 free lives per day in a game. They may
purchase more or wait to continue playing until the next day. Games like this
are quite popular. You do not want to generate disgruntled users because
then your app is less likely to be seen in the stores as it generates negative
ratings.
Mixed methods
Many apps combine monetizing methods. The app may be very inexpensive
but also offer in-app purchases. Or an app might be free and have banner
ads and in-app purchases. A way to entice users is to have a basic app that
is free and then charge for fuller functionality in a business app or more
game levels in an entertainment app.
Know that about 90% of consumers will not buy anything and a consumer who
buys once is likely to buy again market to that demographic.
IoT - 130
Discoverability
Build in discoverablity. Discoverability is the measure of how easy it is for
users to find your app.
One way to increase this measure is to ensure that your app
has high visibility in searches. In 2014 the major app stores
started indexing apps this means that your app will be
identified more appropriately, but only if you market it
correctly. For example, when you submit to an app store be
sure to choose the correct catagories, i.e. Game, Children,
Shopping, etc. In addition to developers actively choosing
catagories, the app stores are improving their ability to help users figure out
which apps to buy. They may classify apps as amateur vs. professional
based on such things as the apps documentation and quality. Thus, as
important as it is that your app function well, it is equally important that you
have a clean UI, good UX and good documentation.
Retention
Getting new downloads is great. However, a high number of downloads in
your first week followed by a high number of uninstalls in your second week
will be detrimental to your revenue. You must focus on retention.
IoT - 131
Dont release before your app is ready, even if you have to delay a bit. An
on time release of a business app that adds incorrectly will kill the app,
whereas delaying the release to fix the bug is often not a big issue.
Dont make a game so hard that the player dies before the user gets the
purchase offer. This seems obvious, but has happened at least once to a
big-name gaming company. Ensure that your marketing and sales are
incorporated appropriately.
Over time introduce new and exciting components. For a business app
use trending colors. For a game add levels, add items and/or add
background or music options.
Send one message only. Imagine you have a great app for people who
love movies and your app also renders images in the most amazing 3D
ever. If you market with both of these messages, someone who wants a
movie app may only notice the 3D message and have no interest in that.
Decide what is most important and make that your message.
Purchasing Psychology
User: Why would I want to buy that?
A person might not consciously think this when looking at a product, but
people are constantly weighing their options. They look at the item and
often want it, then they look at the price and decide if it is worth it. What can
you do to make users think that is it worth it to buy your products your
apps and your in-app purchases?
There are several sales gimmicks that marketers use to sell products. One is
having a sale lowering the cost for a limited time. Clothing stores have
sales. Grocery stores have sales. They do this either to move a product
quickly, or to entice people into their stores. This is not new. It has been
tried and tested in one version or another for thousands of years. Well, for
apps this does not work. Based on history having proven that lower costs
draw people and move products, it is counterintuitive that sales ultimately
reduce revenue. Over the last few decades it has be shown that if there is a
sale in an app, users will no longer pay full price. They will wait for the next
sale. So the first sale will help move product quickly and bring in revenue
i.e. in-app purchases will go up during the sale period, but after the sale,
users wont buy. So revenue drops. They are now expecting a sale. This is
called sale-hangover.
But there are methods that do work.
IoT - 132
Prototype
Build a prototype early. Just as you would storyboard to ensure you have a
good storyline or process flow, prototype to make sure your app works as
you expect.
Sprites and other images you dont need to wait until your artist
creates your images to create your layouts. Create placeholder sprites
circles or rectangles work fine to see whether your views are over
crowded or placement is aesthetically pleasing.
Technical interaction maybe you know that you are planning to create
an app with a large number of views as well as using web services to
fetch data. Good software design process incorporates reducing risk. If
you spend most of your planned development time completing the
design and implementation of your views yet have not tested the web
service you will be using, you might run into a snafu late in the process
that increases your time to market which can impact your revenue. To
reduce risk be sure to test features and interactions as early in the
process as you can.
Playtest
IoT - 133
Use people who have never seen it otherwise testers will already know
the flow and not find parts that may not be intuitive.
You may discover issues in several areas.
o Performance maybe data download takes too long in a certain
part of your app so you will need to rearrange your code to run
some parts asynchronously.
o UI Design maybe you have put controls in the area where
peoples hands cover, so they cannot easily reach those controls.
o UX Design maybe you have the process flow out of order. Your
financial app requests details for a transaction before allowing
you to name the transaction so that if a user is interrupted by a
phone call and comes back to where they left off, they cant
remember what transaction these details belong to. Or your
game allows you to choose items to buy without letting you see
the cost, causing you to waste time on items you cant afford.
Know the game play habits of your targetted demographic. Intel XDK is
primarily targeted at mobile app creation. So if you are reading this, you
are likely creating. In that case it is wise to know that a large percentage
of mobile apps are played/used in 30-60 second increments. We can
call this the standing-in-line entertainment/productivity phenomenon.
As you can see, there are many aspects to think through as you develop your
business strategy and work through creating your app. You may have also
noticed that many of the aspects of business strategy cross over into app
design territory. You dont want to bog down your business plan with a lot of
detail about app design, however it is good to be aware of anything in your
design that may inhibit the desirability of your app as you walk through your
business plan.
Dont let yourself get bogged down with planning details, but do spend some
time each day or each week laying out one more piece of your plan until it is
complete, thereafter reviewing it occationally. Also test the parts of your app
that are least understood so that you move forward productively and have your
surprises early in the process rather than later when there is less recovery time.
IoT - 134
An example: your app is a card game. You offer a set of 5 cards for $2.
Those cards turn out to be very powerful. But then future sets of cards for
the same price are not nearly so powerful.
It is okay to have offers with varying value, just as long as you make the
value proposition clear. If your offering is more powerful, advertize it as
such a one-time only, very powerful set such as a starter deck or a high
value booster pack. Make it clear that you are not tricking the user.
Steps
Introduction
Jessi has a great idea for the game action and a general idea of how the
user will interact with the game, but before she can fully design the app
she needs to make some business decisions. She calls her app
HelpTheBabies!
Name this object:
IoT - 135
1
2
1
17
91
3
1
16
91
15
91
4
1
14
91
15
13
91
12
91
6
1
7
1
10
9
91
1 8
1
11
91
Game play involves connecting dots to form an image, with the challenge
being the users choice of either minimum time or minimum number of
connections needed to name the object. When the image is identified
correctly, the user will be rewarded with gold coins and a Did you know?
window will pop up with a tidbit of information to help babies in some way.
Purpose of the app
Jessi is still in high school and supported fully by her parents. She has some
spending money from her part time job at Bubble Car Wash. She does not
need to make money, but would like to have more spending money.
However, she really wants to help people, so she decides to create an app
that is free and has in-app purchases.
Scope
Though the details of scope are more of an app design topic than a part of
the business plan, it is good to state top level scope in your business plan to
help you stay focused.
Jessi knows she wants it to atract adults so that they will be informed,
thereby helping to prevent problems in babies. She also wants to market to
the soccer-mom demographic (the parent, dad or mom, who runs errands
and transports the kids) those parents who have 5-10 minutes of
downtime several times during the day when they would want to occupy
their time for a few minutes at their kids soccer practice, in line at the
grocery store, at the post office, at DMV, waiting for a dental appointment.
So a game level must conclude within about 3 minutes, but also reliably
stores play progress if the game is suspended by the phone ringing or by
getting called in to see the doctor.
Integrate M&M and Keep it fresh
The app will be free, and there will be in-app purchases. Users earn gold by
identifying the item. Users can choose to buy additional gold that will allow
IoT - 136
the user to play for longer periods of time, advancing more quickly, much
like purchasing health points.
In version one of HelpTheBabies the gold coins will allow the user to
advance levels. In version two there will be genre options to select from
fruit, mountains, house pets, etc., each costing a number of coins.
The color scheme will change twice/year according to the current fashion
trends. In version two, as well as some genres that are purchasable
indefinitely, there will be a quarterly offer of a genre that will never be
available again.
Incorporate analytics to track download numbers, user demographics and
game play frequency
Monetization
Version 2
Demographic
Freshness
Timeline
This is Jessis first iteration of her business plan. Like any business person, she
will continue to evaluate her plan and make adjustments as time goes on. She
IoT - 138
will remember to review game progression when she makes changes to insure
that she does not inadvertently make any unclear value propositions.
IoT - 139
Key words.
Banner ad
Interstitial ad
In-app purchase
Target audience
Demographic
Durables/consumables
Discoverability
Pirate
Retention
Fraud
Unclear value proposition
Unit summary
Purpose in creating an app clearly define why you are doing this.
Establish your goals early.
App design:
Prototype and playtest make sure the app really is useable the way
you think it is
Unit review
52. Name three reasons for creating apps.
53. Name three ways to monetize an app.
54. Why would you want to determine your target audience? Give a
counter example.
55. List three goals for your strategic plan.
56. List three items in an app that would likely be durable
IoT - 140
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
IoT - 141
Unit Objectives
After completing this unit, you should be able to:
Useful notes
Key words
Unit summary
Critique
Unit Topics
IoT - 142
Hardware
IoT - 143
Software
IoT - 144
Become familiar with the hardware and software that will be used in
this unit to create IoT apps
Learn how to connect the various cables and hardware to the board
Steps
Create a New Project
1.
Download and unzip a copy of the project Weather Lamp from
https://github.com/gomobile/sample-weather-lamp/ to a convenient
place on your host machine. If you havent used github before, that is
okay, you dont need to sign up, just click on the Download button and
download the ZIP file.
2.
3.
Instead of Start a New Project, this time click the Open an Intel
XDK Project button
4.
In the window that popped up, locate the Weather Lamp project
that you unzipped. Select the file with the .xdk extension.
IoT - 145
7.
To complete modification of the location information, now go to
the index.js file to modify the time zone. At or around line 270 you will
see the time zone for Los Angeles, CA, as shown below. If that is your
time zone, no need to change anything. Otherwise change it to your
city by finding the appropriate city code in
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
var time =
moment.tz("America/Los_Angeles").format("HH:mm"); //will
need to change here
IoT - 146
9.
Now connect your LEDs to the three PWM pins of your Base
Shield. These are the D3, D5 and D6 sockets on the Base Shield. In the
sample project the LEDs are configured as green on D3, red on D5 and
blue on D6.
10. After you have connected the LEDs power up your IoT board
using the wall adapter. And connect your USB cable from your
IoT - 147
11. Now that your board is wired, you need to set up the network
connections. See detailed instructions for your host OS:
a. Windows*: https://software.intel.com/en-us/setting-up-serialterminal-on-system-with-windows
b. OS X*: https://software.intel.com/en-us/setting-up-serial-terminalon-system-with-mac-os-x
c. Linux*: https://software.intel.com/en-us/setting-up-serial-terminalon-system-with-linux
IoT - 148
This will open the Wi-Fi menu where you can select the network you
would like the target (board) to connect to. Follow the prompts to
configure and connect your Intel Edison Wi-Fi. When successfully
connected a message like the following will display.
Done. Please connect your computer to the same network
as this device and go to http://10.0.157 or
https://myedison.local in your browser
The name of your Intel Edison device may be different from what is
shown above. Log this IP address for reference later. You will need this in
Intel XDK later to connect host to device.
NOTE: For an in-depth explanation of how to set up your Intel Edison WiFi connection, read this Intel Developer Zone tutorial
https://software.intel.com/en-us/connecting-your-intel-edison-boardusing-wifi - it describes alternative methods of connecting to Wi-Fi, as
well as how to connect using an alternative operating system.
NOTE 2: If you ever need to check the IP address of your board, use the
following command in your serial connection (PuTTY or Terminal):
root@Edison: configure_edison showWifiIP
IoT - 149
Useful Notes
Time is already configured in the app. If you want to understand the
formatting process and why it is necessary, read on.
Weather Underground returns time in a particular format (hh:mm). Current
time is formatted in a different way when called on (hh:mm:ss). To be able
to compare the times correctly you must put the two different times into
the same format (either hh:mm or hh:mm:ss). Below are some
explanations that will help you understand that part of the code in case
you ever want to compare time in another app.
1. Moment Timezone There is a dependencies section in your apps
package.json file with moment-timezone details. It should look like the
following.
IoT - 150
"dependencies": {
"express": "^4.13.3",
"moment": "^2.10.6",
"moment-timezone": "^0.5.0",
"superagent": "^1.3.0"
}
add
Subtract
isAfter
isBefore
isSame
format
Note that hh gives 12 hour time (am/pm) and HH gives 24 hour time.
4. If you would like to read further documentation on both moment and
moment-timezone take a look at the following websites
a
http://momentjs.com
http://momentjs.com/timezone/
IoT - 151
Key words.
IoT
Device app
Companion app
Edison/Galileo
Breakout board
Base Shield
LED
SSH Client
Weather Underground
Wi-Fi
PuTTY/Terminal
IP Address
Git Hub
Unit Summary
You can use Intel XDK to create apps for IoT devices.
Unit Review
1.
2.
3.
4.
Think of an IoT use. What would it be? What data would it access
from what site(s)? What hardware would you use?
IoT - 152
Critique
Please take 1-2 minutes to answer survey questions to give feedback so
we can improve this course. Please keep in mind that it is intended as a
beginners course.
IoT - 153