Skip to main content

Simple python wrapper over wirelesstags REST API

Project description

WirelessSensorTags Build Status Coverage Status PyPI - Python Version PyPi - Version

A simple python wrapper library for Wireless Sensor Tag platform (http://wirelesstag.net).

Supports getting data for registered by end user sensor tags. wirelesstag.net account credentials are needed to use this lib. Enabling tags sharing is not required.

Verified with:

  • 13-bit motion/temperature/humidity tags (type 13)
  • Water/Moisture tags (type 32)
  • ALS Pro tag (type 26)
  • PIR Kumo sensor (type 72)

Installation

pip3 install wirelesstagpy

Development notes

See apidoc.html for API details.

Usage

Fetch all tags

import wirelesstagpy

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
tags = api.load_tags()
for (uuid, tag) in tags.items():
    print('Loaded tag: {}, temp: {}, humidity: {} probe taken: {}'.format(
                tag.name, tag.temperature,
                tag.humidity, tag.time_since_last_update))

Install custom push notifications

Wireless Sensor Tags platforms allows to setup custom url calls for set of specific events.

import wirelesstagpy

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
notifications = [
    NotificationConfig('update', {
        'url': 'http://some_local_ip/update_tags',
        'verb': 'POST'
        'disabled': False,
        'nat': True
    })
]

# install notification for tag with id=1 only
# use it you have only one tag manager
succeed = api.install_push_notification(1, notifications, False)

# if you have multiple tag managers you need specify its 'mac' stored in each tag as following
succeed = api.install_push_notification(sensor.tag_id, notifications, False,
                                        sensor.tag_manager_mac)

Monitor push events from cloud

Wireless Sensor Tags platform allows to monitor state of sensors with push notification on change right from cloud.

import wirelesstagspy

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
def callback(sensors):
    print("updated sensors: {}".format(sensors))

# starts long running thread with getting updates from cloud immidiately when change happens.
# it is not a polling, but rather a similar to WebSockets get update logic
api.start_monitoring(callback)

Arm/Disarm sensor monitoring for specific event

Supported events include: motion, temperature, humidity, light

import wirelesstagpy

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')

# arm humidity monitoring for tag with id 1,
# returned instance is updated SensorTag
sensor = api.arm_humidity(1)

# Disarm it
sensor = api.disarm_humidity(1)

# Specify tag manager if you have multiple tag managers
sensor = api.arm_humidity(sensor.tag_id, sensor.tag_manager_mac)

Working with sensors and binary events

Single tag holds notion of multiple sensors and binary events. Each sensor is entity representing single sensing metric such as temperature, humidity, moisture, light or motion. You can get list of supported sensors and binary events by calling tag.allowed_sensor_types for sensors, tag.supported_binary_events_types for binary events. Also you can query tag on list of supported monitoring conditions that can be represented as switches to be armed/disarmed by calling tag.allowed_monitoring_types.

Handling sensors:

import wirelesstagpy
import wirelesstagpy.constants as CONST

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
tags = api.load_tags()

# get temperature sensor value for tag
for (uuid, tag) in tags.items():
    sensor = tag.sensor[CONST.SENSOR_TEMPERATURE]
    if sensor is not None:
        print('{} temperature: {}'.format(tag.name, sensor.value))

Handling binary events:

import wirelesstagpy
import wirelesstagpy.constants as CONST

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
tags = api.load_tags()

# get motion binary event state for each tag
for (uuid, tag) in tags.items():
    if CONST.EVENT_MOTION in tag.supported_binary_events_types:
        event = tag.event[CONST.EVENT_MOTION]
        print('tag {} event state: {}'.format(tag.name, event.is_state_on))

Use binary events to build custom push notifications configurations

import wirelesstagpy
import wirelesstagpy.constants as CONST

api = wirelesstagpy.WirelessTags(username='login_email', password='your_password')
tags = api.load_tags()
tag = tags['uuid-of-tag-in-question']
event = tag.event[CONST.EVENT_MOISTURE]
if event is not None:
    configs = event.build_notifications('http://path_to_post', tag.tag_manager_mac)
    # install it for any tags of tag manager
    succeed = api.install_push_notification(0, configs, True,
                                            tag.tag_manager_mac)

Disclaimer

"Wireless Sensor Tags", "KumoSensor" and "Kumostat" are trademarks of Cao Gadgets LLC, see www.wirelesstag.net for more information.

I am in no way affiliated with Cao Gadgets LLC.

Copyright

See LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wirelesstagpy-0.5.0.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

wirelesstagpy-0.5.0-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file wirelesstagpy-0.5.0.tar.gz.

File metadata

  • Download URL: wirelesstagpy-0.5.0.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/56.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.4

File hashes

Hashes for wirelesstagpy-0.5.0.tar.gz
Algorithm Hash digest
SHA256 91baa57b0266b851568cf9915f18da1a89087dc5ad80f1cde62e3f11ed7cb3b4
MD5 8eb7f9c7805c013139482acfe2e5e7af
BLAKE2b-256 9f152ff70d16400ce960392545ac7cf643abbc825b830fb7f42e19d69002efd8

See more details on using hashes here.

File details

Details for the file wirelesstagpy-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: wirelesstagpy-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/56.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.4

File hashes

Hashes for wirelesstagpy-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2e9dbc0c9ee25473abf7dd77ed833ea38f81ae3b1c4a5fc6f6d37d6a7ddc12b
MD5 e931ff5108530e84de85d7272993db74
BLAKE2b-256 2995bfcb830717898d6fa689271fab43086244e7d86c3aeaef9f190086c6cb17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page