{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from tb_rest_client.rest_client_pe import *\n", "from tb_rest_client.rest import ApiException\n", "from tb_rest_client.api_client import *\n", "import json\n", "from datetime import datetime as dt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def convertDateTimeToMS(datestring):\n", " date = dt.strptime(datestring,\"%d %b %Y, %H:%M:%S\")\n", " return int(date.timestamp() * 1000)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "url = \"https://hp.henrypump.cloud\"\n", "username = \"example@example.com\"\n", "password = \"password123\"\n", "with RestClientPE(base_url=url) as rest_client:\n", " try:\n", " rest_client.login(username=username, password=password)\n", " cid = \"0d4427e0-18ae-11ed-8e6d-5b69d1f90f37\" #This is the Customer ID for Henry Resources and doesn't need changed\n", " devices = rest_client.get_customer_devices(customer_id=cid, page=0, page_size=100)\n", " #print(json.dumps(device.to_dict(),indent=4))\n", " #print(devices)\n", " for device in devices.data:\n", " eType = device.id.entity_type\n", " eid = device.id.id\n", " name = device.name\n", " start = convertDateTimeToMS(\"01 Jan 2024, 00:00:00\") #The date time for when the data should start\n", " end = int(dt.now().timestamp() * 1000) #automatically sets to now\n", " #print(eType, eid, name)\n", " keys = rest_client.get_timeseries_keys_v1(eType,eid)\n", " telemetry = rest_client.get_timeseries(entity_type=eType, entity_id=eid , keys=\",\".join(keys), start_ts=start, end_ts=end, limit=10000)\n", " print([telemetry])\n", " except ApiException as e:\n", " print(e)" ] } ], "metadata": { "kernelspec": { "display_name": "thingsboard", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.10.5" } }, "nbformat": 4, "nbformat_minor": 2 }