All Projects β†’ EddyVerbruggen β†’ Nativescript Particle

EddyVerbruggen / Nativescript Particle

Licence: apache-2.0
πŸ•Ή Control your https://particle.io devices from NativeScript

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Nativescript Particle

Docs
Documentation for Particle
Stars: ✭ 131 (+589.47%)
Mutual labels:  particle, iot
Device Os
Device OS (Firmware) for Particle Devices
Stars: ✭ 976 (+5036.84%)
Mutual labels:  particle, iot
Particle Cli
Command Line Interface for Particle Cloud and devices
Stars: ✭ 208 (+994.74%)
Mutual labels:  particle, iot
Particle Api Js
JS Library for the Particle API
Stars: ✭ 112 (+489.47%)
Mutual labels:  particle, iot
Gort
Command Line Interface (CLI) for RobotOps
Stars: ✭ 425 (+2136.84%)
Mutual labels:  particle, iot
Dot Dom
.dom is a tiny (512 byte) template engine that uses virtual DOM and some of react principles
Stars: ✭ 757 (+3884.21%)
Mutual labels:  iot
Thingsboard Gateway
Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
Stars: ✭ 796 (+4089.47%)
Mutual labels:  iot
Pigpio
Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi
Stars: ✭ 747 (+3831.58%)
Mutual labels:  iot
Swupdate
Software Update for Embedded Systems
Stars: ✭ 711 (+3642.11%)
Mutual labels:  iot
Awesome Ttn
A curated list of awesome things related to The Things Network
Stars: ✭ 18 (-5.26%)
Mutual labels:  iot
Paho.mqtt.embedded C
Paho MQTT C client library for embedded systems. Paho is an Eclipse IoT project (https://iot.eclipse.org/)
Stars: ✭ 887 (+4568.42%)
Mutual labels:  iot
Sitewhere
SiteWhere is an industrial strength open-source application enablement platform for the Internet of Things (IoT). It provides a multi-tenant microservice-based infrastructure that includes device/asset management, data ingestion, big-data storage, and integration through a modern, scalable architecture. SiteWhere provides REST APIs for all system functionality. SiteWhere provides SDKs for many common device platforms including Android, iOS, Arduino, and any Java-capable platform such as Raspberry Pi rapidly accelerating the speed of innovation.
Stars: ✭ 788 (+4047.37%)
Mutual labels:  iot
Zmninja
High performance, cross platform ionic app for Home/Commerical Security Surveillance using ZoneMinder
Stars: ✭ 762 (+3910.53%)
Mutual labels:  iot
Raspberrymatic
🏠 A lightweight, buildroot-based Linux operating system alternative for your CCU3, ELV-Charly or for running your IoT "HomeMatic CCU" as a virtual appliance (using ESXi, Proxmox, VirtualBox, Docker/OCI, Kubernetes/K8s, Home Assistant, etc.) or on your own RaspberryPi, Tinkerboard, etc. SBC devices...
Stars: ✭ 803 (+4126.32%)
Mutual labels:  iot
Raylib
A simple and easy-to-use library to enjoy videogames programming
Stars: ✭ 8,169 (+42894.74%)
Mutual labels:  iot
Mqttx
MQTT X - Elegant MQTT 5.0 Client Tool of Cross-platform
Stars: ✭ 892 (+4594.74%)
Mutual labels:  iot
Contiki Ng
Contiki-NG: The OS for Next Generation IoT Devices
Stars: ✭ 710 (+3636.84%)
Mutual labels:  iot
Volantmq
High-Performance MQTT Server
Stars: ✭ 785 (+4031.58%)
Mutual labels:  iot
Hslcommunication
An industrial IoT underlying architecture framework, focusing on the underlying technical communications and cross-platform, cross-language communication functions, to achieve a variety of mainstream PLC data reading and writing, to achieve modbus of various protocols read and write, and so on, to support the rapid construction of industrial upper computer software, configuration software, SCADA software, factory mes system, To help enterprise Industry 4.0 take-off, to achieve intelligent manufacturing, smart factory goals. The main PLC contains Siemens, Mitsubishi, Omron, Panasonic, Modbus, AB-PLC, Redis
Stars: ✭ 816 (+4194.74%)
Mutual labels:  iot
Pytradfri
IKEA TrΓ₯dfri/Tradfri API. Control and observe your lights from Python. Examples available. On pypi. Sans-io.
Stars: ✭ 778 (+3994.74%)
Mutual labels:  iot

NativeScript Particle plugin

NPM version Twitter Follow

Particle.io logo

Prerequisites

Hop on over to the Particle.io store and order any or all of their cool devices.

While developing this plugin and the demo app I used a Photon Kit and it was a joy to work with.

Thanks, Brandon Satrom for sending one over!

Installation

tns plugin add nativescript-particle

iOS 12+ setup

iOS 12 and up requires you to enable 'Access WiFi Information' for your App ID here.

Also, add this to your App_Resources/iOS/app.entitlements (mind the name!) file:

<key>com.apple.developer.networking.wifi-info</key>
<true/>

The demo app has this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>com.apple.developer.networking.wifi-info</key>
  <true/>
</dict>
</plist>

Demo app

If you want to just play with your Particle device without writing code yet, follow these steps to install the demo app I've created with NativeScript Core:

git clone https://github.com/EddyVerbruggen/nativescript-particle
cd nativescript-particle/src
npm i
npm run demo.ios # or demo.android

Tip: If you get tired entering your login credentials every time you log in, set the PARTICLE_USERNAME and PARTICLE_PASSWORD properties to reflect your own.

Want to see the demo in action? Check out this short video πŸ“Ί.

API

All examples below assume you have these imports and instantiated the Particle class:

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

startDeviceSetupWizard

To help registering devices to your account (and avoid having to use the Particle CLI) you can add devices to your account right from your app! 😎

particle.startDeviceSetupWizard()
    .then(isSuccessful => console.log("Wizard success? " + isSuccessful));

login

Communication between your app and a device is HTTP (REST) based, so the first step is authenticating yourself with the Particle Cloud:

particle.login(
    {
      username: "[email protected]",
      password: "my-particle-password"
    })
    .then(() => console.log("Login successful"))
    .catch(error => console.log(`Login error: ${error}`));

loginWithToken

Alternatively, you can login with an access token.

particle.loginWithToken("the_token");

logout

Once done interacting with your device(s) it's best to log out as this will do a little cleanup in the plugin and underlying SDK.

There's no reason not to because it couldn't be easier:

particle.logout();

publish

Publish an event from your app to the Particle Device Cloud.

particle.publish(
    "ledStatusApp123", // the event name
    "ON", // the event data (string)
    true, // isPrivate (default true)
    30 // ttl (default 60)
);

subscribe

Subscribe to the firehose of public events, plus the private events published by devices one owns. You really want to use a unique prefix, otherwise you'll receive a lot of data (not only from your own devices!).

particle.subscribe(
    "ledStatusApp123",
    (event: TNSParticleEvent) => console.log(`Got a ledStatus event for App 123 from the Particle Cloud: ${JSON.stringify(event)}`));

unsubscribe

To stop receiving published events, unsubscribe from the events. Make sure the prefix is equal to the one you previously subscribed with.

particle.unsubscribe("ledStatusApp123");

listDevices

Make sure you've claimed a device in your Particle account, then do this to list them in your app:

particle.listDevices()
    .then((devices: Array<TNSParticleDevice>) => {
      if (devices.length === 0) {
        console.log("No devices have been claimed in this account.");
      } else {
        console.log("Devices fetched.. now do something neat with 'em.");
      }
    })
    .catch(error => console.log(`Error fetching devices: ${error}`));

The returned list of TNSParticleDevice objects has these properties and functions:

Property Type Description
id string The unique ID of this device.
name string The given name of this device.
status string The current status of the device, usually normal.
connected boolean Whether or not the device is currently connected..
type TNSParticleDeviceType One of Unknown, Core, Photon, P1, Electron, RaspberryPi, DigistumpOak, RedBearDuo, Bluz.
functions Array<string> The list of functions currently available on the device. You can invoke these with callFunction (see below).
variables Array<TNSParticleDeviceVariable> The list of variables currently available on the device. You can get their values with getVariable (see below).

<device>.rename

You can change the device name right from your app! πŸ’ͺ

const myDevice: TNSParticleDevice = null; // you got this from 'listDevices'

myDevice.rename("rocket_bubble")
    .then(() => console.log("Device renamed"))
    .catch(error => console.log(`Error renaming the device: ${error}`));

<device>.callFunction

You can invoke any of the functions you discovered on the device.

As an example let's assume you've flashed this code tutorial to your device, so there's a led function which takes 1 argument: the value must be either "on", or "off":

const myDevice: TNSParticleDevice = null; // you got this from 'listDevices'

myDevice.callFunction("led", "on")
    .then(result => console.log(`Result: ${result}`))
    .catch(error => console.log(`Error in callFunction: ${error}`));

What if you have a function which takes multiple arguments? Let's assume you're using the tinker app and want to set "D7" to "HIGH" via the "digitalWrite" function:

myDevice.callFunction("digitalWrite", "D7", "HIGH")
    .then(result => console.log(`Result: ${result}`))
    .catch(error => console.log(`Error in callFunction: ${error}`));

<device>.getVariable

Getting a variable is quite similar to callFunction.

Let's say you have a variable named "analogvalue", then this will give you the current state of that variable:

const myDevice: TNSParticleDevice = null; // you got this from 'listDevices'

myDevice.getVariable("analogvalue")
    .then(result => console.log(`Result: ${result}`))
    .catch(error => console.log(`Error in getVariable: ${error}`));

<device>.subscribe

You can get notified in your app in case an app on one of your devices publishes an event.

To suppress noise you can filter those events by supplying a prefix, in this case my-prefix-, so events like my-prefix-temp or my-prefix-sensorOn are caught:

const myDevice: TNSParticleDevice = null; // you got this from 'listDevices'

myDevice.subscribe(
    "my-prefix-",
    (event: TNSParticleEvent) => console.log(`device event: ${JSON.stringify(event)}`));

<device>.unsubscribe

To stop receiving published events from your devices, unsubscribe from the events. Make sure the prefix is equal to the one you previously subscribed with.

myDevice.unsubscribe("my-prefix-");

<device>.unclaim

Removes this device from your account.

myDevice.unclaim();

Thanks!

markoImake for adding a few very cool features.

Happy IoT'ing! πŸ•ΉπŸ€–πŸšͺπŸ–²πŸ’‘πŸ“ΈπŸŽ™β›ˆπŸš¦πŸ›ŽπŸ”Š

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].