Esempio n. 1
0
    def test_login_token(self):
        particle_user = os.environ['PARTICLE_IO_USER']
        particle_password = os.environ['PARTICLE_IO_PASSWORD']

        particle = pp.Particle(particle_user, particle_password)

        try:
            particle = pp.Particle(access_token=particle.access_token)
        except Exception, error:
            self.fail("Failed with %s" % error)
Esempio n. 2
0
class Control:
    particle = pp.Particle(access_token=os.getenv('PARTICLE_ACCESS_TOKEN', ''))
    lock = False

    def process_start(self):
        pass
#       res = self.particle.call_function('3d0024000c47353136383631', 'power', 'on')

    def process_stop(self):
        pass
#       res = self.particle.call_function('3d0024000c47353136383631', 'power', 'off')

    def process_request(self, req):
        print(self.lock)
        if self.lock:
            return {'status': 'failure', 'request': req}
        else:
            #self.lock = True
            res = {}
            if req['state'] == "true":
                try:
                    ## TODO: strip device id and grab the req.device_id variable. requires change to iphone client.
                    res = self.particle.call_function(
                        '3d0024000c47353136383631', 'dir', 'right')
                except Exception as e:
                    print(e)
            self.lock = False
            return {'status': 'success', 'request': req, 'response': res}
Esempio n. 3
0
    def test_list_devices(self):
        particle_user = os.environ['PARTICLE_IO_USER']
        particle_password = os.environ['PARTICLE_IO_PASSWORD']

        particle = pp.Particle(particle_user, particle_password)

        try:
            devices = particle.list_devices()

            if len(devices) == 0:
                self.fail("Failed: no devices found")
        except Exception, error:
            self.fail("Failed with %s" % error)
Esempio n. 4
0
    def test_function(self):
        particle_user = os.environ['PARTICLE_IO_USER']
        particle_password = os.environ['PARTICLE_IO_PASSWORD']

        particle = pp.Particle(particle_user, particle_password)

        device = particle.list_devices()[0]

        try:
            result1 = particle.call_function(device['id'], 'set_led', 'on')
            result2 = particle.call_function(device['id'], 'set_led', 'off')

            self.assertEqual(result1, 1)
            self.assertEqual(result2, 0)
        except Exception, error:
            self.fail("Failed with %s" % error)
Esempio n. 5
0
import asyncio
import _thread
from sseclient import SSEClient

# reference to URL with published events
# 'catHere' is the name of the event being published
messages = SSEClient(
    'https://api.particle.io/v1/events/catHere?access_token=PARTICLE_ACCOUNT_TOKEN'
)

# reference to command listener,
# also specifies prefix to issue bot commands '.'
client = commands.Bot(command_prefix='.')

#  reference to particle account - should be change to new token
particle = pp.Particle(access_token='PARTICLE_ACCOUNT_TOKEN')

#  reference to list of devices linked to particle account
devices = particle.list_devices()
# particle photon is only device linked, therefore at index 0
device = devices[0]
# print to confirm correct device selected
print('Selected device: %s' % device['name'])

# location of cat
isInside = True
# set to false to prevent continous listening
keepListening = True
# when startStatus != IsInside, the cat has been detected
startStatus = True
Esempio n. 6
0
# -*- coding: utf-8 -*-

import pyparticle as pp
import sys
import os

# Read the access token stored in a file
current_dir = os.path.dirname(__file__)
token_filename = os.path.join(currenr_dir, 'access_token.txt')

access_token_file = open(token_filename, 'r')
access_token = access_token_file.read().strip()
access_token_file.close()

# Initiatise the Particle object using the cache access token
particle = pp.Particle(access_token=access_token)

try:
    devices = particle.list_devices()
except:
    # An exception has been raised indicating that the access token is out of date use the login details to refresh the token
    particle = pp.Particle('username', 'password')

    # Cache the token for reuse
    access_token_file = open(token_filename, 'w')
    access_token = access_token_file.write(particle.access_token)
    access_token_file.close()

    devices = particle.list_devices()

if len(devices) == 0:
Esempio n. 7
0
import json
import os
import pyparticle as pp
from flask import Flask, request

from server.control import Control

c = Control()

app = Flask(__name__)
access_token = os.getenv('PARTICLE_ACCESS_TOKEN', '')
particle = pp.Particle(access_token=os.getenv('PARTICLE_ACCESS_TOKEN', ''))


@app.route('/')
def hello_world():
    return 'Hello, World!'


@app.route('/api/camera', methods=['GET'])
def hello_heidi():
    user = request.args.get('user')
    device_id = request.args.get('device_id')
    object_detected = request.args.get('object_detected')
    access_token = request.args.get('access_token')
    devices = particle.list_devices()
    print('Found %d device(s)' % len(devices))
    print(user)
    r = c.process_request(3)
    #particle_result = particle.call_function(device_id, 'led', 'off')
    #print('Water plant result: %s' % water_planet_result['return_value'])
Esempio n. 8
0
    def test_login_invalid_details(self):
        particle_user = '******'
        particle_password = '******'

        with self.assertRaises(pp.LoginError):
            particle = pp.Particle(particle_user, particle_password)
Esempio n. 9
0
    render_template,
    redirect,
    request,
    url_for,
)

import pyparticle as pp

load_dotenv()
app = Flask(__name__)
app.secret_key = "ssssh don't tell anyone"

AUTH_TOKEN = os.getenv('AUTH_TOKEN')
DEVICE_ID = os.getenv('DEVICE_ID')

particle = pp.Particle(access_token=AUTH_TOKEN)
devices = particle.list_devices()
device = devices[0]


def get_sent_messages():
    # TODO: Make this return a collection of messages that were sent from the number
    messages = []
    return messages


def send_message(to, body):
    # TODO: Send the text message
    pass