meltaxa / solariot

Leverage your IoT enabled Solar PV Inverter to stream your solar energy usage data to a real time dashboard.
https://solariot.live
MIT License
201 stars 69 forks source link

Output to json format #24

Closed meltaxa closed 3 years ago

meltaxa commented 3 years ago

Enhancement to send output to a file in json format. Use case could be for a telegraf process to ingest this as input.

meltaxa commented 3 years ago

Code to output a json file:

f = open('solariot.json','w')
    f.write(json.dumps(inverter))
    f.close()

The use case of Telegraf ingesting the json allows Telegraf to handle external communications, say to InfluxDB. Telegraf should cache the input and is more resilient to network comms failures.

Sample telegraf conf.d file for those interested:

[[outputs.influxdb_v2]]
  urls = ["https://us-west-2-1.aws.cloud2.influxdata.com"]

  token = "SECRET!"

  organization = "MyOrg"

  bucket = "Your Bucket"

  [outputs.influxdb.tagpass]
    influxdb_database = ["sungrow"]

[[inputs.exec]]
  commands = [
    "cat /path/to/solariot.json"
  ]
  interval = "30s"
  timeout = "15s"
  data_format = "json"
  [inputs.exec.tags]
    influxdb_database = "sungrow"

The exposed json endpoint can also be used by other services that allow json parsing, such as a Momentum dashboard:

Screen Shot 2021-02-24 at 9 16 46 PM