Skip to content

Latest commit

 

History

History
123 lines (96 loc) · 5.15 KB

API.md

File metadata and controls

123 lines (96 loc) · 5.15 KB

Solar Protocol API V1

An API for communicating between distributed Raspberry Pis and making system data accessible

  • Network communication between servers on the network is done with POST requests via the api.php end point
  • Retrieving data from charge controllers is done with GET requests via the chargecontroller.php end point.

api.php

This manages POST requests on the server

  • POST requests allow other devices on the network to update the IP list to account for dynamic IP issues

clientPostIP.py

This script updates the IPs on the other devices on the network

  • this should be set on a cron timer

solarProtocol.py

This script queries the PV data from the other devices and determines if the local device should be point of entry and updates the DNS if so

  • this should be set on a cron timer
  • update the subCall to the appropriate DNS updater system being used

deviceList.json

This is where mac, ip, timestamp, and device name info from devices on the network is stored. The file needs to exist, but it can be blank... It isn't completely necessary to prepopulate it with the IP addresses, but if not you will need to manually make Post requests or edit the files locally to start everything up.

  • name and timestamp aren't required, but may be helpful in the future for debugging

format: [{"mac":"0","ip":"0.0.0.0","time stamp":"0","name":""}, {"mac":"1","ip":"1.1.1.1","time stamp":"0","name":""}]

Set file permissions for deviceList.json

  • sudo chmod a+w deviceList.json

API Key

The API key should be added to the local.json file

POST

Possible keys for post requests:

  • apiKey
  • stamp - time stamp
  • ip
  • mac
  • name - name of device
  • log - log of "point of entry" events

Python Example:

import requests

headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
}

myString = "api_key="+apiKey+"&stamp="+str(time.time())+"&ip="+myIP+"&mac="+myMAC+"&name="+myName
x = requests.post('http://www.mywebsite.xyz/api/v1/api.php', headers=headers,data = myString)

chargecontroller.php

This manages open access GET requests for local charge controller data

  • GET requests allow for querying PV data from the device

Syntax

clientGetPV.py is just for testing purposes. solarProtocol.py handles get request when they system is operational. You can also use a browser to make a get request.

Possible keys for get requests

Simple client side Python and JS examples available in the utilities directory.