From 06272fe594544f2b5f66f29e740a64b63a14be65 Mon Sep 17 00:00:00 2001 From: Justin Parker Date: Wed, 29 May 2024 17:41:17 +1000 Subject: [PATCH] Create api_monitoring_only_script.py (#81) --- Brightsign/api_monitoring_script.py | 136 ++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 Brightsign/api_monitoring_script.py diff --git a/Brightsign/api_monitoring_script.py b/Brightsign/api_monitoring_script.py new file mode 100644 index 0000000..22591b3 --- /dev/null +++ b/Brightsign/api_monitoring_script.py @@ -0,0 +1,136 @@ +''' +BrightSign monitoring only using its built-in API. + +* includes snapshots on demand + +ISSUES + +* work needs to be done on this if authentication is required + +`rev 3` + +''' + +param_IPAddress = Parameter({ 'schema': { 'type': 'string' }}) + + +local_event_Uptime = LocalEvent({ 'order': next_seq(), 'schema': { 'type': 'string' }}) + +local_event_Name = LocalEvent({ 'order': next_seq(), 'schema': { 'type': 'string' }}) + +local_event_Desc = LocalEvent({ 'order': next_seq(), 'schema': { 'type': 'string' }}) + + +local_event_Serial = LocalEvent({ 'group': 'Information', 'schema': { 'type': 'string', 'order': next_seq() }}) +local_event_Model = LocalEvent({ 'group': 'Information', 'schema': { 'type': 'string', 'order': next_seq() }}) +local_event_FW = LocalEvent({ 'group': 'Information', 'schema': { 'type': 'string', 'order': next_seq() }}) +local_event_BootVersion = LocalEvent({ 'group': 'Information', 'schema': { 'type': 'string', 'order': next_seq() }}) + + +local_event_Snapshot = LocalEvent({ 'schema': { 'type': 'string' }}) + +# e.g. > curl "http://192.168.110.11/api/v1/snapshot" -X "POST" -H "x-api-key: cf70" +@local_action({ 'title': 'Generate Snapshot' }) +def Snapshot(): + resp = get_url('http://%s/api/v1/snapshot' % param_IPAddress, method='POST') + + # e.g. >> { "data":{"result":{"remoteSnapshotThumbnail":"data:image/jpeg;base64,/9j ...", + # "filename":"/sd/remote_snapshots/img-2022-04-29-01-47-57.jpg","timestamp":"2022-04-29 13:47:59 AEST","devicename":"RG SC R"}}} + + result = json_decode(resp)['data']['result'] + local_event_Snapshot.emit(result['remoteSnapshotThumbnail']) + +@local_action({ 'title': 'Poll', 'group': 'Information' }) +def Information(): + resp = get_url('http://%s/api/v1/info' % param_IPAddress) + + global _lastReceive + _lastReceive = system_clock() + + # e.g. >> {"data":{"result":{"serial":"D1E927000148","upTime":"297 days 1 hours 40 minutes","upTimeSeconds":25666854,"model":"XD234","FWVersion":"8.2.75","bootVersion":"7.1.53","family":"malibu","isPlayer":true, + # "power":{"result":{"battery":"absent","source":"AC","switch_mode":"hard"}},"poe":{"result": + + result = json_decode(resp)['data']['result'] + + + local_event_Uptime.emit(result['upTime']) + local_event_Name.emit(result['networking']['result']['name']) + local_event_Desc.emit(result['networking']['result']['description']) + + + local_event_Serial.emit(result['serial']) + local_event_Model.emit(result['model']) + local_event_FW.emit(result['FWVersion']) + local_event_BootVersion.emit(result['bootVersion']) + local_event_IPAddress.emit([paramIPAddress]) + +Timer(lambda: Information.call(), 60, 5) # every minute, first after 5 + + + +#