Om de REST API van Enphase te kunnen gebruiken heb je vanaf firmware 7 een access token nodig. Zo’n token is heel eenvoudig aan te maken middels onderstaand PHP-script:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php $user='YOUR_EMAIL_ADDRESS_HERE'; // emailadres waarmee je inlogt op https://enlighten.enphaseenergy.com/ $password='YOUR_PASSWORD_HERE'; // wachtwoord waarmee je ingogt op https://enlighten.enphaseenergy.com/ $envoy_serial='YOUR_ENVOY_SERIAL_HERE'; // is te vinden als je bent ingelogd op https://enlighten.enphaseenergy.com/ en dan vervolgens SYSTEEM > APPARATEN // RETRIEVE SESSION ID $data = (array( "user[email]" => "$user", "user[password]" => "$password" )); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://enlighten.enphaseenergy.com/login/login.json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); $response = json_decode($response); $session_id = $response->session_id; // RETRIEVE TOKEN $data = json_encode(array( "session_id" => "$session_id", "serial_num" => "$envoy_serial", "username" => "$user" )); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://entrez.enphaseenergy.com/tokens'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', ]); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $response = curl_exec($ch); curl_close($ch); echo $response.PHP_EOL.PHP_EOL; ?> |