Narodmon python API
Project description
Simple python wrapper around narodmon's APIs
Requirements
You need to register in https://narodmon.ru/. If you plan to use /api endpoint, you need to get api key also. Narodmon contains two endpoints - json and api. This wrapper provides wrap for both of them.
Usage
Import Narodmon
class, which contains all api methods:
from narodmon import Narodmon
JSON endpoint
This endpoint is used for uploading sensors data. To achieve more security, this wrapper uses https secure connection with POST JSON requests only. If you plan to use something else, feel free to enhance this package or fork.
To succeed with JSON endpoint, you need to specify:
mac
address of device (should be unique and hidden)name
of device (any string)owner
of the device (any string)lat
- latitude where device is placedlon
- longitude where device is placedalt
- altitude where device is placed
If so, it's better to init class like
nm = Narodmon(mac=mac, lat=lat, lon=lon,
alt=alt, owner=owner, name=name)
Optional, you can leave any or all params blank. You can set them any time via set
methods:
nm.via_json.set_mac(mac)
nm.via_json.set_name(name)
nm.via_json.set_owner(owner)
nm.via_json.set_lat(lat)
nm.via_json.set_lon(lon)
nm.via_json.set_alt(alt)
Prior to send data, you must pack it in related dicts, first of all, sensors data can be packed via:
sensor_data = nm.via_json.prepare_sensor_data(id_in=id,
value=val, unit=unit, utc_time=utc)
# 'unit' optional when id_in used with recommended names (refer to docs or
# settings.py dict). 'utc_time' is optional, if sensor measurement is now.
# sensor data will be dict like: {'id': 'TEMPC', 'value': -5.78}
Secondly, you can pack multiple sensors data for each device. To achieve it, use lists:
sensors = [sensor_data1, sensor_data2]
When you prepare all sensor data, you can send data for whole device:
response = nm.via_json.send_full_data(sensors=sensors) # full data send (only for first call)
response = nm.via_json.send_short_data(sensors=sensors) # short sensors data send (without device data)
Alternatively, you can prepare data for several devices and send it bulk:
device1 = nm.via_json.prepare_device_data_full(sensors=sensors1, mac=mac1, name=name1,
owner=owner1, lat=lat1, lon=lon1, alt=alt1)
device2 = nm.via_json.prepare_device_data_short(sensors=sensors2, mac=mac2)
devices = [device1, device2]
response = nm.via_json.send_bulk_data(data=devices)
REST API endpoint
This endpoint is used for manage narodmon, devices (sensors, cameras), obtain and send data. To achieve more security, this wrapper uses https secure connection with POST JSON requests only. If you plan to use something else, feel free to enhance this package or fork.
To succeed with REST API endpoint, you need to specify:
uuid
- unique id of deviceapi_key
obtained from servicelang
- (optional) default language, may be 'ru', 'en', 'uk'lat
- (optional) latitude where device is placedlon
- (optional) longitude where device is placed
self.via_api = InterfaceAPI(uuid=uuid, api_key=api_key, lang=lang, lat=lat, lon=lon)
If so, it's better to init class like
nm = Narodmon(uuid=uuid, api_key=api_key, lang=lang, lat=lat, lon=lon)
Optional, you can leave any or all params blank. You can set them any time via set
methods:
nm.via_api.set_uuid(uuid)
nm.via_api.set_api_key(api_key)
nm.via_api.set_lang(lang)
nm.via_api.set_lat(lat)
nm.via_api.set_lon(lon)
Actually, service assume that uuid
is MD5 hash, not pure name. To convert string-like uuid to hash, use following method:
uuid_hash = nm.via_api.encrypt_uuid()
# method will replace stored uuid with hash, so you do not need to update it manually
To send weather measurements use following:
nm.via_api.weather_report(lat=lat, lon=lon, temp=temp_in_c, humid=humid, press=pressure, wind=wind_heading,
lang=lang, api_key=api_key, uuid=uuid)
# If you fully init Narodmon class, lat, lon, api_key, uuid, lang params are optional
# Sensors params also optional, you can specify one of them or all to send all
All other methods also wrapped, please use inline docs or refer to service.
Troubleshooting
Please read service API docs first. Most probably, all of the problems are related to wrong data and API send limit (1-5 min). Each server response checked by inline function, so, if error occured, it will be redirected to stderr.
Terms of service
Refer to https://narodmon.ru/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file narodmon-python-api-0.0.3.tar.gz
.
File metadata
- Download URL: narodmon-python-api-0.0.3.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.21.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4db6f91edd777edf50814faa88c95a35d7644276482b914083cd4c5d0d2700ea |
|
MD5 | 9ab068e248e8ef0e959aee850658c2f4 |
|
BLAKE2b-256 | c87502c305d79f50a164f228ea202f0897451756d6832e9094b5dc87a8d48398 |
File details
Details for the file narodmon_python_api-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: narodmon_python_api-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.21.0 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1f37eca4805e841c4a47a465daf19079d2aca23bc5fe645b662212fc7870a11 |
|
MD5 | d58d178ae2b31d696595a94ed52ba6b5 |
|
BLAKE2b-256 | 96a5d6cfb8412dfb1d3e3024ecceca008ed6938267059c07b2743a19f528acbb |