Files
ThingsBoard/get_telemetry.ipynb
2022-08-20 10:06:20 -05:00

111 lines
8.5 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"from thingsboardAPI import ThingsBoardAPI\n",
"from datetime import datetime as dt\n",
"import json"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"tb = ThingsBoardAPI(\"nmelone@henry-pump.com\", \"gzU6$26v42mU%3jDzTJf\", \"hp.henrypump.cloud\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#tb"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"customers = tb.getCustomers()\n",
"devices = tb.getDevices(customers=customers, target_customer=\"Amerus Safety Solutions\")\n",
"eType, did, keys = tb.getDeviceKeys(devices=devices, target_device=\"Camera Trailer 106\")\n",
"telemetry = tb.getTelemetry(startTs=tb.convertDateTimeToMS(\"26 May 2022, 13:57:00\"), endTs=int(dt.now().timestamp() * 1000), keys=\",\".join(keys), eType=eType, did=did)\n",
"#telemetry"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import base64\n",
"for snap in telemetry[\"snapshot\"]:\n",
" with open('/Users/nico/Documents/tbTimelapse/'+ str(snap[\"ts\"]) + \".jpg\", 'wb') as img:\n",
" img.write(base64.b64decode(snap[\"value\"]))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'{\\n \"data\": [\\n {\\n \"id\": {\\n \"entityType\": \"DEVICE\",\\n \"id\": \"06488cb0-e0f5-11ec-9bb1-4f9f983f9687\"\\n },\\n \"createdTime\": 1654010351867,\\n \"additionalInfo\": {\\n \"gateway\": false,\\n \"overwriteActivityTime\": false,\\n \"description\": \"\"\\n },\\n \"tenantId\": {\\n \"entityType\": \"TENANT\",\\n \"id\": \"a610ad00-52e2-11ec-89c2-2f343e6c262d\"\\n },\\n \"customerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n },\\n \"name\": \"Camera Trailer 107\",\\n \"type\": \"cameratrailer\",\\n \"label\": \"\",\\n \"deviceProfileId\": {\\n \"entityType\": \"DEVICE_PROFILE\",\\n \"id\": \"9bf921c0-dd3a-11ec-b5bf-ff45c37940c6\"\\n },\\n \"deviceData\": {\\n \"configuration\": {\\n \"type\": \"DEFAULT\"\\n },\\n \"transportConfiguration\": {\\n \"type\": \"DEFAULT\"\\n }\\n },\\n \"firmwareId\": null,\\n \"softwareId\": null,\\n \"ownerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n }\\n },\\n {\\n \"id\": {\\n \"entityType\": \"DEVICE\",\\n \"id\": \"3bbd12c0-e2a9-11ec-bece-e5d3f0ce866e\"\\n },\\n \"createdTime\": 1654197702124,\\n \"additionalInfo\": {\\n \"gateway\": false,\\n \"overwriteActivityTime\": false,\\n \"description\": \"\"\\n },\\n \"tenantId\": {\\n \"entityType\": \"TENANT\",\\n \"id\": \"a610ad00-52e2-11ec-89c2-2f343e6c262d\"\\n },\\n \"customerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n },\\n \"name\": \"Camera Trailer 101\",\\n \"type\": \"cameratrailer\",\\n \"label\": \"\",\\n \"deviceProfileId\": {\\n \"entityType\": \"DEVICE_PROFILE\",\\n \"id\": \"9bf921c0-dd3a-11ec-b5bf-ff45c37940c6\"\\n },\\n \"deviceData\": {\\n \"configuration\": {\\n \"type\": \"DEFAULT\"\\n },\\n \"transportConfiguration\": {\\n \"type\": \"DEFAULT\"\\n }\\n },\\n \"firmwareId\": null,\\n \"softwareId\": null,\\n \"ownerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n }\\n },\\n {\\n \"id\": {\\n \"entityType\": \"DEVICE\",\\n \"id\": \"ac7dd6e0-e0ea-11ec-8c76-ad8278896f52\"\\n },\\n \"createdTime\": 1654005906254,\\n \"additionalInfo\": {\\n \"gateway\": false,\\n \"overwriteActivityTime\": false,\\n \"description\": \"\"\\n },\\n \"tenantId\": {\\n \"entityType\": \"TENANT\",\\n \"id\": \"a610ad00-52e2-11ec-89c2-2f343e6c262d\"\\n },\\n \"customerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n },\\n \"name\": \"Camera Trailer 106\",\\n \"type\": \"cameratrailer\",\\n \"label\": \"\",\\n \"deviceProfileId\": {\\n \"entityType\": \"DEVICE_PROFILE\",\\n \"id\": \"9bf921c0-dd3a-11ec-b5bf-ff45c37940c6\"\\n },\\n \"deviceData\": {\\n \"configuration\": {\\n \"type\": \"DEFAULT\"\\n },\\n \"transportConfiguration\": {\\n \"type\": \"DEFAULT\"\\n }\\n },\\n \"firmwareId\": null,\\n \"softwareId\": null,\\n \"ownerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n }\\n },\\n {\\n \"id\": {\\n \"entityType\": \"DEVICE\",\\n \"id\": \"ebc3d9a0-dd3c-11ec-b1ed-e5d3f0ce866e\"\\n },\\n \"createdTime\": 1653601426490,\\n \"additionalInfo\": {\\n \"gateway\": false,\\n \"overwriteActivityTime\": false,\\n \"description\": \"\"\\n },\\n \"tenantId\": {\\n \"entityType\": \"TENANT\",\\n \"id\": \"a610ad00-52e2-11ec-89c2-2f343e6c262d\"\\n },\\n \"customerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n },\\n \"name\": \"Camera Trailer 123\",\\n \"type\": \"cameratrailer\",\\n \"label\": \"\",\\n \"deviceProfileId\": {\\n \"entityType\": \"DEVICE_PROFILE\",\\n \"id\": \"9bf921c0-dd3a-11ec-b5bf-ff45c37940c6\"\\n },\\n \"deviceData\": {\\n \"configuration\": {\\n \"type\": \"DEFAULT\"\\n },\\n \"transportConfiguration\": {\\n \"type\": \"DEFAULT\"\\n }\\n },\\n \"firmwareId\": null,\\n \"softwareId\": null,\\n \"ownerId\": {\\n \"entityType\": \"CUSTOMER\",\\n \"id\": \"7a6ce000-dd3a-11ec-b1ed-e5d3f0ce866e\"\\n }\\n }\\n ],\\n \"totalPages\": 1,\\n \"totalElements\": 4,\\n \"hasNext\": false\\n}'"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"json.dumps(devices, indent=4)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "22238595996e71d7b27448e64f75d285aa95d1182295fdd30f75905446cf0091"
},
"kernelspec": {
"display_name": "Python 3.9.12 ('webkit')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}