element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Particle
  • Products
  • Dev Tools
  • Single-Board Computers
  • Particle
  • More
  • Cancel
Particle
Blog How to Build a Cross-Platform IoT Mobile App with NativeScript and Particle
  • Blog
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Particle requires membership for participation - click to join
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: brandonsatrom
  • Date Created: 14 May 2019 8:53 PM Date Created
  • Views 523 views
  • Likes 2 likes
  • Comments 38 comments
  • particle
  • nativescript
  • mobile app
  • iot
Related
Recommended

How to Build a Cross-Platform IoT Mobile App with NativeScript and Particle

brandonsatrom
brandonsatrom
14 May 2019

image

When you set out to build a connect product, it's easy to put all your focus on choosing the right development board, great sensors, and cost-effective PCB design. These are big choices and contribute to your product success or failure, but none impact how your customers will interact with your product directly. At least, not as much as your product's mobile app will.

 

Your mobile app is how people will use your product and interface with all of the low-level technical decisions you've made. Don't let it be an after-thought in your design. Here's an example of how you can use NativeScript, a popular open source framework for building truly native apps using JavaScript.

 

The NativeScript Particle Plugin

NativeScript is a framework for building 100% native, cross-platform mobile apps that allows you to leverage JavaScript, TypeScript, Angular, and Vue.js. It lets you build a single cross-platform app for both iOS and Android using the languages and frameworks that you and your developers are already comfortable with.

 

NativeScript also has a vibrant plugin ecosystem, and I figured that a Particle plugin would be a welcome addition to the marketplace. So I called up my friends Rob Lauer and Eddy Verbruggen, and asked if they'd be willing to create a NativeScript plugin for Particle, in exchange for a few Photons. They readily agreed, and Eddy unveiled the NativeScript Particle plugin just a few weeks later. It’s now possible to use the Particle iOS and Android SDKs in NativeScript apps, meaning that cross-platform IoT mobile apps are now far easier to build than ever before!

 

How the Plugin works

One of the things I love most about Particle's iOS and Android Device Cloud SDKs is the fluent programming style they enable. Rather than hand-rolling HTTP requests and callbacks on my own, I can use these SDKs to facilitate user login, fetch devices, call cloud functions, and more, all with just a few lines of code.

 

The NativeScript plugin embraces this fluent-style and gives me the ability to create a single JavaScript codebase that talks to the Particle iOS and Android SDKs. I can import dependencies and login to the Device Cloud.

import { Particle, TNSParticleDevice } from "nativescript-particle";
const particle = new Particle();

particle.login(

  {
    username: "me@domain.com",
    password: "super-secure-pw"
  })
  .then(() => console.log("Login successful"))
  .catch(error => console.log(`Login error: ${error}`));

I can also fetch devices and call functions.

particle.listDevices()    .then(devices => {      devices[0].callFunction("digitalWrite", "D7", "HIGH")        .then(result => console.log(`Result: ${result}`))        .catch(error => console.log(`Error calling function: ${error}`));    })    .catch(error => console.log(`Error fetching devices: ${error}`));


And more. If our SDKs support it, the plugin can do it. In JavaScript. What a time to be alive.

After the plugin was published, I cloned the
GitHub repo for the plugin and was quickly able to get the demo app running. I logged in with my Particle account, found one of my devices running the PartiBadge firmware and called a few cloud functions. It ran smoothly in both an emulator and on my phone, a testament NativeScript's power as a JavaScript-powered framework for building truly native apps!

image
The NativeScript Particle Plugin controlling a PartiBadge[/caption]

Where to go to learn more

If you're building IoT Mobile apps, I highly recommend taking NativeScript for a spin. To get started, visit the website, where you can explore the tool using an online interactive playground, or install the CLI tools, locally.

 

Once you have NativeScript up and running, you can explore its integrations with Angular, Vue, and TypeScript using the online documentation. And if you're looking to leverage NativeScript to control your Particle devices, make sure you check out the official plugin docs in the NativeScript marketplace.

  • Sign in to reply
  • iram1998
    iram1998 2 days ago

    Your blog brings me a great deal of fun. Good luck with the site.

    christmas lighting jupiter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • iram1998
    iram1998 12 days ago

    Great Article it its really informative and innovative keep us posted with new updates. its was really valuable. thanks a lot

    carpet junk removal palm beach county

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • iram1998
    iram1998 23 days ago

    I was exactly searching for. Thanks for such a post and please keep it up.

    lean six sigma new mexico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • iram1998
    iram1998 24 days ago

    I was exactly searching for. Thanks for such a post and please keep it up. 

    lean six sigma for fayetteville businesses

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jacon12
    Jacon12 27 days ago

    Your post has those facts which are not accessible from anywhere else.

    tennessee lean six sigma certification

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

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

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

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

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

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube